1.0.1 • Published 4 years ago
@mygorillacode/logger v1.0.1
Logger
A custom logger for use in any node.js application
Install
npm install --save @mygorillacode/logger
Uninstall
npm uninstall --save @mygorillacode/logger
Constructor API
const Logger = requires('logger')
const logger = new Logger({
level: <'name' or number>
stream: {
level: <'name' or number>,
path: 'filepath'
},
streams: [
stream: {
level: <'name' or number>,
path: 'filepath'
}
]
})
Usage
// Import the join method from path
const { join } = require('path')
// Import the logger library
const Logger = require('logger')
// Get full path using the join method
const logTrace = join(__dirname, 'logs', 'trace.log')
const logDebug = join(__dirname, 'logs', 'debug.log')
const logInfo = join(__dirname, 'logs', 'info.log')
const logWarn = join(__dirname, 'logs', 'warn.log')
const logError = join(__dirname, 'logs', 'error.log')
const logFatal = join(__dirname, 'logs', 'fatal.log')
// Create file streams using the log level
const traceStream = { level: 'trace', path: logTrace }
const debugStream = { level: 'debug', path: logDebug }
const infoStream = { level: 'info', path: logInfo }
const warnStream = { level: 'warn', path: logWarn }
const errorStream = { level: 'error', path: logError }
const fatalStream = { level: 'fatal', path: logFatal }
// Create new logger
const log = new Logger({
level: 'trace',
streams: [
traceStream,
debugStream,
infoStream,
warnStream,
errorStream,
fatalStream
]
})
// Use logger methods
log.trace(`This is a trace log`)
log.debug(`This is a debug log`)
log.info(`This is a info log`)
log.warn(`This is a warn log`)
log.error(`This is a error log`)
log.fatal(`This is a fatal log`)
Levels
Fatal
When a very severe event occurs during the operation of your application that will presumably lead the application to abort, shutdown or crash.
Error
When an error event occurs but the application can usually continue running.
Warn
When a potentially harmful event occurs
Info
Informational messages that highlight the progress of the application.
Debug
More details on informational messages that would be useful to know when debugging an application but generally doesn't need to be visible during the normal operation of your application.
Trace
Even more details on informational messages that go into every little detail about an application.
Contact
Author: Michael Johnson Email: mygorillacode@gmail.com