Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xmcommon

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xmcommon - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

example/test.js

55

lib/log.js

@@ -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;

2

package.json
{
"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
- 初始版本
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc