@nr1e/logging v0.0.8
Logging
Provides a simple logging interface for typescript projects that adheres to the NR1E logging standard.
To install using pnpm
pnpm i @nr1e/logging-js
How to use
Initialize logging in your application.
import * as logging from '@nr1e/logging-js';
// Only needs to be performed once
logging.initialize({
level: 'info',
svc: 'my-service',
});
This only needs to be done once. Additional calls to initialize will have no effect.
In your modules, get a named logger
import * as logging from '@nr1e/logging-js';
const log = logging.getLogger('my-module');
To log a message
log.info('Just another day in the life of a logger');
To log a message with a context
log.info({foo: 'bar'}, 'Just another day in the life of a logger');
You can also log nested objects
log.info(
{foo: 'bar', nested: {foo: 'bar'}},
'Just another day in the life of a logger'
);
To log a message using string interpolation
log.info('Just another day in the life of a logger with %s', 'interpolation');
To log an error
catch (err) {
log.error(err, 'An error occurred');
}
To log an error with additional context
catch (err) {
log.error(err, {foo: 'bar'}, 'An error occurred');
}
Be aware, your error must be named 'err' in the context for the error to be logged.
Angular Projects
If you are trying to use this library with Angular, you will need to add the
os-browserify
package to your project.
pnpm i --save-dev os-browserify
Then add the following to your angular.json
file inside compilerOptions
{
...
compilerOptions: {
...
"paths": {
"os": [
"./node_modules/os-browserify"
]
}
}
}
13 days ago
13 days ago
26 days ago
26 days ago
26 days ago
26 days ago
26 days ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago