koatty_logger
Advanced tools
Comparing version 1.1.1 to 1.1.2
export declare type LogLevelType = "DEBUG" | "INFO" | "WARN" | "ERROR"; | ||
interface LoggerOpt { | ||
logLevel?: LogLevelType; | ||
logConsole?: boolean; | ||
logFile?: boolean; | ||
logFileLevel?: LogLevelType; | ||
logFilePath?: string; | ||
} | ||
/** | ||
@@ -12,13 +19,19 @@ * Logger | ||
private logFile; | ||
private logFileLevel; | ||
private logFilePath; | ||
/** | ||
* Creates an instance of ConsolePlus. | ||
* @memberof ConsolePlus | ||
* Creates an instance of Logger. | ||
* @param {LoggerOpt} [opt] | ||
* @memberof Logger | ||
*/ | ||
constructor(); | ||
constructor(opt?: LoggerOpt); | ||
/** | ||
* setLogConsole | ||
* getLevel | ||
*/ | ||
setLogConsole(t: boolean): void; | ||
getLevel(): string; | ||
/** | ||
* setLevel | ||
*/ | ||
setLevel(level: LogLevelType): void; | ||
/** | ||
* getLogConsole | ||
@@ -28,9 +41,9 @@ */ | ||
/** | ||
* setLevel | ||
* setLogConsole | ||
*/ | ||
setLevel(level: LogLevelType): void; | ||
setLogConsole(t: boolean): void; | ||
/** | ||
* getLevel | ||
* getLogFile | ||
*/ | ||
getLevel(): string; | ||
getLogFile(): boolean; | ||
/** | ||
@@ -41,9 +54,9 @@ * setLogFile | ||
/** | ||
* getLogFile | ||
* getLogFileLevel | ||
*/ | ||
getLogFile(): boolean; | ||
getLogFileLevel(): string; | ||
/** | ||
* setLogPath | ||
* setLogFileLevel | ||
*/ | ||
setLogFilePath(path: string): void; | ||
setLogFileLevel(level: LogLevelType): void; | ||
/** | ||
@@ -54,2 +67,6 @@ * getLogFilePath | ||
/** | ||
* setLogPath | ||
*/ | ||
setLogFilePath(path: string): void; | ||
/** | ||
* 格式化 | ||
@@ -152,1 +169,2 @@ * | ||
export declare const DefaultLogger: Logger; | ||
export {}; |
@@ -8,4 +8,4 @@ "use strict"; | ||
* @Date: 2020-11-20 17:40:48 | ||
* @LastEditors: linyyyang<linyyyang@tencent.com> | ||
* @LastEditTime: 2020-12-03 15:10:12 | ||
* @LastEditors: Please set LastEditors | ||
* @LastEditTime: 2021-06-22 10:26:38 | ||
* @License: BSD (3-Clause) | ||
@@ -57,43 +57,70 @@ * @Copyright (c) - <richenlin(at)gmail.com> | ||
/** | ||
* Creates an instance of ConsolePlus. | ||
* @memberof ConsolePlus | ||
* Creates an instance of Logger. | ||
* @param {LoggerOpt} [opt] | ||
* @memberof Logger | ||
*/ | ||
constructor() { | ||
// 默认是最初的日志级别,改变这个值。可以改变日志输出的结果 | ||
this.logLevel = "DEBUG"; | ||
constructor(opt) { | ||
var _a, _b, _c, _d, _e; | ||
// 控制台日志级别 | ||
this.logLevel = "INFO"; | ||
// 默认打开控制台日志 | ||
this.logConsole = true; | ||
// 空对象 | ||
this.emptyObj = {}; | ||
// 文件日志开关 | ||
this.logFile = false; | ||
this.emptyObj = {}; | ||
// 文件日志级别 | ||
this.logFileLevel = "WARN"; | ||
if (process.env.LOGS_LEVEL && LogLevelObj[process.env.LOGS_LEVEL]) { | ||
this.logLevel = process.env.LOGS_LEVEL; | ||
this.logFileLevel = process.env.LOGS_LEVEL; | ||
} | ||
if (process.env.NODE_ENV === 'production') { | ||
this.logConsole = false; | ||
this.logFile = true; | ||
this.logFileLevel = "INFO"; | ||
} | ||
if (process.env.LOGS_WRITE) { | ||
this.logFile = !!process.env.LOGS_WRITE; | ||
} | ||
if (process.env.LOGS_PATH) { | ||
this.logFilePath = process.env.LOGS_PATH; | ||
} | ||
if (!helper.isTrueEmpty(opt)) { | ||
this.logLevel = (_a = opt.logLevel) !== null && _a !== void 0 ? _a : this.logLevel; | ||
this.logConsole = (_b = opt.logConsole) !== null && _b !== void 0 ? _b : this.logConsole; | ||
this.logFile = (_c = opt.logFile) !== null && _c !== void 0 ? _c : this.logFile; | ||
this.logFileLevel = (_d = opt.logFileLevel) !== null && _d !== void 0 ? _d : this.logFileLevel; | ||
this.logFilePath = (_e = opt.logFilePath) !== null && _e !== void 0 ? _e : this.logFilePath; | ||
} | ||
} | ||
/** | ||
* setLogConsole | ||
* getLevel | ||
*/ | ||
setLogConsole(t) { | ||
this.logConsole = t; | ||
getLevel() { | ||
return this.logLevel; | ||
} | ||
/** | ||
* setLevel | ||
*/ | ||
setLevel(level) { | ||
this.logLevel = level; | ||
} | ||
/** | ||
* getLogConsole | ||
*/ | ||
getLogConsole() { | ||
if (process.env.NODE_ENV === 'production') { | ||
this.logConsole = false; | ||
} | ||
return this.logConsole; | ||
} | ||
/** | ||
* setLevel | ||
* setLogConsole | ||
*/ | ||
setLevel(level) { | ||
this.logLevel = level; | ||
setLogConsole(t) { | ||
this.logConsole = t; | ||
} | ||
/** | ||
* getLevel | ||
* getLogFile | ||
*/ | ||
getLevel() { | ||
if (process.env.LOGS_LEVEL && LogLevelObj[process.env.LOGS_LEVEL]) { | ||
this.logLevel = process.env.LOGS_LEVEL; | ||
} | ||
return this.logLevel; | ||
getLogFile() { | ||
return this.logFile; | ||
} | ||
@@ -107,15 +134,12 @@ /** | ||
/** | ||
* getLogFile | ||
* getLogFileLevel | ||
*/ | ||
getLogFile() { | ||
if (process.env.LOGS_WRITE) { | ||
this.logFile = !!process.env.LOGS_WRITE; | ||
} | ||
return this.logFile; | ||
getLogFileLevel() { | ||
return this.logFileLevel; | ||
} | ||
/** | ||
* setLogPath | ||
* setLogFileLevel | ||
*/ | ||
setLogFilePath(path) { | ||
this.logFilePath = path; | ||
setLogFileLevel(level) { | ||
this.logFileLevel = level; | ||
} | ||
@@ -126,8 +150,11 @@ /** | ||
getLogFilePath() { | ||
if (process.env.LOGS_PATH) { | ||
this.logFilePath = process.env.LOGS_PATH; | ||
} | ||
return this.logFilePath; | ||
} | ||
/** | ||
* setLogPath | ||
*/ | ||
setLogFilePath(path) { | ||
this.logFilePath = path; | ||
} | ||
/** | ||
* 格式化 | ||
@@ -190,2 +217,6 @@ * | ||
try { | ||
const logLevel = this.getLevel(); | ||
if (LogLevelObj[level] < LogLevelObj[logLevel]) { | ||
return; | ||
} | ||
let formatted = false; | ||
@@ -201,4 +232,3 @@ // print console | ||
// record log files | ||
const logLevel = this.getLevel(); | ||
if (this.getLogFile() && LogLevelObj[level] >= LogLevelObj[logLevel]) { | ||
if (this.getLogFile()) { | ||
this.writeLogFile(level, name, args, formatted); | ||
@@ -205,0 +235,0 @@ } |
{ | ||
"name": "koatty_logger", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Logger for koatty.", | ||
"scripts": { | ||
"build": "del-cli --force dist && tsc", | ||
"eslint": "eslint --ext .ts,.js ./", | ||
"prepublishOnly": "npm test && npm run build", | ||
"test": "tslint 'src/**/*.ts'" | ||
"release": "standard-version", | ||
"test": "npm run eslint && npm run build && jest --passWithNoTests", | ||
"test:cov": "jest --collectCoverage --detectOpenHandles", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" | ||
}, | ||
@@ -45,12 +49,30 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@commitlint/cli": "^12.x.x", | ||
"@commitlint/config-conventional": "^12.x.x", | ||
"@types/cls-hooked": "^4.x.x", | ||
"@types/node": "^12.x.x", | ||
"del-cli": "^3.0.1", | ||
"ts-node": "^9.0.0", | ||
"tslint": "^6.1.3", | ||
"tslint-config-alloy": "^0.2.1", | ||
"typescript": "^4.1.2" | ||
"@typescript-eslint/eslint-plugin": "^4.x.x", | ||
"@typescript-eslint/parser": "^4.x.x", | ||
"conventional-changelog-cli": "^2.x.x", | ||
"del-cli": "^3.x.x", | ||
"eslint": "^7.x.x", | ||
"eslint-plugin-jest": "^24.x.x", | ||
"husky": "^6.x.x", | ||
"jest": "^27.x.x", | ||
"jest-html-reporters": "^2.x.x", | ||
"koatty_cacheable": "^1.x.x", | ||
"koatty_schedule": "^1.x.x", | ||
"standard-version": "^9.x.x", | ||
"ts-jest": "^27.x.x", | ||
"ts-node": "^10.x.x", | ||
"typescript": "^4.x.x" | ||
}, | ||
"dependencies": { | ||
"koatty_lib": "^1.x.x" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
} | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
1800874
13
673
19
10