Skip to content

Commit 4c65469

Browse files
committed
add logger
1 parent c7a2d18 commit 4c65469

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Start",
6+
"type": "node",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/app.js",
9+
"stopOnEntry": false,
10+
"args": [],
11+
"cwd": "${workspaceRoot}",
12+
"preLaunchTask": null,
13+
"runtimeExecutable": null,
14+
"runtimeArgs": [
15+
"--nolazy", "--use_strict"
16+
],
17+
"env": {
18+
"NODE_ENV": "development"
19+
},
20+
"externalConsole": false,
21+
"sourceMaps": false,
22+
"outDir": null
23+
}
24+
]
25+
}

samples/node/web/log/winston/app.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const logger = require('./logger.js');
2+
3+
logger.info('start app...');
4+
try {
5+
throw new Error('APP ERROR!');
6+
} catch (e) {
7+
logger.error('error', e);
8+
}
9+
logger.info('app ended.');
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const winston = require('winston');
2+
3+
var logger = new winston.Logger({
4+
transports: [
5+
new winston.transports.Console({
6+
name: 'console',
7+
colorize: true,
8+
level: 'info',
9+
timestamp: true
10+
}),
11+
new winston.transports.File({
12+
name: 'info-file',
13+
filename: __dirname + '/info.log',
14+
level: 'info',
15+
}),
16+
new winston.transports.File({
17+
name: 'error-file',
18+
filename: __dirname + '/error.log',
19+
level: 'error',
20+
json: false,
21+
timestamp: function () {
22+
return new Date().toTimeString();
23+
}
24+
})
25+
]
26+
});
27+
28+
module.exports = logger;
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "logger",
3+
"version": "1.0.0",
4+
"description": "Log example",
5+
"main": "app.js",
6+
"scripts": {
7+
"start": "node app.js"
8+
},
9+
"keywords": [
10+
"log",
11+
"winston"
12+
],
13+
"author": "Michael Liao",
14+
"license": "Apache-2.0",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/michaelliao/learn-javascript.git"
18+
},
19+
"dependencies": {
20+
"winston": "2.3.1"
21+
}
22+
}

0 commit comments

Comments
 (0)