Comparing version 1.0.0 to 1.0.1
@@ -35,5 +35,14 @@ /* | ||
this._attachCount = 0; | ||
this._state = 'idle'; | ||
this._closing = false; | ||
this._closed = false; | ||
} | ||
get closed() { | ||
return this._closed; | ||
} | ||
get closing() { | ||
return this._closing; | ||
} | ||
/** | ||
@@ -49,3 +58,3 @@ * | ||
let data = Array.isArray(meta) ? meta.slice() : | ||
(typeof meta === 'object' ? merge.clone(meta) : meta); | ||
(typeof meta === 'object' ? merge({}, meta) : meta); | ||
if (formatters) { | ||
@@ -66,3 +75,3 @@ formatters = Array.isArray(formatters) ? formatters : [formatters]; | ||
return new Promise((resolve, reject) => { | ||
if (this._attachCount || this._state === 'closed') | ||
if (this._attachCount || (this._closing || this._closed)) | ||
return resolve(); | ||
@@ -74,9 +83,11 @@ this.once('close', (err) => { | ||
}); | ||
if (this._state === 'closing') | ||
/* istanbul ignore next */ | ||
if (this._closing) | ||
return; | ||
this._state = 'closing'; | ||
this._closing = true; | ||
this._close((err) => { | ||
if (err) | ||
return this.emit('close', err); | ||
this._state = 'closed'; | ||
this._closing = false; | ||
this._closed = true; | ||
this.emit('close'); | ||
@@ -83,0 +94,0 @@ }); |
@@ -30,2 +30,3 @@ /* | ||
this._stream = options.stream; | ||
this._finished = this._stream && this._stream._writableState.finished; | ||
} | ||
@@ -52,5 +53,11 @@ | ||
this._stream = this._createStream(); | ||
this._finished = this._stream._writableState.finished; | ||
/* istanbul ignore else */ | ||
if (this._stream && !this._stream._writableState.destroyed) { | ||
this._state = 'idle'; | ||
if (!this._finished) { | ||
const streamFinishListener = this._streamFinishListener = () => { | ||
this._finished = true; | ||
}; | ||
this._closed = false; | ||
this._closing = false; | ||
this._stream.once('finish', streamFinishListener); | ||
/* istanbul ignore next */ | ||
@@ -62,2 +69,8 @@ this._stream.on('error', (...args) => this.emit('error', ...args)); | ||
_detach() { | ||
// if (this._stream) | ||
// this._stream.removeListener('finish', this._streamFinishListener); | ||
super._detach(); | ||
} | ||
/** | ||
@@ -68,7 +81,17 @@ * @override | ||
/* istanbul ignore next */ | ||
if (!this._stream || this._stream._writableState.destroyed) | ||
if (!this._stream || this._finished) | ||
return callback(); | ||
this._stream.once('close', callback); | ||
let c; | ||
const doCallback = () => { | ||
/* istanbul ignore else */ | ||
if (!c) callback(); | ||
c = true; | ||
}; | ||
this._stream.once('close', doCallback); | ||
this._stream.once('destroy', doCallback); | ||
this._stream.end(() => { | ||
this._stream.destroy(); | ||
/* istanbul ignore next */ | ||
if (this._stream.destroy) | ||
this._stream.destroy(); | ||
else doCallback(); | ||
}); | ||
@@ -75,0 +98,0 @@ } |
@@ -77,6 +77,6 @@ /* | ||
function colorize(colors) { | ||
colors = merge.defaults({ | ||
colors = merge({ | ||
timestamp: 'blueBright', | ||
label: 'cyan italic' | ||
}, colors || {}); | ||
}, colors, {functions: true}); | ||
colors.level = colors.level || null; | ||
@@ -172,3 +172,3 @@ | ||
if (typeof arg1 === 'object') { | ||
wrapFns = merge.clone(arg1); | ||
wrapFns = merge({}, arg1, {functions: true}); | ||
for (const n of Object.keys(wrapFns)) { | ||
@@ -208,3 +208,3 @@ const x = parseInt(wrapFns[n], 10); | ||
if (typeof arg1 === 'object') { | ||
indents = merge.clone(arg1); | ||
indents = merge({}, arg1); | ||
for (const n of Object.keys(indents)) { | ||
@@ -267,3 +267,3 @@ const x = parseInt(indents[n], 10); | ||
if (!options.strict) { | ||
const o = merge.filter((_, n) => !fields.hasOwnProperty(n))({}, output); | ||
const o = merge({}, output, {filter: (_, n) => !fields.hasOwnProperty(n)}); | ||
if (Object.keys(o).length) | ||
@@ -270,0 +270,0 @@ result += '\n' + JSON.stringify(o); |
@@ -13,2 +13,3 @@ /* | ||
const {EventEmitter} = require('events'); | ||
const {Writable} = require('stream'); | ||
const {ErrorEx, ArgumentError} = require('errorex'); | ||
@@ -20,2 +21,3 @@ const util = require('util'); | ||
const config = require('./config'); | ||
const StreamAppender = require('./appenders/StreamAppender'); | ||
@@ -191,7 +193,7 @@ /** | ||
* @param {!Object} options An object representing options | ||
* @param {Appender} [options.appender] An Appender instance. If value is not present, logger will make a deep lookup for parents till an appender instance found. | ||
* @param {Appender|Writable} [options.appender] An Appender or Writable stream instance. If value is not present, logger will make a deep lookup for parents till an appender instance found. | ||
* @param {boolean} [options.enabled=true] If true, logging will be enabled for this target, otherwise no log will be written to appender. Default: true | ||
* @param {Array<Function>} options.format An array of formatter methods | ||
* @param {Function} options.filter A function for filtering logs. If function returns true log will be written, otherwise will be ignored. | ||
* @param {string} options.level Logging level for this target. If value is not present, logger will make a deep lookup for parent targets. If no value found, logger's level will be used. | ||
* @param {Array<Function>} [options.format] An array of formatter methods | ||
* @param {Function} [options.filter] A function for filtering logs. If function returns true log will be written, otherwise will be ignored. | ||
* @param {string} [options.level] Logging level for this target. If value is not present, logger will make a deep lookup for parent targets. If no value found, logger's level will be used. | ||
* @return {Logger} This method returns this Logger for method chaining | ||
@@ -202,5 +204,10 @@ */ | ||
throw new ErrorEx('Target "%s" already exists'); | ||
const target = new LogTarget(this, name, | ||
!options ? {enabled: false} : | ||
(options instanceof Appender ? {appender: options} : options)); | ||
if (!options) | ||
options = {enabled: false}; | ||
if (options instanceof Appender) | ||
options = {appender: options}; | ||
/* istanbul ignore next */ | ||
if (options instanceof Writable) | ||
options = {appender: new StreamAppender({stream: options})}; | ||
const target = new LogTarget(this, name, options); | ||
target.on('change', () => this.changed()); | ||
@@ -265,8 +272,8 @@ this._targets[name] = target; | ||
if (typeof message === 'object') { | ||
merge.defaults(meta, message); | ||
merge(meta, message, {adjunct: true}); | ||
} else meta.message = util.format(message, ...args); | ||
if (this.defaultMeta) | ||
merge.defaults(meta, this.defaultMeta); | ||
merge(meta, this.defaultMeta, {adjunct: true}); | ||
if (this._meta) { | ||
merge.defaults(meta, this._meta); | ||
merge(meta, this._meta, {adjunct: true}); | ||
this._meta = null; | ||
@@ -273,0 +280,0 @@ } |
{ | ||
"name": "hixtory", | ||
"description": "Most flexible and fast logging library for NodeJS", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "Panates Ltd.", | ||
@@ -17,3 +17,7 @@ "contributors": [ | ||
"log", | ||
"logger" | ||
"logger", | ||
"logging", | ||
"bunyan", | ||
"pino", | ||
"loglevel" | ||
], | ||
@@ -24,3 +28,3 @@ "dependencies": { | ||
"fecha": "^3.0.2", | ||
"putil-merge": "^2.2.0", | ||
"putil-merge": "^3.1.1", | ||
"putil-promisify": "^1.3.0", | ||
@@ -27,0 +31,0 @@ "streamroller": "^0.8.5", |
@@ -101,4 +101,6 @@ # Hixtory | ||
- [Formatter propagation](#formatter-propagation) | ||
- [Build-in formatters](#build-in-formatters) | ||
- [Build-in formatters](#build-in-formatters) | ||
- [Appenders](#appenders) | ||
- [Core Appenders](#core-appenders) | ||
- [Creating custom appender](#creating-custom-appender) | ||
___ | ||
@@ -528,4 +530,14 @@ | ||
<hr/> | ||
## Appenders | ||
### Core Appenders | ||
### Creating custom appender | ||
--- | ||
## Node Compatibility | ||
@@ -532,0 +544,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
57147
1440
564
0
- Removedputil-merge@2.2.0(transitive)
Updatedputil-merge@^3.1.1