This repository was archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatajo.log.js
More file actions
98 lines (75 loc) · 2.24 KB
/
atajo.log.js
File metadata and controls
98 lines (75 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
const bunyan = require('bunyan');
const fs = require('fs');
const path = require('path');
const os = require('os');
const mkdirp = require('mkdirp');
class Log {
constructor(release, logpath) {
//CHECK IF LOG LOCATION EXISTS
try {
var stats = fs.statSync(logpath);
} catch (e) {
console.log("CREATING LOG PATH : " + logpath);
mkdirp(logpath);
}
const LogLevel = {
DEBUG: 'debug',
INFO: 'info',
WARN: 'warning',
ERROR: 'error'
};
let streams = [{
stream: process.stdout,
level: LogLevel.DEBUG
}];
if (release == 'prd') {
const logFile = path.join(logpath, 'prd.log');
fs.stat(logFile, function(err, stats) {
if (err) {
fs.writeFileSync(logFile, '');
}
streams = [{
path: logFile,
level: LogLevel.WARN
}];
});
} else if (release == 'qas') {
const logFile = path.join(logpath, 'qas.log');
fs.stat(logFile, function(err, stats) {
if (err) {
fs.writeFileSync(logFile, '');
}
streams = [{
path: logFile,
level: LogLevel.INFO
}];
});
} else {
const logFile = path.join(logpath, 'dev.log');
fs.stat(logFile, function(err, stats) {
if (err) {
fs.writeFileSync(logFile, '');
}
streams = [{
path: logFile,
level: LogLevel.DEBUG
}];
});
}
this.log = bunyan.createLogger({
streams,
name: release + '@' + os.hostname() + ':',
serializers: {
req: bunyan.stdSerializers.req,
res: bunyan.stdSerializers.res,
error: bunyan.stdSerializers.err
}
});
return this.log;
}
child(tag) {
return this.log.child({ tag: tag });
}
}
module.exports = Log;