add logging to file via env variable UCI_PROD

master
David Kebler 2019-01-30 19:19:45 -08:00
parent 26eedb3d19
commit 68a7ce98f3
2 changed files with 11 additions and 5 deletions

View File

@ -4,12 +4,13 @@
"description": "Parent Logger for all UCI modules",
"main": "src/logger",
"scripts": {
"testw": "mocha -r esmtest/*.test.mjs --watch --recurse --watch-extensions mjs",
"test": "mocha -r esmtest/*.test.mjs",
"testw": "mocha -r esm test/*.test.mjs --watch --recurse --watch-extensions mjs",
"test": "mocha -r esm test/*.test.mjs",
"testci": "istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec --recursive && codecov || true",
"example": "node -r esm example/example",
"dev": "UCI_DEV=true ./node_modules/.bin/nodemon -r esm example/example",
"log": "UCI_LOG=true ./node_modules/.bin/nodemon -r esm example/example"
"log": "UCI_LOG=true ./node_modules/.bin/nodemon -r esm example/example",
"pro": "UCI_PROD=./test/logs/uci.log node -r esm example/example"
},
"author": "David Kebler",
"license": "MIT",

View File

@ -1,4 +1,5 @@
import pino from 'pino'
import { homedir } from 'os'
let pretty = false
if(process.env.UCI_DEV) {
@ -6,7 +7,8 @@ if(process.env.UCI_DEV) {
pretty.search = process.env.UCI_LOG_SEARCH
}
let LOG = process.env.UCI_LOG || process.env.UCI_DEV
let LOG = process.env.UCI_LOG || process.env.UCI_DEV || process.env.UCI_PROD
let LOG_PATH = (process.env.UCI_PROD===true) ? homedir()+'/logs/uci.log' : process.env.UCI_PROD
const logger = pino({
name: 'UCI',
@ -17,7 +19,10 @@ const logger = pino({
res: pino.stdSerializers.res
},
prettyPrint: pretty
})
},
// if production not enabled then LOG_PATH is empty and logs go to stdout/stderr and can be piped from there
LOG_PATH
)
function child (opts) {
const LOG_OPTS = {