Skip to content

Commit

Permalink
Added consoleOptions to options dict of logger
Browse files Browse the repository at this point in the history
  • Loading branch information
alon-codefresh committed Oct 20, 2016
1 parent 9007e4a commit a905f0c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@ node_modules
coverage/*.html
.debug
coverage
.coveralls.yml
.coveralls.yml
.idea
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -45,7 +45,16 @@ var options = {
showNamespace: Boolean,
env_module: String,
showRequestId: Boolean,
level: String(one of: "error/warn/info/debug")
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) : '' );
}
}
}

var logger = require('cf-logs');
Expand Down
14 changes: 8 additions & 6 deletions lib/index.js
Expand Up @@ -16,7 +16,8 @@ var defaultOptions = {
env_module: "",
showRequestId: false,
level: "debug",
namespaces: "codefresh,codefresh:*"
namespaces: "codefresh,codefresh:*",
consoleOptions: null,
};

var globalOptions = defaultOptions;
Expand Down Expand Up @@ -111,12 +112,13 @@ var Logger = function(namespace) {
//Log to console
if (!globalOptions || globalOptions.console){
if (globalOptions && globalOptions.handleExceptions){
logger.add(winston.transports.Console, {
handleExceptions: true
});
consoleOptions.handleExceptions = true;
logger.add(winston.transports.Console, globalOptions.consoleOptions);
}
else{
logger.add(winston.transports.Console);
logger.add(
winston.transports.Console, globalOptions.consoleOptions
);
}
}

Expand Down Expand Up @@ -200,4 +202,4 @@ var Logger = function(namespace) {
};

var defaultLogger = Logger("CF_LOGS_DEFAULT");
module.exports = defaultLogger;
module.exports = defaultLogger;
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cf-logs",
"version": "0.0.3",
"version": "0.0.4",
"description": "codefresh logs",
"main": "lib/index.js",
"repository": {
Expand Down

0 comments on commit a905f0c

Please sign in to comment.