Skip to content

Commit aa5fde6

Browse files
committed
增加clientId 的输出,应对多进程启动说对进程的区分
1 parent 04d49f1 commit aa5fde6

3 files changed

Lines changed: 12 additions & 19 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Record log info to logfile, info log by date, error log by error.code
1111
<pre>
1212
const Logger = require('@open-node/logger');
1313

14-
const logger = Logger({ errorLogPath, infoLogPath });
14+
const logger = Logger({ errorLogPath, infoLogPath }, deps, clientId);
1515
</pre>
1616

1717

@@ -38,8 +38,8 @@ const logger = Logger({ errorLogPath, infoLogPath });
3838
### Parameters
3939

4040
- `config` **[Object][9]** 配置信息,errorLogPath, infoLogPath, 必须包含
41-
- `config.errorLogPath`
42-
- `config.infoLogPath`
41+
- `config.errorLogPath`
42+
- `config.infoLogPath`
4343

4444
Returns **[Logger][10]** Instance
4545

@@ -52,7 +52,7 @@ Returns **[Logger][10]** Instance
5252
- `e` **[error][11]** error对象
5353
- `extra` **any?** 额外要记录的信息
5454

55-
Returns **void**
55+
Returns **void**
5656

5757
### info
5858

@@ -63,7 +63,7 @@ Returns **void**
6363
- `message` **[string][12]** 要记录的信息
6464
- `extra` **any?** 额外要记录的信息
6565

66-
Returns **void**
66+
Returns **void**
6767

6868
### logger
6969

@@ -78,7 +78,7 @@ Returns **void**
7878
- `errorHandler` **[function][13]?** 错误信息处理函数 (optional, default `e=>e.message`)
7979
- `argsHandler` **[function][13]?** 参数信息处理函数 (optional, default `JSON.stringify`)
8080

81-
Returns **[function][13]**
81+
Returns **[function][13]**
8282

8383
[1]: #logger
8484

‎package.json‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@open-node/logger",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "log recorder, info and error",
55
"main": "src/logger.js",
66
"scripts": {
@@ -11,19 +11,12 @@
1111
"release": "npm run readme && npm publish --registry=https://registry.npmjs.org --access=public",
1212
"release:github": "npm run readme && npm publish --registry=https://npm.pkg.github.com/"
1313
},
14-
"pre-commit": [
15-
"lint",
16-
"test"
17-
],
14+
"pre-commit": ["lint", "test"],
1815
"repository": {
1916
"type": "git",
2017
"url": "git+https://github.com/open-node/logger.git"
2118
},
22-
"keywords": [
23-
"debugger",
24-
"log",
25-
"logger"
26-
],
19+
"keywords": ["debugger", "log", "logger"],
2720
"author": "Redstone Zhao",
2821
"license": "MIT",
2922
"bugs": {

‎src/logger.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
88
* @class
99
* @return {Logger} Instance
1010
*/
11-
function Logger({ errorLogPath, infoLogPath, ignoreErrors }, { _ }) {
11+
function Logger({ errorLogPath, infoLogPath, ignoreErrors }, { _ }, clientId) {
1212
const makeDir = _.memoize(dir => {
1313
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
1414
});
@@ -37,7 +37,7 @@ function Logger({ errorLogPath, infoLogPath, ignoreErrors }, { _ }) {
3737
const dir = `${errorLogPath}/${today}`;
3838
makeDir(dir);
3939
const file = `${dir}/${code}.err`;
40-
const content = [time, e.message];
40+
const content = [time, clientId, e.message];
4141
if (e.data) content.push(JSON.stringify(e.data));
4242
if (extra != null) content.push(JSON.stringify(extra));
4343
if (e.stack) content.push(JSON.stringify(e.stack));
@@ -59,7 +59,7 @@ function Logger({ errorLogPath, infoLogPath, ignoreErrors }, { _ }) {
5959
const dir = `${infoLogPath}/${today}`;
6060
makeDir(dir);
6161
const file = `${dir}/info.log`;
62-
const content = [time, message];
62+
const content = [time, clientId, message];
6363
if (extra != null) content.push(JSON.stringify(extra));
6464
fs.appendFileSync(file, `${content.join("\t")}\n`);
6565
};

0 commit comments

Comments
 (0)