@verdaccio/logger 6.0.0-6-next.8 → 6.0.0-6-next.11
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 +50 -0
- package/build/logger.js +13 -15
- package/build/logger.js.map +1 -1
- package/package.json +6 -6
- package/src/logger.ts +12 -14
- package/test/logger.spec.ts +2 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @verdaccio/logger
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.11
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 82cb0f2b: feat!: config.logs throw an error, logging config not longer accept array or logs property
|
|
8
|
+
|
|
9
|
+
### 💥 Breaking change
|
|
10
|
+
|
|
11
|
+
This is valid
|
|
12
|
+
|
|
13
|
+
```yaml
|
|
14
|
+
log: { type: stdout, format: pretty, level: http }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This is invalid
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
logs: { type: stdout, format: pretty, level: http }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
or
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
logs:
|
|
27
|
+
- [{ type: stdout, format: pretty, level: http }]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [82cb0f2b]
|
|
33
|
+
- Updated dependencies [5167bb52]
|
|
34
|
+
- @verdaccio/core@6.0.0-6-next.5
|
|
35
|
+
|
|
36
|
+
## 6.0.0-6-next.10
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- b78f3525: Fix re-opening log files using SIGUSR2
|
|
41
|
+
|
|
42
|
+
## 6.0.0-6-next.9
|
|
43
|
+
|
|
44
|
+
### Major Changes
|
|
45
|
+
|
|
46
|
+
- 730b5d8c: feat: upgrade to pino v7
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [730b5d8c]
|
|
51
|
+
- @verdaccio/logger-prettify@6.0.0-6-next.6
|
|
52
|
+
|
|
3
53
|
## 6.0.0-6-next.8
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/build/logger.js
CHANGED
|
@@ -36,11 +36,11 @@ const DEFAULT_LOG_FORMAT = isProd() ? 'json' : 'pretty';
|
|
|
36
36
|
|
|
37
37
|
function createLogger(options = {
|
|
38
38
|
level: 'http'
|
|
39
|
-
}, destination = _pino.default.destination(1),
|
|
39
|
+
}, destination = _pino.default.destination(1), prettyPrintOptions = {
|
|
40
40
|
// we hide warning since the prettifier should not be used in production
|
|
41
41
|
// https://getpino.io/#/docs/pretty?id=prettifier-api
|
|
42
42
|
suppressFlushSyncWarning: true
|
|
43
|
-
}) {
|
|
43
|
+
}, format = DEFAULT_LOG_FORMAT) {
|
|
44
44
|
if (_lodash.default.isNil(format)) {
|
|
45
45
|
format = DEFAULT_LOG_FORMAT;
|
|
46
46
|
}
|
|
@@ -119,16 +119,7 @@ function setup(options = DEFAULT_LOGGER_CONF) {
|
|
|
119
119
|
var _loggerConfig;
|
|
120
120
|
|
|
121
121
|
debug('setup logger');
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (isLegacyConf) {
|
|
125
|
-
_core.warningUtils.emit(_core.warningUtils.Codes.VERDEP002);
|
|
126
|
-
} // verdaccio 5 does not allow multiple logger configuration
|
|
127
|
-
// backward compatible, pick only the first option
|
|
128
|
-
// next major will thrown an error
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
let loggerConfig = isLegacyConf ? options[0] : options;
|
|
122
|
+
let loggerConfig = options;
|
|
132
123
|
|
|
133
124
|
if (!((_loggerConfig = loggerConfig) !== null && _loggerConfig !== void 0 && _loggerConfig.level)) {
|
|
134
125
|
loggerConfig = Object.assign({}, {
|
|
@@ -142,14 +133,21 @@ function setup(options = DEFAULT_LOGGER_CONF) {
|
|
|
142
133
|
|
|
143
134
|
if (loggerConfig.type === 'file') {
|
|
144
135
|
debug('logging file enabled');
|
|
145
|
-
|
|
136
|
+
|
|
137
|
+
const destination = _pino.default.destination(loggerConfig.path);
|
|
138
|
+
|
|
139
|
+
process.on('SIGUSR2', () => destination.reopen()); // @ts-ignore
|
|
140
|
+
|
|
141
|
+
exports.logger = logger = createLogger(pinoConfig, destination, loggerConfig.format); // @ts-ignore
|
|
146
142
|
} else if (loggerConfig.type === 'rotating-file') {
|
|
147
143
|
_core.warningUtils.emit(_core.warningUtils.Codes.VERWAR003);
|
|
148
144
|
|
|
149
|
-
debug('logging stdout enabled');
|
|
145
|
+
debug('logging stdout enabled'); // @ts-ignore
|
|
146
|
+
|
|
150
147
|
exports.logger = logger = createLogger(pinoConfig, _pino.default.destination(1), loggerConfig.format);
|
|
151
148
|
} else {
|
|
152
|
-
debug('logging stdout enabled');
|
|
149
|
+
debug('logging stdout enabled'); // @ts-ignore
|
|
150
|
+
|
|
153
151
|
exports.logger = logger = createLogger(pinoConfig, _pino.default.destination(1), loggerConfig.format);
|
|
154
152
|
}
|
|
155
153
|
|
package/build/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logger.ts"],"names":["debug","logger","isProd","process","env","NODE_ENV","DEFAULT_LOG_FORMAT","createLogger","options","level","destination","pino","format","prettyPrintOptions","suppressFlushSyncWarning","_","isNil","pinoConfig","customLevels","http","serializers","err","stdSerializers","req","res","Object","assign","prettifier","prettyPrint","levelFirst","prettyStamp","hooks","logMethod","inputArgs","method","templateObject","message","otherArgs","templateVars","getOwnPropertyNames","length","apply","hydratedMessage","DEBUG","on","lvl","val","prevLvl","prevVal","getLogger","warningUtils","emit","Codes","VERWAR002","DEFAULT_LOGGER_CONF","type","setup","isLegacyConf","Array","isArray","VERDEP002","loggerConfig","path","VERWAR003","finalHandler","final","finalLogger","event","info","error","exit"],"mappings":";;;;;;;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AA3C;AACA7D,IAAAA,OAAO,CAACyC,EAAR,CAAW,MAAX,EAAmB,MAAMoB,YAAY,CAAC,IAAD,EAAO,MAAP,CAArC;AACA7D,IAAAA,OAAO,CAACyC,EAAR,CAAW,mBAAX,EAAiCvB,GAAD,IAAS2C,YAAY,CAAC3C,GAAD,EAAM,mBAAN,CAArD;AACAlB,IAAAA,OAAO,CAACyC,EAAR,CAAW,QAAX,EAAqB,MAAMoB,YAAY,CAAC,IAAD,EAAO,QAAP,CAAvC;AACA7D,IAAAA,OAAO,CAACyC,EAAR,CAAW,SAAX,EAAsB,MAAMoB,YAAY,CAAC,IAAD,EAAO,SAAP,CAAxC;AACA7D,IAAAA,OAAO,CAACyC,EAAR,CAAW,SAAX,EAAsB,MAAMoB,YAAY,CAAC,IAAD,EAAO,SAAP,CAAxC;AACD;;AAED,SAAO/D,MAAP;AACD","sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport pino from 'pino';\n\nimport { warningUtils } from '@verdaccio/core';\nimport prettifier, { fillInMsgTemplate } from '@verdaccio/logger-prettify';\n\nconst debug = buildDebug('verdaccio:logger');\n\nexport let logger;\n\nfunction isProd() {\n return process.env.NODE_ENV === 'production';\n}\n\nconst DEFAULT_LOG_FORMAT = isProd() ? 'json' : 'pretty';\n\nexport type LogPlugin = {\n dest: string;\n options?: any[];\n};\n\nexport type LogType = 'file' | 'stdout';\nexport type LogFormat = 'json' | 'pretty-timestamped' | 'pretty';\n\nexport function createLogger(\n options = { level: 'http' },\n destination = pino.destination(1),\n format: LogFormat = DEFAULT_LOG_FORMAT,\n prettyPrintOptions = {\n // we hide warning since the prettifier should not be used in production\n // https://getpino.io/#/docs/pretty?id=prettifier-api\n suppressFlushSyncWarning: true,\n }\n) {\n if (_.isNil(format)) {\n format = DEFAULT_LOG_FORMAT;\n }\n\n let pinoConfig = {\n customLevels: {\n http: 25,\n },\n ...options,\n level: options.level,\n serializers: {\n err: pino.stdSerializers.err,\n req: pino.stdSerializers.req,\n res: pino.stdSerializers.res,\n },\n };\n\n debug('has prettifier? %o', !isProd());\n // pretty logs are not allowed in production for performance reasons\n if ((format === DEFAULT_LOG_FORMAT || format !== 'json') && isProd() === false) {\n pinoConfig = Object.assign({}, pinoConfig, {\n prettifier,\n // more info\n // https://github.com/pinojs/pino-pretty/issues/37\n prettyPrint: {\n levelFirst: true,\n prettyStamp: format === 'pretty-timestamped',\n ...prettyPrintOptions,\n },\n });\n } else {\n pinoConfig = Object.assign({}, pinoConfig, {\n // more info\n // https://github.com/pinojs/pino/blob/v7.1.0/docs/api.md#hooks-object\n hooks: {\n logMethod(inputArgs, method) {\n const [templateObject, message, ...otherArgs] = inputArgs;\n const templateVars =\n !!templateObject && typeof templateObject === 'object'\n ? Object.getOwnPropertyNames(templateObject)\n : [];\n if (!message || !templateVars.length) return method.apply(this, inputArgs);\n const hydratedMessage = fillInMsgTemplate(message, templateObject, false);\n return method.apply(this, [templateObject, hydratedMessage, ...otherArgs]);\n },\n },\n });\n }\n const logger = pino(pinoConfig, destination);\n\n if (process.env.DEBUG) {\n logger.on('level-change', (lvl, val, prevLvl, prevVal) => {\n debug('%s (%d) was changed to %s (%d)', lvl, val, prevLvl, prevVal);\n });\n }\n\n return logger;\n}\n\nexport function getLogger() {\n if (_.isNil(logger)) {\n // FIXME: not sure about display here a warning\n warningUtils.emit(warningUtils.Codes.VERWAR002);\n return;\n }\n\n return logger;\n}\n\nconst DEFAULT_LOGGER_CONF: LoggerConfigItem = {\n type: 'stdout',\n format: 'pretty',\n level: 'http',\n};\n\nexport type LoggerConfigItem = {\n type?: LogType;\n plugin?: LogPlugin;\n format?: LogFormat;\n path?: string;\n level?: string;\n};\n\nexport type LoggerConfig = LoggerConfigItem[];\n\nexport function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_CONF) {\n debug('setup logger');\n const isLegacyConf = Array.isArray(options);\n if (isLegacyConf) {\n warningUtils.emit(warningUtils.Codes.VERDEP002);\n }\n\n // verdaccio 5 does not allow multiple logger configuration\n // backward compatible, pick only the first option\n // next major will thrown an error\n let loggerConfig = isLegacyConf ? options[0] : options;\n if (!loggerConfig?.level) {\n loggerConfig = Object.assign(\n {},\n {\n level: 'http',\n },\n loggerConfig\n );\n }\n const pinoConfig = { level: loggerConfig.level };\n if (loggerConfig.type === 'file') {\n debug('logging file enabled');\n logger = createLogger(pinoConfig, pino.destination(loggerConfig.path), loggerConfig.format);\n } else if (loggerConfig.type === 'rotating-file') {\n warningUtils.emit(warningUtils.Codes.VERWAR003);\n debug('logging stdout enabled');\n logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);\n } else {\n debug('logging stdout enabled');\n logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);\n }\n\n if (isProd()) {\n // why only on prod? https://github.com/pinojs/pino/issues/920#issuecomment-710807667\n const finalHandler = pino.final(logger, (err, finalLogger, event) => {\n finalLogger.info(`${event} caught`);\n if (err) {\n finalLogger.error(err, 'error caused exit');\n }\n process.exit(err ? 1 : 0);\n });\n\n process.on('uncaughtException', (err) => finalHandler(err, 'uncaughtException'));\n process.on('unhandledRejection', (err) => finalHandler(err as Error, 'unhandledRejection'));\n process.on('beforeExit', () => finalHandler(null, 'beforeExit'));\n process.on('exit', () => finalHandler(null, 'exit'));\n process.on('uncaughtException', (err) => finalHandler(err, 'uncaughtException'));\n process.on('SIGINT', () => finalHandler(null, 'SIGINT'));\n process.on('SIGQUIT', () => finalHandler(null, 'SIGQUIT'));\n process.on('SIGTERM', () => finalHandler(null, 'SIGTERM'));\n }\n\n return logger;\n}\n"],"file":"logger.js"}
|
|
1
|
+
{"version":3,"sources":["../src/logger.ts"],"names":["debug","logger","isProd","process","env","NODE_ENV","DEFAULT_LOG_FORMAT","createLogger","options","level","destination","pino","prettyPrintOptions","suppressFlushSyncWarning","format","_","isNil","pinoConfig","customLevels","http","serializers","err","stdSerializers","req","res","Object","assign","prettifier","prettyPrint","levelFirst","prettyStamp","hooks","logMethod","inputArgs","method","templateObject","message","otherArgs","templateVars","getOwnPropertyNames","length","apply","hydratedMessage","DEBUG","on","lvl","val","prevLvl","prevVal","getLogger","warningUtils","emit","Codes","VERWAR002","DEFAULT_LOGGER_CONF","type","setup","loggerConfig","path","reopen","VERWAR003","finalHandler","final","finalLogger","event","info","error","exit"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;AAEA,MAAMA,KAAK,GAAG,oBAAW,kBAAX,CAAd;AAEO,IAAIC,MAAJ;;;AAEP,SAASC,MAAT,GAAkB;AAChB,SAAOC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAhC;AACD;;AAED,MAAMC,kBAAkB,GAAGJ,MAAM,KAAK,MAAL,GAAc,QAA/C;;AAUO,SAASK,YAAT,CACLC,OAAO,GAAG;AAAEC,EAAAA,KAAK,EAAE;AAAT,CADL,EAELC,WAAW,GAAGC,cAAKD,WAAL,CAAiB,CAAjB,CAFT,EAGLE,kBAAkB,GAAG;AACnB;AACA;AACAC,EAAAA,wBAAwB,EAAE;AAHP,CAHhB,EAQLC,MAAiB,GAAGR,kBARf,EASL;AACA,MAAIS,gBAAEC,KAAF,CAAQF,MAAR,CAAJ,EAAqB;AACnBA,IAAAA,MAAM,GAAGR,kBAAT;AACD;;AAED,MAAIW,UAAU,GAAG;AACfC,IAAAA,YAAY,EAAE;AACZC,MAAAA,IAAI,EAAE;AADM,KADC;AAIf,OAAGX,OAJY;AAKfC,IAAAA,KAAK,EAAED,OAAO,CAACC,KALA;AAMfW,IAAAA,WAAW,EAAE;AACXC,MAAAA,GAAG,EAAEV,cAAKW,cAAL,CAAoBD,GADd;AAEXE,MAAAA,GAAG,EAAEZ,cAAKW,cAAL,CAAoBC,GAFd;AAGXC,MAAAA,GAAG,EAAEb,cAAKW,cAAL,CAAoBE;AAHd;AANE,GAAjB;AAaAxB,EAAAA,KAAK,CAAC,oBAAD,EAAuB,CAACE,MAAM,EAA9B,CAAL,CAlBA,CAmBA;;AACA,MAAI,CA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B,GAAD,IAASwC,YAAY,CAACxC,GAAD,EAAe,oBAAf,CAAtD;AACAlB,IAAAA,OAAO,CAACyC,EAAR,CAAW,YAAX,EAAyB,MAAMiB,YAAY,CAAC,IAAD,EAAO,YAAP,CAA3C;AACA1D,IAAAA,OAAO,CAACyC,EAAR,CAAW,MAAX,EAAmB,MAAMiB,YAAY,CAAC,IAAD,EAAO,MAAP,CAArC;AACA1D,IAAAA,OAAO,CAACyC,EAAR,CAAW,mBAAX,EAAiCvB,GAAD,IAASwC,YAAY,CAACxC,GAAD,EAAM,mBAAN,CAArD;AACAlB,IAAAA,OAAO,CAACyC,EAAR,CAAW,QAAX,EAAqB,MAAMiB,YAAY,CAAC,IAAD,EAAO,QAAP,CAAvC;AACA1D,IAAAA,OAAO,CAACyC,EAAR,CAAW,SAAX,EAAsB,MAAMiB,YAAY,CAAC,IAAD,EAAO,SAAP,CAAxC;AACA1D,IAAAA,OAAO,CAACyC,EAAR,CAAW,SAAX,EAAsB,MAAMiB,YAAY,CAAC,IAAD,EAAO,SAAP,CAAxC;AACD;;AAED,SAAO5D,MAAP;AACD","sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport pino from 'pino';\n\nimport { warningUtils } from '@verdaccio/core';\nimport prettifier, { fillInMsgTemplate } from '@verdaccio/logger-prettify';\n\nconst debug = buildDebug('verdaccio:logger');\n\nexport let logger;\n\nfunction isProd() {\n return process.env.NODE_ENV === 'production';\n}\n\nconst DEFAULT_LOG_FORMAT = isProd() ? 'json' : 'pretty';\n\nexport type LogPlugin = {\n dest: string;\n options?: any[];\n};\n\nexport type LogType = 'file' | 'stdout';\nexport type LogFormat = 'json' | 'pretty-timestamped' | 'pretty';\n\nexport function createLogger(\n options = { level: 'http' },\n destination = pino.destination(1),\n prettyPrintOptions = {\n // we hide warning since the prettifier should not be used in production\n // https://getpino.io/#/docs/pretty?id=prettifier-api\n suppressFlushSyncWarning: true,\n },\n format: LogFormat = DEFAULT_LOG_FORMAT\n) {\n if (_.isNil(format)) {\n format = DEFAULT_LOG_FORMAT;\n }\n\n let pinoConfig = {\n customLevels: {\n http: 25,\n },\n ...options,\n level: options.level,\n serializers: {\n err: pino.stdSerializers.err,\n req: pino.stdSerializers.req,\n res: pino.stdSerializers.res,\n },\n };\n\n debug('has prettifier? %o', !isProd());\n // pretty logs are not allowed in production for performance reasons\n if ((format === DEFAULT_LOG_FORMAT || format !== 'json') && isProd() === false) {\n pinoConfig = Object.assign({}, pinoConfig, {\n prettifier,\n // more info\n // https://github.com/pinojs/pino-pretty/issues/37\n prettyPrint: {\n levelFirst: true,\n prettyStamp: format === 'pretty-timestamped',\n ...prettyPrintOptions,\n },\n });\n } else {\n pinoConfig = Object.assign({}, pinoConfig, {\n // more info\n // https://github.com/pinojs/pino/blob/v7.1.0/docs/api.md#hooks-object\n hooks: {\n logMethod(inputArgs, method) {\n const [templateObject, message, ...otherArgs] = inputArgs;\n const templateVars =\n !!templateObject && typeof templateObject === 'object'\n ? Object.getOwnPropertyNames(templateObject)\n : [];\n if (!message || !templateVars.length) return method.apply(this, inputArgs);\n const hydratedMessage = fillInMsgTemplate(message, templateObject, false);\n return method.apply(this, [templateObject, hydratedMessage, ...otherArgs]);\n },\n },\n });\n }\n const logger = pino(pinoConfig, destination);\n\n if (process.env.DEBUG) {\n logger.on('level-change', (lvl, val, prevLvl, prevVal) => {\n debug('%s (%d) was changed to %s (%d)', lvl, val, prevLvl, prevVal);\n });\n }\n\n return logger;\n}\n\nexport function getLogger() {\n if (_.isNil(logger)) {\n // FIXME: not sure about display here a warning\n warningUtils.emit(warningUtils.Codes.VERWAR002);\n return;\n }\n\n return logger;\n}\n\nconst DEFAULT_LOGGER_CONF: LoggerConfigItem = {\n type: 'stdout',\n format: 'pretty',\n level: 'http',\n};\n\nexport type LoggerConfigItem = {\n type?: LogType;\n plugin?: LogPlugin;\n format?: LogFormat;\n path?: string;\n level?: string;\n};\n\nexport type LoggerConfig = LoggerConfigItem;\n\nexport function setup(options: LoggerConfigItem = DEFAULT_LOGGER_CONF) {\n debug('setup logger');\n let loggerConfig = options;\n if (!loggerConfig?.level) {\n loggerConfig = Object.assign(\n {},\n {\n level: 'http',\n },\n loggerConfig\n );\n }\n const pinoConfig = { level: loggerConfig.level };\n if (loggerConfig.type === 'file') {\n debug('logging file enabled');\n const destination = pino.destination(loggerConfig.path);\n process.on('SIGUSR2', () => destination.reopen());\n // @ts-ignore\n logger = createLogger(pinoConfig, destination, loggerConfig.format);\n // @ts-ignore\n } else if (loggerConfig.type === 'rotating-file') {\n warningUtils.emit(warningUtils.Codes.VERWAR003);\n debug('logging stdout enabled');\n // @ts-ignore\n logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);\n } else {\n debug('logging stdout enabled');\n // @ts-ignore\n logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);\n }\n\n if (isProd()) {\n // why only on prod? https://github.com/pinojs/pino/issues/920#issuecomment-710807667\n const finalHandler = pino.final(logger, (err, finalLogger, event) => {\n finalLogger.info(`${event} caught`);\n if (err) {\n finalLogger.error(err, 'error caused exit');\n }\n process.exit(err ? 1 : 0);\n });\n\n process.on('uncaughtException', (err) => finalHandler(err, 'uncaughtException'));\n process.on('unhandledRejection', (err) => finalHandler(err as Error, 'unhandledRejection'));\n process.on('beforeExit', () => finalHandler(null, 'beforeExit'));\n process.on('exit', () => finalHandler(null, 'exit'));\n process.on('uncaughtException', (err) => finalHandler(err, 'uncaughtException'));\n process.on('SIGINT', () => finalHandler(null, 'SIGINT'));\n process.on('SIGQUIT', () => finalHandler(null, 'SIGQUIT'));\n process.on('SIGTERM', () => finalHandler(null, 'SIGTERM'));\n }\n\n return logger;\n}\n"],"file":"logger.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/logger",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.11",
|
|
4
4
|
"description": "logger",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"npm": ">=6"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
34
|
-
"@verdaccio/logger-prettify": "6.0.0-6-next.
|
|
33
|
+
"@verdaccio/core": "6.0.0-6-next.5",
|
|
34
|
+
"@verdaccio/logger-prettify": "6.0.0-6-next.6",
|
|
35
|
+
"pino-pretty": "7.6.0",
|
|
35
36
|
"debug": "4.3.3",
|
|
36
37
|
"lodash": "4.17.21",
|
|
37
|
-
"pino": "6.
|
|
38
|
+
"pino": "7.6.4"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types
|
|
41
|
-
"@verdaccio/types": "11.0.0-6-next.10"
|
|
41
|
+
"@verdaccio/types": "11.0.0-6-next.11"
|
|
42
42
|
},
|
|
43
43
|
"funding": {
|
|
44
44
|
"type": "opencollective",
|
package/src/logger.ts
CHANGED
|
@@ -26,12 +26,12 @@ export type LogFormat = 'json' | 'pretty-timestamped' | 'pretty';
|
|
|
26
26
|
export function createLogger(
|
|
27
27
|
options = { level: 'http' },
|
|
28
28
|
destination = pino.destination(1),
|
|
29
|
-
format: LogFormat = DEFAULT_LOG_FORMAT,
|
|
30
29
|
prettyPrintOptions = {
|
|
31
30
|
// we hide warning since the prettifier should not be used in production
|
|
32
31
|
// https://getpino.io/#/docs/pretty?id=prettifier-api
|
|
33
32
|
suppressFlushSyncWarning: true,
|
|
34
|
-
}
|
|
33
|
+
},
|
|
34
|
+
format: LogFormat = DEFAULT_LOG_FORMAT
|
|
35
35
|
) {
|
|
36
36
|
if (_.isNil(format)) {
|
|
37
37
|
format = DEFAULT_LOG_FORMAT;
|
|
@@ -116,19 +116,11 @@ export type LoggerConfigItem = {
|
|
|
116
116
|
level?: string;
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
export type LoggerConfig = LoggerConfigItem
|
|
119
|
+
export type LoggerConfig = LoggerConfigItem;
|
|
120
120
|
|
|
121
|
-
export function setup(options:
|
|
121
|
+
export function setup(options: LoggerConfigItem = DEFAULT_LOGGER_CONF) {
|
|
122
122
|
debug('setup logger');
|
|
123
|
-
|
|
124
|
-
if (isLegacyConf) {
|
|
125
|
-
warningUtils.emit(warningUtils.Codes.VERDEP002);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// verdaccio 5 does not allow multiple logger configuration
|
|
129
|
-
// backward compatible, pick only the first option
|
|
130
|
-
// next major will thrown an error
|
|
131
|
-
let loggerConfig = isLegacyConf ? options[0] : options;
|
|
123
|
+
let loggerConfig = options;
|
|
132
124
|
if (!loggerConfig?.level) {
|
|
133
125
|
loggerConfig = Object.assign(
|
|
134
126
|
{},
|
|
@@ -141,13 +133,19 @@ export function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_
|
|
|
141
133
|
const pinoConfig = { level: loggerConfig.level };
|
|
142
134
|
if (loggerConfig.type === 'file') {
|
|
143
135
|
debug('logging file enabled');
|
|
144
|
-
|
|
136
|
+
const destination = pino.destination(loggerConfig.path);
|
|
137
|
+
process.on('SIGUSR2', () => destination.reopen());
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
logger = createLogger(pinoConfig, destination, loggerConfig.format);
|
|
140
|
+
// @ts-ignore
|
|
145
141
|
} else if (loggerConfig.type === 'rotating-file') {
|
|
146
142
|
warningUtils.emit(warningUtils.Codes.VERWAR003);
|
|
147
143
|
debug('logging stdout enabled');
|
|
144
|
+
// @ts-ignore
|
|
148
145
|
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
|
|
149
146
|
} else {
|
|
150
147
|
debug('logging stdout enabled');
|
|
148
|
+
// @ts-ignore
|
|
151
149
|
logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
|
|
152
150
|
}
|
|
153
151
|
|
package/test/logger.spec.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { warningUtils } from '@verdaccio/core';
|
|
2
|
-
|
|
3
1
|
import { logger, setup } from '../src';
|
|
4
2
|
|
|
5
3
|
const mockWarningUtils = jest.fn();
|
|
@@ -34,7 +32,7 @@ describe('logger', () => {
|
|
|
34
32
|
// expect(spyOn).toHaveBeenCalledTimes(2);
|
|
35
33
|
});
|
|
36
34
|
|
|
37
|
-
test('throw deprecation warning if multiple loggers configured', () => {
|
|
35
|
+
test.skip('throw deprecation warning if multiple loggers configured', () => {
|
|
38
36
|
setup([
|
|
39
37
|
{
|
|
40
38
|
level: 'info',
|
|
@@ -43,7 +41,7 @@ describe('logger', () => {
|
|
|
43
41
|
level: 'http',
|
|
44
42
|
},
|
|
45
43
|
]);
|
|
46
|
-
expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
|
|
44
|
+
// expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
|
|
47
45
|
});
|
|
48
46
|
|
|
49
47
|
test('regression: do not throw deprecation warning if no logger config is provided', () => {
|