Comparing version 0.0.3 to 0.0.4
@@ -0,1 +1,2 @@ | ||
let path = require("path"); | ||
let {datetimeUtils} = require('./datetimeUtils'); | ||
@@ -5,3 +6,52 @@ let {utils} = require("./utils"); | ||
let workdir = process.cwd(); | ||
/** | ||
* 取文件名的短名称 | ||
* 用于缩短日志文件名前缀的函数 | ||
* @param {string} filename 文件名 | ||
* @return {String} 去除当前路径的文件短名 | ||
*/ | ||
function shortpath(filename) { | ||
let ff = filename.replace(workdir, ''); | ||
let ext = path.extname(ff); | ||
let pp = path.dirname(ff); | ||
let basename = path.basename(ff,ext); | ||
let spltchar = '/'; | ||
if(pp.indexOf("\\") >= 0) { | ||
spltchar = "\\"; | ||
} | ||
if(pp === '\\' || pp === '/') { | ||
pp = ''; | ||
} | ||
if(pp.length > 0) { | ||
ff = path.dirname(ff) + spltchar + basename; | ||
} | ||
else { | ||
ff = basename; | ||
} | ||
let sss = ff.charAt(0); | ||
if (sss === '\\' || sss === '/') { | ||
ff = ff.slice(1); | ||
} | ||
return `${ff}`; | ||
} | ||
/** | ||
* 生成日志前缀 | ||
* @param {string} paramFilename 当前的文件名 | ||
* @param {...any} args 其它前缀 | ||
* @return {[shortpath, ...args]} 返回结果 | ||
*/ | ||
function logPrefix(paramFilename, ...args) { | ||
if(paramFilename === null || paramFilename === undefined) { | ||
return [...args]; | ||
} | ||
else { | ||
return [shortpath(paramFilename), ...args]; | ||
} | ||
} | ||
/** | ||
* 控制台日志类 | ||
@@ -95,3 +145,4 @@ */ | ||
let getLogger = function getLogger(tag) { | ||
return logManager.getLogger(tag); | ||
let [prefix] = logPrefix(tag); | ||
return logManager.getLogger(prefix); | ||
}; | ||
@@ -126,2 +177,2 @@ /** | ||
exports.getLocalLogger = getLocalLogger; | ||
exports.logPrefix = logPrefix; |
{ | ||
"name": "xmcommon", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "javascript common lib for es6", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# xmcommon | ||
一个js 通用库 | ||
github: https://github.com/zdhsoft/xmcommon | ||
npm: https://www.npmjs.com/package/xmcommon | ||
## 安装 | ||
npm install xmcommon | ||
# 版本变更说明 | ||
## 0.0.4 | ||
- \+ 增加日志前缀缩短处理 | ||
```js | ||
//文件:example/test.js | ||
let comm = require("xmcommon"); | ||
let log = comm.getLogger(__filename); | ||
log.info("hello world"); | ||
//[example\test 2018-10-31 19:29:09.802 INFO] hello world | ||
``` | ||
--- | ||
## 0.0.3 | ||
- 初始版本 |
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
49082
15
1503
23
2