meh-logging
v1.4.0
Published
---
Downloads
109
Keywords
Readme
MEH Logging module
Logging module based on Winston. By default the output will be in JSON format and can be parsed to human readable output when the parser is used.
$ yarn add meh-logging
How to use
import logger from 'meh-logging';
logger.info('Hello world');
logger.debug(['foo', 'bar']); //silenced in production
logger.debug({'foo', 'bar'}); //silenced in production
logger.verbose('verbose message'); //silenced in production
logger.track('kpi');
logger.warn('This should someday be fixed.');
logger.error(new Error('Ow nooo...'));
How to use (express)
The module contains a middleware for express that adds additional metadata to the json output. Fields that are added:
requestId
path
method
hostname
Tip: When e.g. an error is thrown, the Request ID can be used to lookup the error within the logging platform.
import logger from 'meh-logging';
import express from 'express';
const app = express();
const port = process.env.PORT || 3000;
app.use(logger.express);
app.get('/', function (req, res) {
req.logger.info('Received request.');
res.send('ok');
});
app.listen(port, () => logger.debug(`App listening at http://localhost:${port}`));
Track level
The actions will end up in a kpi reporting platform. For more details see: meh-activity-logger
import logger from 'meh-logging';
// simple
logger.track('action to track');
// advanced
logger.track('action to track', {
label?: string,
value?: int,
priority?: int
});
Human readable output
install the binary
$ yarn global add meh-logging
$ node app.js | meh-printer
Before:
after:
Log levels
ERROR (error): Use when something fatal has happened, that is, something will have user-visible consequences. This level is always logged. Issues that justify some logging at the ERROR level are good candidates to be reported to a log management platform.
WARNING (warn): Use when something serious and unexpected happened, that is, something that will have user-visible consequences but is likely to be recoverable. This level is always logged. Issues that justify logging at the WARNING level might also be considered for reporting to a log management platformr.
INFORMATIVE (info): Use to note that something interesting happened, that is, when a situation is detected that is likely to have widespread impact, though isn't necessarily an error. This level is always logged to a log management platform.
DEBUG (debug): Use to further note what's happening in the application that could be relevant to investigate and debug unexpected behaviors. Log only what's needed to gather enough information about what's going on with your component. If your debug logs are dominating the log, then you should use verbose logging. These logs won't end up in a log management platform and are silences in production environments.
VERBOSE (verbose): Use for everything else. This level is only logged on debug builds.
TRACK (track): Custom Helper log level that can be use when certain KPI's are met and will end up in a kpi reporting platform . For more information:meh-activity-logger
Source: Google Android logging guidelines
Known issues
- Kubetail is currently not supported due to the fact that it's not using stdout completely.
TODO's
- Support for logging in the browser.