@koopjs/logger
Advanced tools
Comparing version 3.0.1 to 4.0.0
{ | ||
"name": "@koopjs/logger", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "A shared logger for Koop", | ||
@@ -13,3 +13,3 @@ "main": "src/index.js", | ||
"type": "git", | ||
"url": "https://www.github.com/koopjs/koop-logger.git" | ||
"url": "https://www.github.com/koopjs/koop.git" | ||
}, | ||
@@ -16,0 +16,0 @@ "keywords": [ |
# Koop-Logger | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/koopjs/koop-logger.svg)](https://greenkeeper.io/) | ||
* A shared logger for Koop | ||
[![Build Status](https://travis-ci.org/koopjs/koop-logger.svg?branch=master)](https://travis-ci.org/koopjs/koop-logger) | ||
## Usage | ||
@@ -9,0 +4,0 @@ `npm install @koopjs/logger` |
@@ -13,26 +13,34 @@ /* @flow */ | ||
config = config || {}; | ||
let level; | ||
if (process.env.KOOP_LOG_LEVEL) { | ||
level = process.env.KOOP_LOG_LEVEL; | ||
} else if (process.env.NODE_ENV === 'production') { | ||
level = 'info'; | ||
} else { | ||
level = 'debug'; | ||
const level = setLogLevel(config.logLevel); | ||
if (config.logfile) { | ||
const fileTransports = setupFileTransport(config.logfile, level); | ||
return winston.createLogger({ transports: fileTransports }); | ||
} | ||
if (!config.logfile) { | ||
// no logfile defined, log to STDOUT an STDERRv | ||
const debugConsole = new winston.transports.Console({ | ||
colorize: process.env.NODE_ENV === 'production', | ||
level, | ||
stringify: true, | ||
json: true | ||
}); | ||
return winston.createLogger({ transports: [debugConsole] }); | ||
const consoleTransport = new winston.transports.Console({ | ||
colorize: true, | ||
level, | ||
stringify: true, | ||
json: true | ||
}); | ||
return winston.createLogger({ transports: [consoleTransport] }); | ||
} | ||
function setLogLevel (logLevel) { | ||
if (logLevel) { | ||
return logLevel; | ||
} | ||
// we need a dir to do log rotation so we get the dir from the file | ||
const logpath = path.dirname(config.logfile); | ||
if (process.env.KOOP_LOG_LEVEL || process.env.LOG_LEVEL) { | ||
return process.env.KOOP_LOG_LEVEL || process.env.LOG_LEVEL; | ||
} | ||
return 'info'; | ||
} | ||
function setupFileTransport (logfile, level) { | ||
const logpath = path.dirname(logfile); | ||
const logAll = new winston.transports.File({ | ||
filename: config.logfile, | ||
filename: logfile, | ||
name: 'log.all', | ||
@@ -45,4 +53,5 @@ dirname: logpath, | ||
}); | ||
const logError = new winston.transports.File({ | ||
filename: config.logfile.replace('.log', '.error.log'), | ||
filename: logfile.replace('.log', '.error.log'), | ||
name: 'log.error', | ||
@@ -56,10 +65,9 @@ dirname: logpath, | ||
// always log errors | ||
const transports = [logError]; | ||
// only log everthing if debug mode is on | ||
if (process.env.LOG_LEVEL === 'debug') { | ||
if (level === 'debug') { | ||
transports.push(logAll); | ||
} | ||
return winston.createLogger({ transports }); | ||
return transports; | ||
} | ||
@@ -66,0 +74,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
74
4
14637
15