koatty_logger
Advanced tools
Comparing version 1.2.12 to 1.3.0
@@ -5,12 +5,2 @@ # Changelog | ||
### [1.2.12](https://github.com/thinkkoa/koatty_logger/compare/v1.2.10...v1.2.12) (2021-12-01) | ||
### [1.2.10](https://github.com/thinkkoa/koatty_logger/compare/v1.2.8...v1.2.10) (2021-12-01) | ||
### [1.2.8](https://github.com/thinkkoa/koatty_logger/compare/v1.2.6...v1.2.8) (2021-12-01) | ||
### [1.2.6](https://github.com/thinkkoa/koatty_logger/compare/v1.1.2...v1.2.6) (2021-11-23) | ||
# Changelog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
## [1.3.0](https://github.com/thinkkoa/koatty_logger/compare/v1.2.12...v1.3.0) (2021-12-18) |
@@ -1,11 +0,14 @@ | ||
export declare type LogLevelType = "DEBUG" | "INFO" | "WARN" | "ERROR"; | ||
interface LoggerOpt { | ||
logLevel?: LogLevelType; | ||
logConsole?: boolean; | ||
logFile?: boolean; | ||
logFileLevel?: LogLevelType; | ||
logFilePath?: string; | ||
sensFields?: Set<string>; | ||
} | ||
/*! | ||
* @Author: richen | ||
* @Date: 2021-12-18 12:57:35 | ||
* @License: BSD (3-Clause) | ||
* @Copyright (c) - <richenlin(at)gmail.com> | ||
* @HomePage: https://koatty.org/ | ||
*/ | ||
/** | ||
* DefaultLogger | ||
*/ | ||
export declare const DefaultLogger: Logger; | ||
/** | ||
* Logger | ||
@@ -16,9 +19,2 @@ * | ||
export declare class Logger { | ||
private logLevel; | ||
private logConsole; | ||
private emptyObj; | ||
private logFile; | ||
private logFileLevel; | ||
private logFilePath; | ||
private sensFields; | ||
/** | ||
@@ -88,3 +84,2 @@ * Creates an instance of Logger. | ||
*/ | ||
private format; | ||
/** | ||
@@ -100,3 +95,2 @@ * print console | ||
*/ | ||
private print; | ||
/** | ||
@@ -113,3 +107,2 @@ * write log file | ||
*/ | ||
private writeLogFile; | ||
/** | ||
@@ -151,11 +144,11 @@ * log Debug | ||
/** | ||
* log Custom | ||
* log Log | ||
* | ||
* Logger.Custom('msg') | ||
* Logger.Log('msg') | ||
* | ||
* Logger.Custom('name', 'msg') | ||
* Logger.Log('name', 'msg') | ||
* | ||
* Logger.Custom('name', 'color', 'msg') | ||
* Logger.Log('name', 'color', 'msg') | ||
* | ||
* Logger.Custom('name', 'color', 'msg1', 'msg2'...) | ||
* Logger.Log('name', 'color', 'msg1', 'msg2'...) | ||
* | ||
@@ -166,2 +159,6 @@ * @param {...any[]} args | ||
*/ | ||
Log(...args: any[]): void; | ||
/** | ||
* alias Log | ||
*/ | ||
Custom(...args: any[]): void; | ||
@@ -177,6 +174,14 @@ /** | ||
} | ||
/** | ||
* DefaultLogger | ||
*/ | ||
export declare const DefaultLogger: Logger; | ||
export {}; | ||
declare interface LoggerOpt { | ||
logLevel?: LogLevelType; | ||
logConsole?: boolean; | ||
logFile?: boolean; | ||
logFileLevel?: LogLevelType; | ||
logFilePath?: string; | ||
sensFields?: Set<string>; | ||
} | ||
export declare type LogLevelType = "DEBUG" | "INFO" | "WARN" | "ERROR"; | ||
export { } |
@@ -1,20 +0,142 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DefaultLogger = exports.Logger = void 0; | ||
const tslib_1 = require("tslib"); | ||
/*! | ||
* @Author: richen | ||
* @Date: 2021-12-18 12:57:25 | ||
* @License: BSD (3-Clause) | ||
* @Copyright (c) - <richenlin(at)gmail.com> | ||
* @HomePage: https://koatty.org/ | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var fs = require('fs'); | ||
var util = require('util'); | ||
var helper = require('koatty_lib'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); | ||
var util__default = /*#__PURE__*/_interopDefaultLegacy(util); | ||
var helper__namespace = /*#__PURE__*/_interopNamespace(helper); | ||
/* | ||
* @Description: | ||
* @Usage: | ||
* @Author: richen | ||
* @Date: 2021-11-04 20:31:43 | ||
* @LastEditTime: 2021-11-22 18:35:50 | ||
*/ | ||
/** | ||
* ShieldField | ||
* | ||
* @export | ||
* @param {string} str | ||
* @returns {*} {ShieldFieldRes} | ||
*/ | ||
function ShieldField(str) { | ||
const strArr = Object.assign([], str); | ||
const l = strArr.length; | ||
let start, end, res; | ||
if (l <= 1) { | ||
start = "*"; | ||
end = ""; | ||
res = "*"; | ||
} | ||
else if (l == 2) { | ||
start = strArr.slice(1).join(""); | ||
end = "*"; | ||
res = `${start}${end}`; | ||
} | ||
else { | ||
let num = Math.floor(l / 3); | ||
const mo = Math.floor(l % 3); | ||
let startNum = num; | ||
if (mo > 0) { | ||
num = num + 1; | ||
} | ||
if (startNum > 4) { | ||
num = num + (startNum - 4); | ||
startNum = 4; | ||
} | ||
const endNum = l - num - startNum; | ||
if (endNum > 4) { | ||
num = num + (endNum - 4); | ||
// endNum = 4; | ||
} | ||
// console.log(startNum, num, endNum) | ||
start = strArr.slice(0, startNum).join(""); | ||
end = strArr.slice(num + startNum).join(""); | ||
res = `${start}${"*".repeat(num)}${end}`; | ||
} | ||
return { res, start, end }; | ||
} | ||
/** | ||
* ShieldLog | ||
* | ||
* @export | ||
* @param {*} splat | ||
* @param {Set<string>} fields | ||
* @param {string} [keyName] | ||
* @returns {*} {*} | ||
*/ | ||
function ShieldLog(splat, fields, keyName) { | ||
if (fields.size === 0) { | ||
return splat; | ||
} | ||
if (splat === null) | ||
return splat; | ||
if (Array.isArray(splat)) { | ||
for (let index = 0; index < splat.length; index++) { | ||
splat[index] = ShieldLog(splat[index], fields); | ||
} | ||
return splat; | ||
} | ||
if (helper__namespace.isError(splat)) { | ||
return splat.message; | ||
} | ||
if (typeof splat !== "object") { | ||
if (fields.has(keyName)) { | ||
return ShieldField(splat).res; | ||
} | ||
return `${splat}`; | ||
} | ||
const cloneSplat = new splat.constructor(); | ||
for (const key in splat) { | ||
if (splat.hasOwnProperty(key)) { | ||
// 递归拷贝 | ||
cloneSplat[key] = ShieldLog(splat[key], fields, key); | ||
} | ||
} | ||
return cloneSplat; | ||
} | ||
/* | ||
* @Author: richen | ||
* @Date: 2020-11-20 17:40:48 | ||
* @LastEditors: Please set LastEditors | ||
* @LastEditTime: 2021-12-01 23:18:26 | ||
* @LastEditTime: 2021-12-18 00:40:08 | ||
* @License: BSD (3-Clause) | ||
* @Copyright (c) - <richenlin(at)gmail.com> | ||
*/ | ||
const fs_1 = (0, tslib_1.__importDefault)(require("fs")); | ||
const util_1 = (0, tslib_1.__importStar)(require("util")); | ||
const helper = (0, tslib_1.__importStar)(require("koatty_lib")); | ||
const shield_1 = require("./shield"); | ||
const fsOpen = (0, util_1.promisify)(fs_1.default.open); | ||
const fsAppend = (0, util_1.promisify)(fs_1.default.appendFile); | ||
const fsClose = (0, util_1.promisify)(fs_1.default.close); | ||
const fsOpen = util.promisify(fs__default["default"].open); | ||
const fsAppend = util.promisify(fs__default["default"].appendFile); | ||
const fsClose = util.promisify(fs__default["default"].close); | ||
const styles = { | ||
@@ -87,3 +209,3 @@ 'bold': ['\x1B[1m', '\x1B[22m'], | ||
} | ||
if (!helper.isTrueEmpty(opt)) { | ||
if (!helper__namespace.isTrueEmpty(opt)) { | ||
this.logLevel = (_a = opt.logLevel) !== null && _a !== void 0 ? _a : this.logLevel; | ||
@@ -181,3 +303,3 @@ this.logConsole = (_b = opt.logConsole) !== null && _b !== void 0 ? _b : this.logConsole; | ||
try { | ||
const params = [`[${helper.dateTime('', '')}]`, `[${name}]`, ...(0, shield_1.ShieldLog)(args, this.sensFields)]; | ||
const params = [`[${helper__namespace.dateTime('', '')}]`, `[${name}]`, ...ShieldLog(args, this.sensFields)]; | ||
if (level === "DEBUG") { | ||
@@ -188,3 +310,3 @@ Error.captureStackTrace(this.emptyObj); | ||
} | ||
return util_1.default.format.apply(null, params); | ||
return util__default["default"].format.apply(null, params); | ||
} | ||
@@ -246,4 +368,4 @@ catch (e) { | ||
const logFilePath = this.getLogFilePath(); | ||
if (!helper.isDir(logFilePath)) { | ||
await helper.mkDir(logFilePath); | ||
if (!helper__namespace.isDir(logFilePath)) { | ||
await helper__namespace.mkDir(logFilePath); | ||
} | ||
@@ -254,3 +376,3 @@ let params = msgs; | ||
} | ||
const file = `${logFilePath}${helper.sep}${name ? `${name}_` : ''}${helper.dateTime('', 'YYYY-MM-DD')}.log`; | ||
const file = `${logFilePath}${helper__namespace.sep}${name ? `${name}_` : ''}${helper__namespace.dateTime('', 'YYYY-MM-DD')}.log`; | ||
const fd = await fsOpen(file, 'a'); | ||
@@ -315,11 +437,11 @@ // tslint:disable-next-line: no-null-keyword | ||
/** | ||
* log Custom | ||
* log Log | ||
* | ||
* Logger.Custom('msg') | ||
* Logger.Log('msg') | ||
* | ||
* Logger.Custom('name', 'msg') | ||
* Logger.Log('name', 'msg') | ||
* | ||
* Logger.Custom('name', 'color', 'msg') | ||
* Logger.Log('name', 'color', 'msg') | ||
* | ||
* Logger.Custom('name', 'color', 'msg1', 'msg2'...) | ||
* Logger.Log('name', 'color', 'msg1', 'msg2'...) | ||
* | ||
@@ -330,3 +452,3 @@ * @param {...any[]} args | ||
*/ | ||
Custom(...args) { | ||
Log(...args) { | ||
// tslint:disable-next-line: one-variable-per-declaration | ||
@@ -349,2 +471,8 @@ let name = "", color = "white", msgs = []; | ||
/** | ||
* alias Log | ||
*/ | ||
Custom(...args) { | ||
return this.Log(args); | ||
} | ||
/** | ||
* write log file | ||
@@ -369,7 +497,8 @@ * | ||
} | ||
exports.Logger = Logger; | ||
/** | ||
* DefaultLogger | ||
*/ | ||
exports.DefaultLogger = new Logger(); | ||
//# sourceMappingURL=index.js.map | ||
const DefaultLogger = new Logger(); | ||
exports.DefaultLogger = DefaultLogger; | ||
exports.Logger = Logger; |
@@ -28,4 +28,2 @@ /** | ||
'ts-jest': { | ||
// 是否使用 babel 配置来转译 | ||
babelConfig: true, | ||
// 编译 Typescript 所依赖的配置 | ||
@@ -32,0 +30,0 @@ tsconfig: '<rootDir>/tsconfig.json', |
{ | ||
"name": "koatty_logger", | ||
"version": "1.2.12", | ||
"version": "1.3.0", | ||
"description": "Logger for koatty.", | ||
"scripts": { | ||
"build": "del-cli --force dist && tsc", | ||
"build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp", | ||
"build:cp": "node scripts/postBuild && copyfiles package.json LICENSE README.md dist/", | ||
"build:js": "del-cli --force dist && npx rollup -c", | ||
"build:doc": "del-cli --force docs/api && npx api-documenter markdown --input temp --output docs/api", | ||
"build:dts": "del-cli --force temp && npx tsc && npx api-extractor run --local --verbose", | ||
"eslint": "eslint --ext .ts,.js ./", | ||
"prepublishOnly": "npm test && npm run build", | ||
"release": "npm run prepublishOnly && standard-version", | ||
"prerelease": "npm test && npm run build", | ||
"release": "standard-version", | ||
"release:pre": "npm run release -- --prerelease", | ||
"release:major": "npm run release -- --release-as major", | ||
"release:minor": "npm run release -- --release-as minor", | ||
"pub": "git push --follow-tags origin && npm publish", | ||
@@ -50,8 +58,5 @@ "test": "npm run eslint && jest --passWithNoTests", | ||
"devDependencies": { | ||
"@babel/core": "^7.x.x", | ||
"@babel/plugin-proposal-decorators": "^7.x.x", | ||
"@babel/preset-env": "^7.x.x", | ||
"@babel/preset-typescript": "^7.x.x", | ||
"@commitlint/cli": "^12.x.x", | ||
"@commitlint/config-conventional": "^15.x.x", | ||
"@microsoft/api-documenter": "^7.x.x", | ||
"@microsoft/api-extractor": "^7.x.x", | ||
"@rollup/plugin-json": "^4.x.x", | ||
"@types/jest": "^27.x.x", | ||
@@ -62,3 +67,6 @@ "@types/koa": "^2.x.x", | ||
"@typescript-eslint/parser": "^5.x.x", | ||
"commitlint": "^15.x.x", | ||
"commitlint-config-gitmoji": "^2.x.x", | ||
"conventional-changelog-cli": "^2.x.x", | ||
"copyfiles": "^2.x.x", | ||
"del-cli": "^4.x.x", | ||
@@ -70,2 +78,4 @@ "eslint": "^8.x.x", | ||
"jest-html-reporters": "^2.x.x", | ||
"rollup": "^2.x.x", | ||
"rollup-plugin-typescript2": "^0.x.x", | ||
"standard-version": "^9.x.x", | ||
@@ -72,0 +82,0 @@ "ts-jest": "^27.x.x", |
@@ -14,5 +14,6 @@ { | ||
"declaration": true /* Generates corresponding '.d.ts' file. */, | ||
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
"sourceMap": true /* Generates corresponding '.map' file. */, | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
"outDir": "./dist/" /* Redirect output structure to the directory. */, | ||
"outDir": "./temp" /* Redirect output structure to the directory. */, | ||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
@@ -25,3 +26,3 @@ "removeComments": false /* Do not emit comments to output. */, | ||
/* Strict Type-Checking Options */ | ||
"stripInternal": true /* Enable all strict type-checking options. */, | ||
"stripInternal": true, /* Enable all strict type-checking options. */ | ||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, | ||
@@ -53,2 +54,3 @@ // "strictNullChecks": true, /* Enable strict null checks. */ | ||
"esModuleInterop": true, | ||
"useUnknownInCatchVariables": false, /* Default catch clause variables as unknown instead of any. */ | ||
/* Source Map Options */ | ||
@@ -55,0 +57,0 @@ // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ |
Sorry, the diff of this file is not supported yet
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
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1846681
48
1727
24
19
1