ac-logger 2.0.1 → 2.2.0
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 +14 -11
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
<a name="2.2.0"></a>
|
|
2
|
+
|
|
3
|
+
# [2.2.0](https://github.com/admiralcloud/ac-logger/compare/v2.1.0..v2.2.0) (2023-07-26 07:02:00)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Feature
|
|
7
|
+
|
|
8
|
+
* **App:** Add option for log rotation | MP | [e4b0b2163b1cefdd37aba734b7e28349a0a7e658](https://github.com/admiralcloud/ac-logger/commit/e4b0b2163b1cefdd37aba734b7e28349a0a7e658)
|
|
9
|
+
You can use winston-daily-rotate-file with ac-logger
|
|
10
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
11
|
+
<a name="2.1.0"></a>
|
|
12
|
+
|
|
13
|
+
# [2.1.0](https://github.com/admiralcloud/ac-logger/compare/v2.0.1..v2.1.0) (2023-07-26 06:39:56)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Feature
|
|
17
|
+
|
|
18
|
+
* **App:** Add option to add more transporters | MP | [1b26ccf1bee9dde56545e51f767f03def84328b7](https://github.com/admiralcloud/ac-logger/commit/1b26ccf1bee9dde56545e51f767f03def84328b7)
|
|
19
|
+
You can init the logger with additional transporters
|
|
20
|
+
Related issues: [/issues#undefined](https://github.com//issues/undefined)
|
|
1
21
|
<a name="2.0.1"></a>
|
|
2
22
|
|
|
3
23
|
## [2.0.1](https://github.com/admiralcloud/ac-logger/compare/v2.0.0..v2.0.1) (2023-07-26 06:22:11)
|
package/index.js
CHANGED
|
@@ -2,16 +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')
|
|
6
|
-
|
|
7
|
-
module.exports = (config) => {
|
|
8
|
-
const prefixFields = _.get(config, 'prefixFields', [])
|
|
9
|
-
const timestampFormat = _.get(config, 'timestampFormat', 'YYYY-MM-DD HH:mm:ss')
|
|
10
|
-
const level = _.get(config, 'level', (process.env.NODE_ENV === 'production' ? 'info' : 'verbose'))
|
|
11
|
-
const headLength = _.get(config, 'headLength', 80)
|
|
12
|
-
const padLength = _.get(config, 'padLength', 12)
|
|
13
|
-
const customLevels = _.get(config,'customLevels')
|
|
5
|
+
const { createLogger, format, transports, addColors } = require('winston')
|
|
6
|
+
require('winston-daily-rotate-file')
|
|
14
7
|
|
|
8
|
+
module.exports = ({ prefixFields = [], timestampFormat = 'YYYY-MM-DD HH:mm:ss', level = (process.env.NODE_ENV === 'production' ? 'info' : 'verbose'), headLength = 80, padLength = 12, customLevels, additionalTransports } = {}) => {
|
|
15
9
|
const precisionMap = [
|
|
16
10
|
{ precision: 1e6, name: 'ms' },
|
|
17
11
|
{ precision: 1e3, name: 'µs' },
|
|
@@ -37,7 +31,7 @@ module.exports = (config) => {
|
|
|
37
31
|
console.error(e)
|
|
38
32
|
if (_.get(e, 'message')) message += ' | ' + _.get(e, 'message', '')
|
|
39
33
|
}
|
|
40
|
-
return `${timestamp} ${level} ${fileName}${functionName}${subName}${prefixData}${message}
|
|
34
|
+
return `${timestamp} ${level} ${fileName}${functionName}${subName}${prefixData}${message}`
|
|
41
35
|
})
|
|
42
36
|
|
|
43
37
|
const logConfig = {
|
|
@@ -49,7 +43,7 @@ module.exports = (config) => {
|
|
|
49
43
|
format.errors({ stack: true }),
|
|
50
44
|
format(info => {
|
|
51
45
|
info.level = _.padEnd(info.level.toUpperCase(), 8)
|
|
52
|
-
return info
|
|
46
|
+
return info
|
|
53
47
|
})(),
|
|
54
48
|
format.colorize(),
|
|
55
49
|
format.splat(),
|
|
@@ -64,6 +58,15 @@ module.exports = (config) => {
|
|
|
64
58
|
const acLogger = createLogger(logConfig)
|
|
65
59
|
if (_.get(customLevels, 'colors')) addColors(_.get(customLevels, 'colors'))
|
|
66
60
|
|
|
61
|
+
// Array of objects with type (e.g. File) and options for that type
|
|
62
|
+
if (_.size(additionalTransports)) {
|
|
63
|
+
_.forEach(additionalTransports, additionalTransport => {
|
|
64
|
+
const transport = new transports[additionalTransport.type](additionalTransport.options)
|
|
65
|
+
if (_.has(additionalTransport, 'onRotate')) transport.on('rotate', additionalTransport.onRotate)
|
|
66
|
+
acLogger.add(transport)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
67
70
|
if (process.env.NODE_ENV === 'test') {
|
|
68
71
|
acLogger.add(new transports.File({
|
|
69
72
|
filename: 'test.log',
|
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.0
|
|
6
|
+
"version": "2.2.0",
|
|
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",
|