UNPKG

thunder-log

Version:

The logger used for Shared Services Logging.

84 lines (75 loc) 3.29 kB
/* Describes the functionality of the Shared Services Logger, 'thunder-log' */ const Logging = require('../index'); const logger = Logging.getLogger('development'); // set the logging file to a temporary location const fs = require('fs'); fs.rename('log.txt', 'temp.txt', (err) => { if (err) console.error(err); }); /* Writing a simple info statement write(severity, summary) params: severity as a string, summary as a string */ logger.write('info', 'This is a basic info statement'); logger.info('This is a basic info statement') /* Alternatively, can include the summary as a field in an object write(severity, object) */ logger.write('info', { Summary: 'This is also a valid info statement' }); /* All other logging severities EXCEPT error can take advantage of the simple log statement due to additional requirement */ logger.write('debug', 'This is a basic debug statement with only a summary'); logger.debug('This is a basic debug statement with only a summary'); logger.write('warn', 'This is a basic warn statement with only a summary'); logger.warn('This is a basic warn statement with only a summary'); /* Minimum requirements for an error logging statement */ logger.write('error', { Summary: 'This is an explanation of the error', ExceptionDetails: '400: Missing Parameters' }); logger.error({ Summary: 'This is an explanation of the error', ExceptionDetails: '400: Missing Parameters' }); /* All logging statement can take in an object as the second parameter The fields of the object all follow the Share Services Logging Schema -LoggerId string The component responsible for where the logging took place; a method name, a class, or a file -UserId string Identifier for a particular user (see PII requirements to not post any information that can be tracked back to the user) -Summary string Detailed description of the log -Action string Http request verbs; GET, POST, DELETE, etc -ActionTarget string What module, service, or class is the target of the operation -ActionResult string What was the result of the action; success, fail, timeout -ExceptionDetails string Contains the exception code corresponding to the message passed using the Shared Services Exceptions Handling Schema ex: '400: Invalid Input Error' -StackInfo string When errors occur, can provide a stack trace in the log -AdditionalDetails string Information which should be provided but does not fit a category above */ const exampleOptions = { LoggerId: 'functional test log', UserId: '', Summary: 'This is an example with full fields for logging', Action: 'Example Log', ActionTarget: 'Console', ActionResult: 'Success', ExceptionDetails: '200 No Problem', StackInfo: '~/logging/functionTest.js', AdditionalDetails: 'This is where I add anything that will not go into a predfined field' } logger.write('debug', exampleOptions); /* These options are also all supported for the other logging severities */ logger.write('info', exampleOptions); logger.write('warn', exampleOptions); logger.write('error', exampleOptions); // overwrite the functional test logs fs.rename('temp.txt', 'log.txt', (err) => { if (err) console.error(err) });