kitten-logger
Advanced tools
Comparing version 0.1.14 to 0.1.20
@@ -0,1 +1,19 @@ | ||
## v0.1.20 | ||
- Do not truncate logs. | ||
## v0.1.19 | ||
- Fix logs format for master process. | ||
## v0.1.18 | ||
- Logs from sub kitten-logger instances were not correctly formatted. | ||
### v0.1.17 | ||
- Fix LOG_RETENTION value in scheduler. | ||
### v0.1.16 | ||
- Fix: ensure that `KITTEN_LOGGER_RETENTION_DAYS` is not a NaN. | ||
### v0.1.15 | ||
- Fix: parse env variable `KITTEN_LOGGER_RETENTION_DAYS` | ||
### v0.1.14 | ||
@@ -2,0 +20,0 @@ - Fix: Listen to error event for writable stream. |
@@ -8,2 +8,3 @@ const cluster = require('cluster'); | ||
const destination = require('./src/destination'); | ||
const variables = require('./src/variables'); | ||
@@ -20,2 +21,6 @@ if (cluster.isWorker) { | ||
if (process.env.KITTEN_LOGGER_IS_LOADED) { | ||
variables.isLoggerChild = true; | ||
} | ||
filter.filter(); | ||
@@ -22,0 +27,0 @@ logger.enable(); |
{ | ||
"name": "kitten-logger", | ||
"version": "0.1.14", | ||
"version": "0.1.20", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -50,2 +50,3 @@ # kitten-logger | ||
`KITTEN_LOGGER_RETENTION_FILENAME` | Filename where to write logs. Default is `out`; | ||
`KITTEN_LOGGER_IS_LOADED` | If `true`, kitten-logger will prefix all logs by `K_LOG` for sub instances of kitten-logger. | ||
@@ -52,0 +53,0 @@ ### Initialisation `kittenLogger.init` |
@@ -1,5 +0,6 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const cluster = require('cluster'); | ||
const formatters = require('./formatters'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const cluster = require('cluster'); | ||
const formatters = require('./formatters'); | ||
const { KITTEN_LOGGER_TAG } = require('./utils'); | ||
@@ -12,5 +13,5 @@ const originalWrite = process.stdout.write.bind(process.stdout); | ||
let LOGS_DIRECTORY = ''; | ||
let LOGS_FILE = ''; | ||
let outFilename = ''; | ||
const LOGS_DIRECTORY = process.env.KITTEN_LOGGER_RETENTION_DIRECTORY || 'logs'; | ||
const LOGS_FILE = process.env.KITTEN_LOGGER_RETENTION_FILENAME || 'out'; | ||
const outFilename = path.join(process.cwd(), LOGS_DIRECTORY, LOGS_FILE + '.log'); | ||
@@ -24,2 +25,19 @@ let rotationWritesBuffer = []; | ||
/** | ||
* Return msg to destination if Ttag defined | ||
* Prevent debug formatting | ||
* @param {Bbffer} chunk | ||
* @param {String} encoding | ||
* @param {Function} callback | ||
* @returns {Boolean} | ||
*/ | ||
function returnIfTag (chunk, encoding, callback) { | ||
if (chunk.slice(0, 5) === KITTEN_LOGGER_TAG) { | ||
destination(chunk.slice(5), encoding, callback); | ||
return true; | ||
} | ||
return false; | ||
} | ||
module.exports = { | ||
@@ -37,2 +55,6 @@ originalWrite, | ||
process.stdout.write = (chunk, encoding, callback) => { | ||
if (returnIfTag(chunk, encoding, callback)) { | ||
return; | ||
} | ||
destination( | ||
@@ -45,2 +67,6 @@ formatFn('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()), | ||
process.stderr.write = (chunk, encoding, callback) => { | ||
if (returnIfTag(chunk, encoding, callback)) { | ||
return; | ||
} | ||
destination( | ||
@@ -55,6 +81,2 @@ formatFn('ERROR', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()), | ||
setFile () { | ||
LOGS_DIRECTORY = process.env.KITTEN_LOGGER_RETENTION_DIRECTORY || 'logs'; | ||
LOGS_FILE = process.env.KITTEN_LOGGER_RETENTION_FILENAME || 'out'; | ||
outFilename = path.join(process.cwd(), LOGS_DIRECTORY, LOGS_FILE + '.log'); | ||
try { | ||
@@ -69,2 +91,6 @@ fs.mkdirSync(path.join(process.cwd(), LOGS_DIRECTORY)); | ||
process.stdout.write = (chunk, encoding, callback) => { | ||
if (returnIfTag(chunk, encoding, callback)) { | ||
return; | ||
} | ||
destination( | ||
@@ -77,2 +103,6 @@ formatters.format('DEBUG', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()), | ||
process.stderr.write = (chunk, encoding, callback) => { | ||
if (returnIfTag(chunk, encoding, callback)) { | ||
return; | ||
} | ||
destination( | ||
@@ -79,0 +109,0 @@ formatters.format('ERROR', cluster.isWorker ? 'worker' : 'master', process.pid, chunk.toString()), |
@@ -1,7 +0,8 @@ | ||
const utils = require('./utils'); | ||
const getTime = utils.getTime | ||
const getCurrentTimestamp = utils.getCurrentTimestamp; | ||
const COLORS = require('../colors'); | ||
const CSV_SEPARATOR = '\t'; | ||
const MAX_LENGTH = 60000; | ||
const utils = require('./utils'); | ||
const getTime = utils.getTime | ||
const getCurrentTimestamp = utils.getCurrentTimestamp; | ||
const COLORS = require('../colors'); | ||
const { KITTEN_LOGGER_TAG } = require('./utils'); | ||
const variables = require('./variables'); | ||
const CSV_SEPARATOR = '\t'; | ||
@@ -47,3 +48,3 @@ let formatters = {}; | ||
if (msg.constructor === String){ | ||
_msg = msg.slice(0, MAX_LENGTH); | ||
_msg = msg; | ||
} | ||
@@ -65,3 +66,3 @@ else { | ||
_out = _time + CSV_SEPARATOR + level + CSV_SEPARATOR + namespace + CSV_SEPARATOR + _msg + CSV_SEPARATOR + pid + CSV_SEPARATOR + _id; | ||
return _out + '\n'; | ||
return (variables.isLoggerChild && !variables.isInitialized ? KITTEN_LOGGER_TAG : '') + _out + '\n'; | ||
}, | ||
@@ -87,3 +88,3 @@ | ||
else if (msg.constructor === String){ | ||
_msg = msg.slice(0, MAX_LENGTH); | ||
_msg = msg; | ||
} | ||
@@ -107,4 +108,4 @@ else { | ||
_out = _time + CSV_SEPARATOR + level + CSV_SEPARATOR + namespace + CSV_SEPARATOR + _msg + CSV_SEPARATOR + pid + CSV_SEPARATOR + _id; | ||
return _out + '\n'; | ||
return (variables.isLoggerChild && !variables.isInitialized ? KITTEN_LOGGER_TAG : '') + _out + '\n'; | ||
} | ||
}; |
@@ -1,3 +0,4 @@ | ||
const filter = require('./filter'); | ||
const loggers = require('./logger'); | ||
const filter = require('./filter'); | ||
const loggers = require('./logger'); | ||
const variables = require('./variables'); | ||
@@ -7,2 +8,4 @@ module.exports = function init () { | ||
variables.isInitialized = true; | ||
filter.filter(); | ||
@@ -9,0 +12,0 @@ loggers.enable(); |
@@ -7,5 +7,10 @@ const fs = require('fs'); | ||
const LOG_RETENTION = process.env.KITTEN_LOGGER_RETENTION_DAYS || 10; | ||
var currentDay = ''; | ||
let LOG_RETENTION = 10; | ||
const envVar = parseInt(process.env.KITTEN_LOGGER_RETENTION_DAYS, 10); | ||
if (!isNaN(envVar)) { | ||
LOG_RETENTION = envVar; | ||
} | ||
var currentDay = ''; | ||
let currentRotationIterator = LOG_RETENTION; | ||
@@ -12,0 +17,0 @@ |
@@ -37,7 +37,5 @@ const cluster = require('cluster'); | ||
hasBeenTampered () { | ||
return process.stdout.write !== process.stdout.constructor.prototype.write || cluster.isWorker | ||
}, | ||
isTTY : tty.isatty(process.stdout.fd), | ||
isTTY : tty.isatty(process.stdout.fd) | ||
KITTEN_LOGGER_TAG : 'K_LOG' | ||
}; |
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
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
31519
18
780
201
17