1.1.1 • Published 5 months ago
@zaneray/gcp-node-logging v1.1.1
ZaneRay Node Logging
- A wrapper around Winston
- Supports logging to Google StackDriver for deployed applications
- Provides logger 'Singleton' for convenience
Provides configurable logging 'Singleton', to provide custom-configured loggers
Definitions
Environments
- development
- test
- staging
- production
Transports (transports.js)
- defines where to log in each Environment
- development->Console
- test->Google Stackdriver
- staging->Google Stackdriver
- production->Google Stackdriver
Options (options.js)
- defines how to log in each Environment
- development->Timstamp Level Message
- test->JSON
- staging->JSON
- production->JSON
Log Levels - from Winston
- 0: error
- 1: warn
- 2: info
- 3: verbose
- 4: debug
- 5: silly
Usage (see test/loggingTest.js)
in your node project
npm install --save @zaneray/gcp-node-logging
in your application code
const {logger} = require("@zaneray/gcp-node-logging");
// Writes some log entries
logger.info("here's some information");
logger.warn("something might be wrong");
logger.error("something is wrong, seriously");
//change log level to log warn and above
logging.setLevel("warn");
//show the current level
logger.warn(logging.getLevel());
// Writes some log entries
logger.info("here's some information");
logger.warn("something might be wrong");
logger.error("something is wrong, seriously");
to configure different transports, or formats, the 'logging' object is also esposed.
const logging = require("@zaneray/nodejs-logging");
let transports = [new winston.transports.Console({level: "silly",handleExceptions: true})];
let format = format.json();
// set process.env.NODE_ENV in the runtime
// logger level and output method is determined by environment (see transports.js and options.js)
const logger = logging.createWithTransportsAndFormat(transports,format);
// Writes some log entries
logger.info("here's some information");
logger.warn("something might be wrong");
logger.error("something is wrong, seriously");