@autofleet/logger 4.0.0-beta-2 → 4.0.0-beta-3

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/dist/index.js CHANGED
@@ -6,44 +6,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LogLevel = void 0;
7
7
  const pino_1 = __importDefault(require("pino"));
8
8
  const pino_cloud_logging_1 = require("pino-cloud-logging");
9
+ // eslint-disable-next-line no-shadow
10
+ var LogLevel;
11
+ (function (LogLevel) {
12
+ LogLevel["trace"] = "trace";
13
+ LogLevel["debug"] = "debug";
14
+ LogLevel["info"] = "info";
15
+ LogLevel["warn"] = "warn";
16
+ LogLevel["error"] = "error";
17
+ LogLevel["fatal"] = "fatal";
18
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
9
19
  const getLevel = (logLevel) => {
10
20
  if (logLevel)
11
21
  return logLevel;
12
22
  if (process.env.LOG_LEVEL)
13
23
  return process.env.LOG_LEVEL;
14
24
  if (process.env.NODE_ENV && ['production', 'staging', 'test'].includes(process.env.NODE_ENV))
15
- return 'info';
25
+ return LogLevel.info;
16
26
  if (process.env.NODE_ENV === 'development')
17
- return 'debug';
18
- return 'debug';
27
+ return LogLevel.debug;
28
+ return LogLevel.debug;
19
29
  };
20
30
  const createLoggerInstance = (level, options) => {
21
31
  let loggerInstance;
22
32
  if (process.env.NODE_ENV === 'production') {
23
- loggerInstance = (0, pino_1.default)((0, pino_cloud_logging_1.gcpLogOptions)(Object.assign({ level: process.env.PINO_LOG_LEVEL || 'info' }, options)));
33
+ loggerInstance = (0, pino_1.default)((0, pino_cloud_logging_1.gcpLogOptions)({
34
+ level: process.env.PINO_LOG_LEVEL || 'info',
35
+ ...options,
36
+ }));
24
37
  }
25
38
  else {
26
- loggerInstance = (0, pino_1.default)(Object.assign({ level: process.env.PINO_LOG_LEVEL || 'info', transport: {
39
+ loggerInstance = (0, pino_1.default)({
40
+ level: process.env.PINO_LOG_LEVEL || 'info',
41
+ transport: {
27
42
  target: 'pino-pretty',
28
43
  options: {
29
44
  colorize: true,
30
45
  },
31
- } }, options));
46
+ },
47
+ ...options,
48
+ });
32
49
  }
33
50
  loggerInstance.level = level;
34
51
  return loggerInstance;
35
52
  };
36
- // eslint-disable-next-line no-shadow
37
- var LogLevel;
38
- (function (LogLevel) {
39
- LogLevel["trace"] = "trace";
40
- LogLevel["debug"] = "debug";
41
- LogLevel["info"] = "info";
42
- LogLevel["warn"] = "warn";
43
- LogLevel["error"] = "error";
44
- LogLevel["fatal"] = "fatal";
45
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
46
53
  class LoggerInstanceManager {
54
+ contextMiddlewares;
55
+ logger;
47
56
  constructor(logLevel) {
48
57
  this.contextMiddlewares = [];
49
58
  this.logger = createLoggerInstance(getLevel(logLevel), {
package/index.ts CHANGED
@@ -1,15 +1,27 @@
1
1
  import Pino from 'pino';
2
2
  import { gcpLogOptions } from 'pino-cloud-logging';
3
3
 
4
- const getLevel = (logLevel: string | undefined) => {
4
+ // eslint-disable-next-line no-shadow
5
+ export enum LogLevel {
6
+ trace = 'trace',
7
+ debug = 'debug',
8
+ info = 'info',
9
+ warn = 'warn',
10
+ error = 'error',
11
+ fatal = 'fatal',
12
+ }
13
+
14
+ type LogLevels = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
15
+
16
+ const getLevel = (logLevel?: LogLevel): LogLevel => {
5
17
  if (logLevel) return logLevel;
6
- if (process.env.LOG_LEVEL) return process.env.LOG_LEVEL;
7
- if (process.env.NODE_ENV && ['production', 'staging', 'test'].includes(process.env.NODE_ENV)) return 'info';
8
- if (process.env.NODE_ENV === 'development') return 'debug';
9
- return 'debug';
18
+ if (process.env.LOG_LEVEL) return process.env.LOG_LEVEL as LogLevel;
19
+ if (process.env.NODE_ENV && ['production', 'staging', 'test'].includes(process.env.NODE_ENV)) return LogLevel.info;
20
+ if (process.env.NODE_ENV === 'development') return LogLevel.debug;
21
+ return LogLevel.debug;
10
22
  };
11
23
 
12
- const createLoggerInstance = (level: string, options: object) => {
24
+ const createLoggerInstance = (level: LogLevel, options: object) => {
13
25
  let loggerInstance;
14
26
  if (process.env.NODE_ENV === 'production') {
15
27
  loggerInstance = Pino(gcpLogOptions({
@@ -32,16 +44,6 @@ const createLoggerInstance = (level: string, options: object) => {
32
44
  return loggerInstance;
33
45
  };
34
46
 
35
- // eslint-disable-next-line no-shadow
36
- export enum LogLevel {
37
- trace = 'trace',
38
- debug = 'debug',
39
- info = 'info',
40
- warn = 'warn',
41
- error = 'error',
42
- fatal = 'fatal',
43
- }
44
-
45
47
  type MiddlewareFunction = () => Record<string, unknown>;
46
48
 
47
49
  class LoggerInstanceManager {
@@ -49,7 +51,7 @@ class LoggerInstanceManager {
49
51
 
50
52
  logger: Pino.Logger;
51
53
 
52
- constructor(logLevel?: string) {
54
+ constructor(logLevel?: LogLevel) {
53
55
  this.contextMiddlewares = [];
54
56
  this.logger = createLoggerInstance(getLevel(logLevel), {
55
57
  mixin: () => this.addMetadata(),
@@ -110,4 +112,5 @@ class LoggerInstanceManager {
110
112
  return this.logger.level;
111
113
  }
112
114
  }
113
- export default (loglevel?: string) => new LoggerInstanceManager(loglevel);
115
+
116
+ export default (loglevel?: LogLevels) => new LoggerInstanceManager(loglevel as LogLevel);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/logger",
3
- "version": "4.0.0-beta-2",
3
+ "version": "4.0.0-beta-3",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "coverage": "jest --coverage --forceExit --runInBand",
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
3
+ "target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4
4
  "module": "commonjs", /* Specify what module code is generated. */ /* Allow 'import x from y' when a module doesn't have a default export. */
5
5
  "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
6
6
  // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */