@verdaccio/logger 6.0.0-6-next.4 → 6.0.0-6-next.8

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 CHANGED
@@ -1,5 +1,49 @@
1
1
  # @verdaccio/logger
2
2
 
3
+ ## 6.0.0-6-next.8
4
+
5
+ ### Patch Changes
6
+
7
+ - e75c0a3b: hydrate template placeholders in log messages when format is set to 'json'
8
+ - Updated dependencies [24b9be02]
9
+ - Updated dependencies [e75c0a3b]
10
+ - @verdaccio/core@6.0.0-6-next.4
11
+ - @verdaccio/logger-prettify@6.0.0-6-next.5
12
+
13
+ ## 6.0.0-6-next.7
14
+
15
+ ### Minor Changes
16
+
17
+ - 6c1eb021: feat: use warning codes for deprecation warnings
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [6c1eb021]
22
+ - @verdaccio/core@6.0.0-6-next.3
23
+
24
+ ## 6.0.0-6-next.6
25
+
26
+ ### Major Changes
27
+
28
+ - 794af76c: Remove Node 12 support
29
+
30
+ - We need move to the new `undici` and does not support Node.js 12
31
+
32
+ ### Minor Changes
33
+
34
+ - 154b2ecd: refactor: remove @verdaccio/commons-api in favor @verdaccio/core and remove duplications
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies [b702ea36]
39
+ - @verdaccio/logger-prettify@6.0.0-6-next.4
40
+
41
+ ## 6.0.0-6-next.5
42
+
43
+ ### Patch Changes
44
+
45
+ - 2c594910: do not show deprecation warning on default logger config
46
+
3
47
  ## 6.0.0-6-next.4
4
48
 
5
49
  ### Major Changes
package/build/index.js CHANGED
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "setup", {
7
- enumerable: true,
8
- get: function () {
9
- return _logger.setup;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "createLogger", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -21,6 +15,12 @@ Object.defineProperty(exports, "logger", {
21
15
  return _logger.logger;
22
16
  }
23
17
  });
18
+ Object.defineProperty(exports, "setup", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _logger.setup;
22
+ }
23
+ });
24
24
 
25
25
  var _logger = require("./logger");
26
26
  //# sourceMappingURL=index.js.map
package/build/logger.js CHANGED
@@ -5,22 +5,24 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createLogger = createLogger;
7
7
  exports.getLogger = getLogger;
8
- exports.setup = setup;
9
8
  exports.logger = void 0;
9
+ exports.setup = setup;
10
10
 
11
- var _pino = _interopRequireDefault(require("pino"));
11
+ var _debug = _interopRequireDefault(require("debug"));
12
12
 
13
13
  var _lodash = _interopRequireDefault(require("lodash"));
14
14
 
15
- var _debug = _interopRequireDefault(require("debug"));
15
+ var _pino = _interopRequireDefault(require("pino"));
16
16
 
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ var _core = require("@verdaccio/core");
18
+
19
+ var _loggerPrettify = _interopRequireWildcard(require("@verdaccio/logger-prettify"));
18
20
 
19
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
22
 
21
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
24
 
23
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
26
 
25
27
  const debug = (0, _debug.default)('verdaccio:logger');
26
28
  let logger;
@@ -43,30 +45,45 @@ function createLogger(options = {
43
45
  format = DEFAULT_LOG_FORMAT;
44
46
  }
45
47
 
46
- let pinoConfig = _objectSpread(_objectSpread({
48
+ let pinoConfig = {
47
49
  customLevels: {
48
50
  http: 25
49
- }
50
- }, options), {}, {
51
+ },
52
+ ...options,
51
53
  level: options.level,
52
54
  serializers: {
53
55
  err: _pino.default.stdSerializers.err,
54
56
  req: _pino.default.stdSerializers.req,
55
57
  res: _pino.default.stdSerializers.res
56
58
  }
57
- });
58
-
59
+ };
59
60
  debug('has prettifier? %o', !isProd()); // pretty logs are not allowed in production for performance reasons
60
61
 
61
62
  if ((format === DEFAULT_LOG_FORMAT || format !== 'json') && isProd() === false) {
62
63
  pinoConfig = Object.assign({}, pinoConfig, {
64
+ prettifier: _loggerPrettify.default,
63
65
  // more info
64
66
  // https://github.com/pinojs/pino-pretty/issues/37
65
- prettyPrint: _objectSpread({
67
+ prettyPrint: {
66
68
  levelFirst: true,
67
- prettyStamp: format === 'pretty-timestamped'
68
- }, prettyPrintOptions),
69
- prettifier: require('@verdaccio/logger-prettify')
69
+ prettyStamp: format === 'pretty-timestamped',
70
+ ...prettyPrintOptions
71
+ }
72
+ });
73
+ } else {
74
+ pinoConfig = Object.assign({}, pinoConfig, {
75
+ // more info
76
+ // https://github.com/pinojs/pino/blob/v7.1.0/docs/api.md#hooks-object
77
+ hooks: {
78
+ logMethod(inputArgs, method) {
79
+ const [templateObject, message, ...otherArgs] = inputArgs;
80
+ const templateVars = !!templateObject && typeof templateObject === 'object' ? Object.getOwnPropertyNames(templateObject) : [];
81
+ if (!message || !templateVars.length) return method.apply(this, inputArgs);
82
+ const hydratedMessage = (0, _loggerPrettify.fillInMsgTemplate)(message, templateObject, false);
83
+ return method.apply(this, [templateObject, hydratedMessage, ...otherArgs]);
84
+ }
85
+
86
+ }
70
87
  });
71
88
  }
72
89
 
@@ -84,7 +101,8 @@ function createLogger(options = {
84
101
  function getLogger() {
85
102
  if (_lodash.default.isNil(logger)) {
86
103
  // FIXME: not sure about display here a warning
87
- process.emitWarning('logger is not defined');
104
+ _core.warningUtils.emit(_core.warningUtils.Codes.VERWAR002);
105
+
88
106
  return;
89
107
  }
90
108
 
@@ -97,15 +115,14 @@ const DEFAULT_LOGGER_CONF = {
97
115
  level: 'http'
98
116
  };
99
117
 
100
- function setup(options = [DEFAULT_LOGGER_CONF]) {
118
+ function setup(options = DEFAULT_LOGGER_CONF) {
101
119
  var _loggerConfig;
102
120
 
103
121
  debug('setup logger');
104
122
  const isLegacyConf = Array.isArray(options);
105
123
 
106
124
  if (isLegacyConf) {
107
- const deprecateMessage = 'deprecate: multiple logger configuration is deprecated, please check the migration guide.';
108
- process.emitWarning(deprecateMessage);
125
+ _core.warningUtils.emit(_core.warningUtils.Codes.VERDEP002);
109
126
  } // verdaccio 5 does not allow multiple logger configuration
110
127
  // backward compatible, pick only the first option
111
128
  // next major will thrown an error
@@ -127,7 +144,8 @@ function setup(options = [DEFAULT_LOGGER_CONF]) {
127
144
  debug('logging file enabled');
128
145
  exports.logger = logger = createLogger(pinoConfig, _pino.default.destination(loggerConfig.path), loggerConfig.format);
129
146
  } else if (loggerConfig.type === 'rotating-file') {
130
- process.emitWarning('rotating-file type is not longer supported, consider use [logrotate] instead');
147
+ _core.warningUtils.emit(_core.warningUtils.Codes.VERWAR003);
148
+
131
149
  debug('logging stdout enabled');
132
150
  exports.logger = logger = createLogger(pinoConfig, _pino.default.destination(1), loggerConfig.format);
133
151
  } else {
@@ -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","prettyPrint","levelFirst","prettyStamp","prettifier","require","DEBUG","on","lvl","val","prevLvl","prevVal","getLogger","emitWarning","DEFAULT_LOGGER_CONF","type","setup","isLegacyConf","Array","isArray","deprecateMessage","loggerConfig","path","finalHandler","final","finalLogger","event","info","error","exit"],"mappings":";;;;;;;;;;AAAA;;AACA;;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,MAAiB,GAAGN,kBAHf,EAILO,kBAAkB,GAAG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MgB,YAAY,CAAC,IAAD,EAAO,YAAP,CAA3C;AACA9C,IAAAA,OAAO,CAAC8B,EAAR,CAAW,MAAX,EAAmB,MAAMgB,YAAY,CAAC,IAAD,EAAO,MAAP,CAArC;AACA9C,IAAAA,OAAO,CAAC8B,EAAR,CAAW,mBAAX,EAAiCZ,GAAD,IAAS4B,YAAY,CAAC5B,GAAD,EAAM,mBAAN,CAArD;AACAlB,IAAAA,OAAO,CAAC8B,EAAR,CAAW,QAAX,EAAqB,MAAMgB,YAAY,CAAC,IAAD,EAAO,QAAP,CAAvC;AACA9C,IAAAA,OAAO,CAAC8B,EAAR,CAAW,SAAX,EAAsB,MAAMgB,YAAY,CAAC,IAAD,EAAO,SAAP,CAAxC;AACA9C,IAAAA,OAAO,CAAC8B,EAAR,CAAW,SAAX,EAAsB,MAAMgB,YAAY,CAAC,IAAD,EAAO,SAAP,CAAxC;AACD;;AAED,SAAOhD,MAAP;AACD","sourcesContent":["import pino from 'pino';\nimport _ from 'lodash';\nimport buildDebug from 'debug';\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 // 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 prettifier: require('@verdaccio/logger-prettify'),\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 process.emitWarning('logger is not defined');\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 const deprecateMessage =\n 'deprecate: multiple logger configuration is deprecated, please check the migration guide.';\n process.emitWarning(deprecateMessage);\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 process.emitWarning(\n 'rotating-file type is not longer supported, consider use [logrotate] instead'\n );\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","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":";;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;;;;;;;AAEA,MAAMA,KAAK,GAAG,oBAAW,kBAAX,CAAd;AAEO,I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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/logger",
3
- "version": "6.0.0-6-next.4",
3
+ "version": "6.0.0-6-next.8",
4
4
  "description": "logger",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -26,18 +26,19 @@
26
26
  "verdaccio"
27
27
  ],
28
28
  "engines": {
29
- "node": ">=10",
29
+ "node": ">=14",
30
30
  "npm": ">=6"
31
31
  },
32
32
  "dependencies": {
33
- "@verdaccio/logger-prettify": "6.0.0-alpha.3",
34
- "debug": "4.3.2",
33
+ "@verdaccio/core": "6.0.0-6-next.4",
34
+ "@verdaccio/logger-prettify": "6.0.0-6-next.5",
35
+ "debug": "4.3.3",
35
36
  "lodash": "4.17.21",
36
- "pino": "6.13.1"
37
+ "pino": "6.13.3"
37
38
  },
38
39
  "devDependencies": {
39
- "@types/pino": "6.3.11",
40
- "@verdaccio/types": "11.0.0-6-next.7"
40
+ "@types/pino": "6.3.12",
41
+ "@verdaccio/types": "11.0.0-6-next.10"
41
42
  },
42
43
  "funding": {
43
44
  "type": "opencollective",
package/src/logger.ts CHANGED
@@ -1,6 +1,9 @@
1
- import pino from 'pino';
2
- import _ from 'lodash';
3
1
  import buildDebug from 'debug';
2
+ import _ from 'lodash';
3
+ import pino from 'pino';
4
+
5
+ import { warningUtils } from '@verdaccio/core';
6
+ import prettifier, { fillInMsgTemplate } from '@verdaccio/logger-prettify';
4
7
 
5
8
  const debug = buildDebug('verdaccio:logger');
6
9
 
@@ -51,6 +54,7 @@ export function createLogger(
51
54
  // pretty logs are not allowed in production for performance reasons
52
55
  if ((format === DEFAULT_LOG_FORMAT || format !== 'json') && isProd() === false) {
53
56
  pinoConfig = Object.assign({}, pinoConfig, {
57
+ prettifier,
54
58
  // more info
55
59
  // https://github.com/pinojs/pino-pretty/issues/37
56
60
  prettyPrint: {
@@ -58,7 +62,23 @@ export function createLogger(
58
62
  prettyStamp: format === 'pretty-timestamped',
59
63
  ...prettyPrintOptions,
60
64
  },
61
- prettifier: require('@verdaccio/logger-prettify'),
65
+ });
66
+ } else {
67
+ pinoConfig = Object.assign({}, pinoConfig, {
68
+ // more info
69
+ // https://github.com/pinojs/pino/blob/v7.1.0/docs/api.md#hooks-object
70
+ hooks: {
71
+ logMethod(inputArgs, method) {
72
+ const [templateObject, message, ...otherArgs] = inputArgs;
73
+ const templateVars =
74
+ !!templateObject && typeof templateObject === 'object'
75
+ ? Object.getOwnPropertyNames(templateObject)
76
+ : [];
77
+ if (!message || !templateVars.length) return method.apply(this, inputArgs);
78
+ const hydratedMessage = fillInMsgTemplate(message, templateObject, false);
79
+ return method.apply(this, [templateObject, hydratedMessage, ...otherArgs]);
80
+ },
81
+ },
62
82
  });
63
83
  }
64
84
  const logger = pino(pinoConfig, destination);
@@ -75,7 +95,7 @@ export function createLogger(
75
95
  export function getLogger() {
76
96
  if (_.isNil(logger)) {
77
97
  // FIXME: not sure about display here a warning
78
- process.emitWarning('logger is not defined');
98
+ warningUtils.emit(warningUtils.Codes.VERWAR002);
79
99
  return;
80
100
  }
81
101
 
@@ -98,13 +118,11 @@ export type LoggerConfigItem = {
98
118
 
99
119
  export type LoggerConfig = LoggerConfigItem[];
100
120
 
101
- export function setup(options: LoggerConfig | LoggerConfigItem = [DEFAULT_LOGGER_CONF]) {
121
+ export function setup(options: LoggerConfig | LoggerConfigItem = DEFAULT_LOGGER_CONF) {
102
122
  debug('setup logger');
103
123
  const isLegacyConf = Array.isArray(options);
104
124
  if (isLegacyConf) {
105
- const deprecateMessage =
106
- 'deprecate: multiple logger configuration is deprecated, please check the migration guide.';
107
- process.emitWarning(deprecateMessage);
125
+ warningUtils.emit(warningUtils.Codes.VERDEP002);
108
126
  }
109
127
 
110
128
  // verdaccio 5 does not allow multiple logger configuration
@@ -125,9 +143,7 @@ export function setup(options: LoggerConfig | LoggerConfigItem = [DEFAULT_LOGGER
125
143
  debug('logging file enabled');
126
144
  logger = createLogger(pinoConfig, pino.destination(loggerConfig.path), loggerConfig.format);
127
145
  } else if (loggerConfig.type === 'rotating-file') {
128
- process.emitWarning(
129
- 'rotating-file type is not longer supported, consider use [logrotate] instead'
130
- );
146
+ warningUtils.emit(warningUtils.Codes.VERWAR003);
131
147
  debug('logging stdout enabled');
132
148
  logger = createLogger(pinoConfig, pino.destination(1), loggerConfig.format);
133
149
  } else {
@@ -1,7 +1,27 @@
1
+ import { warningUtils } from '@verdaccio/core';
2
+
1
3
  import { logger, setup } from '../src';
2
4
 
5
+ const mockWarningUtils = jest.fn();
6
+
7
+ jest.mock('@verdaccio/core', () => {
8
+ const original = jest.requireActual('@verdaccio/core');
9
+ return {
10
+ warningUtils: {
11
+ ...original.warningUtils,
12
+ emit: (...args) => {
13
+ mockWarningUtils(...args);
14
+ },
15
+ },
16
+ };
17
+ });
18
+
3
19
  describe('logger', () => {
4
- test('dsadasd', () => {
20
+ beforeEach(() => {
21
+ jest.clearAllMocks();
22
+ });
23
+
24
+ test.skip('should write message logger', () => {
5
25
  jest.spyOn(process.stdout, 'write');
6
26
  setup([
7
27
  {
@@ -13,4 +33,21 @@ describe('logger', () => {
13
33
  // FIXME: check expect
14
34
  // expect(spyOn).toHaveBeenCalledTimes(2);
15
35
  });
36
+
37
+ test('throw deprecation warning if multiple loggers configured', () => {
38
+ setup([
39
+ {
40
+ level: 'info',
41
+ },
42
+ {
43
+ level: 'http',
44
+ },
45
+ ]);
46
+ expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
47
+ });
48
+
49
+ test('regression: do not throw deprecation warning if no logger config is provided', () => {
50
+ setup();
51
+ expect(mockWarningUtils).not.toHaveBeenCalled();
52
+ });
16
53
  });