This lib is a log manager that facilitates the identification of logs in code.
Internally it is an console.log
.
No styling, i.e. a default console.log
this.$log.cleanLog($log.printObject(data));
Internally it is an console.debug
this.$log.debug('Msg test for debug');
In the example the e is passed in the catch, so it could be an error or something else
Internally it is an console.error
this.$log.error(e);
Internally it is an console.log
this.$log.log('Hello world')
this.$log.log('Hello world 1', 'Hello world 2')
Internally it is an console.log
this.$log.logDebug('Hello world')
this.$log.logDebug('Hello world 1', 'Hello world 2')
this.$log.logDebug(JSON.stringify({algumObj}, null, 2))
Internally it is an console.error
this.$log.logError('this is the error')
Internally it is an console.log
this.$log.logInfo('Hello world')
this.$log.logInfo('Hello world 1', 'Hello world 2')
Internally it is an console.log
this.$log.method('Hello world')
this.$log.method('Hello world 1', 'Hello world 2')
Used with the $log.cleanLog
Internally it is an printObject
this.$log.cleanLog(this.$log.printObject({ name: 'test' }));
Internally it is an console.table
this.$log.table({ name: 'test' });
Starts a timer in the console
Internally it is an console.time
this.$log.time();
for (let i = 0; i < 3; i++) {
console.log(i)
}
this.$log.timeEnd();
It is used after the logic inserted after $log.time()
Internally it is an console.timeEnd
this.$log.time();
for (let i = 0; i < 3; i++) {
console.log(i)
}
this.$log.timeEnd();
Internally it is an console.debug
this.$log.trace('Msg test for trace')
Internally it is an console.warn
this.$log.warn('Msg test for warn')
npm i @vlalg-nimbus/raven-sentinel
or
yarn add @vlalg-nimbus/raven-sentinel
import LoggerFactory from '@vlalg-nimbus/raven-sentinel'
const nodeEnv = process.env.NODE_ENV
const isDev = !!(nodeEnv === 'development')
const logOptions = {
className: 'App Name',
nodeEnv: nodeEnv,
showLogs: isDev ? 'Trace' : 'Warn'
}
const $log = new LoggerFactory(logOptions).create()
$log.logDebug('Hello world')
https://unpkg.com/@vlalg-nimbus/raven-sentinel/dist/bundle.min.umd.js
-
showLogs: It serves to inform which log level can appear in the development and production environments. For the previous example we used level 0 (trace) if it is 'development', so all logs are allowed, as it is not safe and correct to be logging in production, we set level 3 (warn), which will log (Warn, Error and None) that is, the levels (3, 4 and 5) in production.
Trace = '0' Debug = '1' Info = '2' Warn = '3' Error = '4' None = '5'
-
className: Used to pass the system name, libs and such that are using log-manager. This makes it easier to identify the log, since we can use it in several places, so if we were using it in a service and in the general application, we could set the right name of the service as 'Service X' and inside the application 'Application Y', when you consult the console, everything will be separated.
-
nodeEnv: This field receives the environment that is currently being used, if I am in development
development
and productionproduction
. Then we passprocess.env.NODE_ENV
or whatever env you are using. -
primaryColor: Used to pass a hex of some color that will be used as the primary color. The default is the color
#04F0FC
. The default color is used if none is passed. -
logStyle: You can pass the style of the log, if you do not inform anything, the default will be used. This would basically be like working with css in
console.log
.