codefresh logs
npm install cf-logs
javascript
var logger = require('cf-logs');logger.info("info message");
logger.error("error message");
`
Notice that if you use this option then you will not be able to use the DEBUG environment variable to filter these logs.
So our main use should be with the advanced usage.Advanced Usage - specific namespaced logger
You can provide a namespace for your current logger, just like in 'debug' module and then controll the output logs with DEBUG environment variable
`javascript
var logger = require('cf-logs').Logger("codefresh:example");logger.info("info message");
logger.debug("debug meesage"):
`
This is very powerfull for development, because many times you want to see only logs from a specific part of the application so you can for example set the DEBUG environment variable to for example: "codefresh:builds".
The default is set so that all logs that begins with a namespace 'codefresh,codefresh:*' will be shown.
$3
`javascript
var logger = require('cf-logs').Logger("codefresh:example");var error = new Error("very bad error");
logger.error("error: %s", error.toString());
logger.error("stack: %s", error.stack);
`Configuring the logger
The options that can be passed are:
`javascript
var options = {
showNamespace: Boolean,
env_module: String,
showRequestId: Boolean,
level: String(one of: "error/warn/info/debug"),
consoleOptions: {
formatter: function(options) {
// Receives the consoleOptions object, merged with the meta objects
// Should return a formatted string for this log.
// This is an example:
return new Date().toISOString() +' '+ options.level.toUpperCase() +' >> '+ (undefined !== options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? ' << ' + JSON.stringify(options.meta) : '' );
}
},
basePath: String,
baseNamepsace: String
}var logger = require('cf-logs');
logger.setGlobalOptions(options);
``