2.0.5 • Published 1 month ago

@vlalg-nimbus/raven-sentinel v2.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

npm npm Snyk Vulnerabilities for npm package Snyk Vulnerabilities for GitHub Repo

This lib is a log manager that facilitates the identification of logs in code.

Logs list

cleanLog

Internally it is an console.log. No styling, i.e. a default console.log

this.$log.cleanLog($log.printObject(data));

debug

Internally it is an console.debug

this.$log.debug('Msg test for debug');

error

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);

log

Internally it is an console.log

this.$log.log('Hello world')
this.$log.log('Hello world 1', 'Hello world 2')

logDebug

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))

logError

Internally it is an console.error

this.$log.logError('this is the error')

logInfo

Internally it is an console.log

this.$log.logInfo('Hello world')
this.$log.logInfo('Hello world 1', 'Hello world 2')

method

Internally it is an console.log

this.$log.method('Hello world')
this.$log.method('Hello world 1', 'Hello world 2')

printObject

Used with the $log.cleanLog

Internally it is an printObject

this.$log.cleanLog(this.$log.printObject({ name: 'test' }));

table

Internally it is an console.table

this.$log.table({ name: 'test' });

time

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();

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();

trace

Internally it is an console.debug

this.$log.trace('Msg test for trace')

warn

Internally it is an console.warn

this.$log.warn('Msg test for warn')

How to use?

To install
npm i @vlalg-nimbus/raven-sentinel

or

yarn add @vlalg-nimbus/raven-sentinel
To use
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')
CDN

Unpkg

https://unpkg.com/@vlalg-nimbus/raven-sentinel/dist/bundle.min.umd.js

Options

  • 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 production production. Then we pass process.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.

License

MIT

2.0.5

1 month ago

2.0.4

7 months ago

2.0.3

7 months ago

2.0.2

7 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago