mira-logger-js
An opinionated logging client for Node and the browser.
Usage
Initializing the client
const MiraLogger = ; const logger = token: envLOGGLY_CUSTOMER_TOKEN environment: envENVIRONMENT revision: envREVISION service: 'my-service';
See MiraLoggerOptions for the full set of options.
Log levels
logger;logger;logger;logger;logger; // Send logs.await logger;
Setting context (optional)
Set the context to send with each subsequent log.
logger; ... // Context passed in with an individual log is merged in with// the default context set with `setContext`.logger; // Logs [{ message: 'info message', requestId: 'some-uuid', statusCode: 200 }]await logger;
See Context for the full set of options.
Wrapping functions
Wrap a function with logger.wrap
to automatically log errors and flush on return. Works with async functions too.
logger;
Examples
Http Errors
{ supermessage; thisname = 'HttpError'; // statusCode will automatically be logged. thisstatusCode = code; } const res = await ; if !resok logger;
Lambda Scheduled Event
const logger = token: envLOGGLY_CUSTOMER_TOKEN environment: envENVIRONMENT service: 'my-service' // We manually flush at the end of the lambda so there's not // much point in keeping auto flushing enabled. enableAutoFlush: false; moduleexportshandler = logger
Publishing to NPM
Publishing is currently manual. Grab the NPM login from 1password.
- Bump the version in
package.json
. - Run
yarn deploy
. - Commit with the version name and push (ie.
git commit -m "v0.1.5"
)