egg-logger
Advanced tools
Comparing version 1.7.1 to 1.8.0
1.8.0 / 2019-05-07 | ||
================== | ||
**fixes** | ||
* [[`bca447c`](http://github.com/eggjs/egg-logger/commit/bca447c76fd01af20c767f6233c656e3e758a073)] - fix: implicitly any type (#53) (吖猩 <<whx89768@alibaba-inc.com>>) | ||
* [[`dc90baa`](http://github.com/eggjs/egg-logger/commit/dc90baacf75d9dfe600df0f7f2c87719f3dfc8e5)] - fix: buffer error flush by pick #30 (#57) (TZ | 天猪 <<atian25@qq.com>>) | ||
* [[`683ddd1`](http://github.com/eggjs/egg-logger/commit/683ddd1f35a40009d7c4e9470de32aef3bf340bc)] - fix: buffer error flush (#56) (TZ | 天猪 <<atian25@qq.com>>) | ||
**others** | ||
* [[`9e0510f`](http://github.com/eggjs/egg-logger/commit/9e0510fba9414bc30b6a17ab13e4b6eafe8d1df2)] - feat: support contextFormatter, backport #51 (#52) (TZ | 天猪 <<atian25@qq.com>>) | ||
1.7.1 / 2018-07-09 | ||
@@ -3,0 +14,0 @@ ================== |
@@ -21,3 +21,4 @@ interface ILoggerLevel { | ||
file: string; | ||
formatter?: any; | ||
formatter?: (meta?: object) => string; | ||
contextFormatter?: (meta?: object) => string; | ||
jsonFile?: string; | ||
@@ -123,3 +124,3 @@ outputJSON?: boolean; | ||
export class EggLoggers extends Map { | ||
export class EggLoggers extends Map<string, Logger> { | ||
constructor(options: EggLoggersOptions); | ||
@@ -142,3 +143,3 @@ | ||
*/ | ||
set(name: string, logger: Logger); | ||
set(name: string, logger: Logger): this; | ||
@@ -150,3 +151,4 @@ [key: string]: any; | ||
level?: LoggerLevel; | ||
formatter?: any; | ||
formatter?: (meta?: object) => string; | ||
contextFormatter?: (meta?: object) => string; | ||
json?: boolean; | ||
@@ -153,0 +155,0 @@ encoding?: string; |
@@ -48,2 +48,6 @@ 'use strict'; | ||
}; | ||
Object.defineProperty(meta, 'ctx', { | ||
enumerable: false, | ||
value: this.ctx, | ||
}); | ||
this._logger.log(LEVEL, arguments, meta); | ||
@@ -50,0 +54,0 @@ }; |
@@ -41,2 +41,3 @@ 'use strict'; | ||
formatter: this.options.formatter, | ||
contextFormatter: this.options.contextFormatter, | ||
flushInterval: this.options.flushInterval, | ||
@@ -62,2 +63,3 @@ eol: this.options.eol, | ||
formatter: utils.consoleFormatter, | ||
contextFormatter: this.options.contextFormatter, | ||
eol: this.options.eol, | ||
@@ -64,0 +66,0 @@ }); |
@@ -55,3 +55,3 @@ 'use strict'; | ||
flush() { | ||
if (this._buf.length > 0) { | ||
if (this._buf.length > 0 && this.writable) { | ||
if (this.options.encoding === 'utf8') { | ||
@@ -58,0 +58,0 @@ this._stream.write(this._buf.join('')); |
@@ -56,3 +56,3 @@ 'use strict'; | ||
log(level, args, meta) { | ||
if (!this._stream) { | ||
if (!this.writable) { | ||
const err = new Error(`${this.options.file} log stream had been closed`); | ||
@@ -93,2 +93,11 @@ console.error(err.stack); | ||
/** | ||
* transport is writable | ||
* @return {Boolean} writable | ||
*/ | ||
get writable() { | ||
return this._stream && !this._stream.closed && this._stream.writable && !this._stream.destroyed; | ||
} | ||
/** | ||
* 创建一个 stream | ||
@@ -108,3 +117,4 @@ * @return {Stream} 返回一个 writeStream | ||
}; | ||
stream.on('error', onError); | ||
// only listen error once because stream will reload after error | ||
stream.once('error', onError); | ||
stream._onError = onError; | ||
@@ -111,0 +121,0 @@ return stream; |
@@ -18,7 +18,8 @@ 'use strict'; | ||
* @param {Object} options | ||
* - {String} [level = NONE] - 日志打印级别,打印的方法必须高于此配置方法。如配置了 info,debug 不会打印。 | ||
* - {Function} formatter - 格式化函数 | ||
* - {Boolean} [json = false] - 日志内容是否为 json 格式 | ||
* - {String} [encoding = utf8] - 文件编码,可选编码 {@link https://github.com/ashtuchkin/iconv-lite#supported-encodings} | ||
* - {String} [eol = os.EOL] - 换行符 | ||
* - {String} [level = NONE] - log level. ouput method must higher than this option. if level is `info`, `debug` will disabled | ||
* - {Function} formatter - format function | ||
* - {Function} contextFormatter - format function for context logger | ||
* - {Boolean} [json = false] - log format is json or not | ||
* - {String} [encoding = utf8] - log encodeing, see {@link https://github.com/ashtuchkin/iconv-lite#supported-encodings} | ||
* - {String} [eol = os.EOL] - end of line | ||
*/ | ||
@@ -38,2 +39,3 @@ constructor(options) { | ||
formatter: null, | ||
contextFormatter: null, | ||
json: false, | ||
@@ -40,0 +42,0 @@ encoding: 'utf8', |
@@ -83,3 +83,4 @@ 'use strict'; | ||
let output; | ||
const formatter = meta.formatter || options.formatter; | ||
let formatter = meta.formatter || options.formatter; | ||
if (meta.ctx && options.contextFormatter) formatter = options.contextFormatter; | ||
@@ -86,0 +87,0 @@ if (args[0] instanceof Error) { |
{ | ||
"name": "egg-logger", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "egg logger", | ||
@@ -55,10 +55,13 @@ "main": "index.js", | ||
"index.js", | ||
"index.d.ts", | ||
"lib" | ||
"lib", | ||
"index.d.ts" | ||
], | ||
"ci": { | ||
"version": "4, 6, 8, 9", | ||
"version": "4, 6, 8, 10", | ||
"license": true | ||
}, | ||
"publishConfig": { | ||
"tag": "latest-1" | ||
}, | ||
"license": "MIT" | ||
} |
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
44855
1173