ac-logger 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/index.js +25 -20
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
<a name="2.2.1"></a>
|
|
2
|
+
|
|
3
|
+
## [2.2.1](https://github.com/admiralcloud/ac-logger/compare/v2.2.0..v2.2.1) (2023-07-26 08:32:44)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fix
|
|
7
|
+
|
|
8
|
+
* **App:** Add more flexibility for transporters | MP | [e661253e0dd6f68165941aeb9fb5a2c2ed6483d7](https://github.com/admiralcloud/ac-logger/commit/e661253e0dd6f68165941aeb9fb5a2c2ed6483d7)
|
|
9
|
+
You can create logger without default console log.
|
|
10
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
11
|
+
<a name="2.2.0"></a>
|
|
12
|
+
|
|
13
|
+
# [2.2.0](https://github.com/admiralcloud/ac-logger/compare/v2.1.0..v2.2.0) (2023-07-26 07:02:00)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Feature
|
|
17
|
+
|
|
18
|
+
* **App:** Add option for log rotation | MP | [e4b0b2163b1cefdd37aba734b7e28349a0a7e658](https://github.com/admiralcloud/ac-logger/commit/e4b0b2163b1cefdd37aba734b7e28349a0a7e658)
|
|
19
|
+
You can use winston-daily-rotate-file with ac-logger
|
|
20
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
1
21
|
<a name="2.1.0"></a>
|
|
2
22
|
|
|
3
23
|
# [2.1.0](https://github.com/admiralcloud/ac-logger/compare/v2.0.1..v2.1.0) (2023-07-26 06:39:56)
|
package/index.js
CHANGED
|
@@ -2,9 +2,10 @@ const _ = require('lodash')
|
|
|
2
2
|
const moment = require('moment')
|
|
3
3
|
const path = require('path')
|
|
4
4
|
|
|
5
|
-
const { createLogger, format, transports, addColors } = require('winston')
|
|
5
|
+
const { createLogger, format, transports, addColors } = require('winston')
|
|
6
|
+
require('winston-daily-rotate-file')
|
|
6
7
|
|
|
7
|
-
module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss', level = (process.env.NODE_ENV === 'production' ? 'info' : 'verbose'), headLength = 80, padLength = 12, customLevels,
|
|
8
|
+
module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss', level = (process.env.NODE_ENV === 'production' ? 'info' : 'verbose'), headLength = 80, padLength = 12, customLevels, transporters = [] } = {}) => {
|
|
8
9
|
const precisionMap = [
|
|
9
10
|
{ precision: 1e6, name: 'ms' },
|
|
10
11
|
{ precision: 1e3, name: 'µs' },
|
|
@@ -30,9 +31,28 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
|
|
|
30
31
|
console.error(e)
|
|
31
32
|
if (_.get(e, 'message')) message += ' | ' + _.get(e, 'message', '')
|
|
32
33
|
}
|
|
33
|
-
return `${timestamp} ${level} ${fileName}${functionName}${subName}${prefixData}${message}
|
|
34
|
+
return `${timestamp} ${level} ${fileName}${functionName}${subName}${prefixData}${message}`
|
|
34
35
|
})
|
|
35
36
|
|
|
37
|
+
const logTransports = []
|
|
38
|
+
if (!_.size(transporters)) {
|
|
39
|
+
// default behaviour
|
|
40
|
+
logTransports.push(new transports.Console())
|
|
41
|
+
if (process.env.NODE_ENV === 'test') {
|
|
42
|
+
logTransports.push(new transports.File({
|
|
43
|
+
filename: 'test.log',
|
|
44
|
+
level: 'debug'
|
|
45
|
+
}))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
_.forEach(transporters, item => {
|
|
50
|
+
const logTransport = new transports[item.type](item.options)
|
|
51
|
+
if (_.has(item, 'onRotate')) logTransport.on('rotate', item.onRotate)
|
|
52
|
+
logTransports.push(logTransport)
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
36
56
|
const logConfig = {
|
|
37
57
|
level,
|
|
38
58
|
format: format.combine(
|
|
@@ -42,34 +62,19 @@ module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss',
|
|
|
42
62
|
format.errors({ stack: true }),
|
|
43
63
|
format(info => {
|
|
44
64
|
info.level = _.padEnd(info.level.toUpperCase(), 8)
|
|
45
|
-
return info
|
|
65
|
+
return info
|
|
46
66
|
})(),
|
|
47
67
|
format.colorize(),
|
|
48
68
|
format.splat(),
|
|
49
69
|
myFormat
|
|
50
70
|
),
|
|
51
|
-
transports:
|
|
52
|
-
new transports.Console()
|
|
53
|
-
]
|
|
71
|
+
transports: logTransports
|
|
54
72
|
}
|
|
55
73
|
if (_.get(customLevels, 'levels')) _.set(logConfig, 'levels', _.get(customLevels, 'levels'))
|
|
56
74
|
|
|
57
75
|
const acLogger = createLogger(logConfig)
|
|
58
76
|
if (_.get(customLevels, 'colors')) addColors(_.get(customLevels, 'colors'))
|
|
59
|
-
|
|
60
|
-
// Array of objects with type (e.g. File) and options for that type
|
|
61
|
-
if (_.size(additionalTransports)) {
|
|
62
|
-
_.forEach(additionalTransports, transport => {
|
|
63
|
-
acLogger.add(new transports[transport.type](transport.options))
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
77
|
|
|
67
|
-
if (process.env.NODE_ENV === 'test') {
|
|
68
|
-
acLogger.add(new transports.File({
|
|
69
|
-
filename: 'test.log',
|
|
70
|
-
level: 'debug'
|
|
71
|
-
}))
|
|
72
|
-
}
|
|
73
78
|
|
|
74
79
|
const headline = (params) => {
|
|
75
80
|
acLogger.info('')
|
package/package.json
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
"author": "Mark Poepping (https://www.admiralcloud.com)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "admiralcloud/ac-logger",
|
|
6
|
-
"version": "2.1
|
|
6
|
+
"version": "2.2.1",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"lodash": "^4.17.21",
|
|
9
9
|
"moment": "^2.29.4",
|
|
10
|
-
"winston": "^3.10.0"
|
|
10
|
+
"winston": "^3.10.0",
|
|
11
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
13
14
|
"ac-semantic-release": "^0.4.2",
|