@autofleet/logger 1.2.5 → 1.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/logger",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "coverage": "jest --coverage --forceExit --runInBand",
@@ -1,16 +0,0 @@
1
- interface EntityObject {
2
- entityId: string;
3
- entityType: string;
4
- businessModelId?: string;
5
- fleetId?: string;
6
- demandSourceId?: string;
7
- }
8
- export default class DebugConsoleLog {
9
- entites: EntityObject;
10
- constructor(entites: EntityObject);
11
- private generateLevelLog;
12
- info(msg: string, payload?: any, additonalEntityies?: any): Promise<void>;
13
- warn(msg: string, payload?: any, additonalEntityies?: any): Promise<void>;
14
- error(msg: string, payload?: any, additonalEntityies?: any): Promise<void>;
15
- }
16
- export {};
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const Events = require('@autofleet/events');
16
- const logger_1 = __importDefault(require("./logger"));
17
- const events = new Events({ logger: logger_1.default });
18
- class DebugConsoleLog {
19
- constructor(entites) {
20
- this.entites = entites;
21
- }
22
- generateLevelLog(level) {
23
- return (msg, payload, additonalEntityies) => __awaiter(this, void 0, void 0, function* () {
24
- logger_1.default[level](msg, payload);
25
- events.send('log_events', 1, Object.assign(Object.assign({ action: 'logEvent', level }, this.entites), { payload: JSON.stringify(payload) }));
26
- });
27
- }
28
- info(msg, payload, additonalEntityies) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- return this.generateLevelLog('info')(msg, payload, additonalEntityies);
31
- });
32
- }
33
- warn(msg, payload, additonalEntityies) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- return this.generateLevelLog('warn')(msg, payload, additonalEntityies);
36
- });
37
- }
38
- error(msg, payload, additonalEntityies) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- return this.generateLevelLog('error')(msg, payload, additonalEntityies);
41
- });
42
- }
43
- }
44
- exports.default = DebugConsoleLog;
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import logger from './logger';
2
- import DebugConsoleLog from './debug-console-log';
3
- export { DebugConsoleLog };
4
- export default logger;
package/dist/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DebugConsoleLog = void 0;
7
- const logger_1 = __importDefault(require("./logger"));
8
- const debug_console_log_1 = __importDefault(require("./debug-console-log"));
9
- exports.DebugConsoleLog = debug_console_log_1.default;
10
- exports.default = logger_1.default;
package/dist/logger.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import winston from 'winston';
2
- declare const logger: winston.Logger;
3
- export declare const httpMorganInfo: (options: any) => void;
4
- export default logger;
package/dist/logger.js DELETED
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.httpMorganInfo = void 0;
7
- const winston_1 = __importDefault(require("winston"));
8
- const { createLogger } = winston_1.default;
9
- require('dotenv').config();
10
- const { env } = process;
11
- const isProd = env.NODE_ENV === 'production';
12
- const infoEnvNmaes = [
13
- 'production',
14
- 'staging',
15
- 'test',
16
- ];
17
- const serializeError = (error) => {
18
- const fields = ['code', 'status', 'statusCode', 'message', 'messageData', 'name', 'stack', 'stackTrace'];
19
- return fields.reduce((v, field) => (Object.assign(Object.assign({}, v), { [field]: error[field] })), {});
20
- };
21
- const getLevel = () => {
22
- if (env.LOG_LEVEL)
23
- return env.LOG_LEVEL;
24
- if (infoEnvNmaes.includes(env.NODE_ENV || ''))
25
- return 'info';
26
- if (env.NODE_ENV === 'development')
27
- return 'debug';
28
- return 'debug';
29
- };
30
- const enumerateErrorFormat = winston_1.default.format((info) => {
31
- // fix for this crap: https://github.com/googleapis/nodejs-logging-winston/issues/285
32
- // eslint-disable-next-line no-param-reassign
33
- info.severity = info.level.toUpperCase();
34
- if (info instanceof Error) {
35
- return Object.assign({
36
- message: info.message,
37
- stack: info.stack,
38
- }, info);
39
- }
40
- // eslint-disable-next-line array-callback-return
41
- Object.keys(info).map((k) => {
42
- if (info[k] instanceof Error) {
43
- // eslint-disable-next-line no-param-reassign
44
- info[k] = serializeError(info[k]);
45
- }
46
- });
47
- return info;
48
- });
49
- const getFormat = () => {
50
- if (isProd) {
51
- return winston_1.default.format.combine(enumerateErrorFormat(), winston_1.default.format.json());
52
- }
53
- return winston_1.default.format.combine(enumerateErrorFormat(), winston_1.default.format.splat(), winston_1.default.format.colorize(), winston_1.default.format.simple());
54
- };
55
- const logger = createLogger({
56
- level: getLevel(),
57
- format: getFormat(),
58
- transports: [
59
- new winston_1.default.transports.Console(),
60
- ],
61
- exitOnError: false,
62
- });
63
- const httpMorganInfo = (options) => {
64
- logger.info(options.url, {
65
- httpRequest: {
66
- status: options.status,
67
- requestUrl: options.url,
68
- requestMethod: options.method,
69
- responseSize: options['content-length'],
70
- latency: {
71
- seconds: parseInt(options['response-time'], 10) / 1000,
72
- nanos: parseInt(options['response-time'], 10) * 1000000,
73
- },
74
- userAgent: options['user-agent'],
75
- },
76
- });
77
- };
78
- exports.httpMorganInfo = httpMorganInfo;
79
- exports.default = logger;
@@ -1,16 +0,0 @@
1
- interface EntityObject {
2
- entityId: string;
3
- entityType: string;
4
- businessModelId?: string;
5
- fleetId?: string;
6
- demandSourceId?: string;
7
- }
8
- export default class DebugConsoleLog {
9
- entites: EntityObject;
10
- constructor(entites: EntityObject);
11
- private generateLevelLog;
12
- info(msg: string, payload?: any, additonalEntityies?: any): Promise<void>;
13
- warn(msg: string, payload?: any, additonalEntityies?: any): Promise<void>;
14
- error(msg: string, payload?: any, additonalEntityies?: any): Promise<void>;
15
- }
16
- export {};
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const events_1 = __importDefault(require("@autofleet/events"));
16
- const logger_1 = __importDefault(require("./logger"));
17
- const events = new events_1.default();
18
- class DebugConsoleLog {
19
- constructor(entites) {
20
- this.entites = entites;
21
- }
22
- generateLevelLog(level) {
23
- return (msg, payload, additonalEntityies) => __awaiter(this, void 0, void 0, function* () {
24
- logger_1.default[level](msg, payload);
25
- events.send('log_events', 1, Object.assign(Object.assign({ action: 'logEvent', level }, this.entites), { payload: JSON.stringify(payload) }));
26
- });
27
- }
28
- info(msg, payload, additonalEntityies) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- return this.generateLevelLog('info')(msg, payload, additonalEntityies);
31
- });
32
- }
33
- warn(msg, payload, additonalEntityies) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- return this.generateLevelLog('warn')(msg, payload, additonalEntityies);
36
- });
37
- }
38
- error(msg, payload, additonalEntityies) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- return this.generateLevelLog('error')(msg, payload, additonalEntityies);
41
- });
42
- }
43
- }
44
- exports.default = DebugConsoleLog;
@@ -1,4 +0,0 @@
1
- import logger from './logger';
2
- import DebugConsoleLog from './debug-console-log';
3
- export { DebugConsoleLog };
4
- export default logger;
package/dist/src/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DebugConsoleLog = void 0;
7
- const logger_1 = __importDefault(require("./logger"));
8
- const debug_console_log_1 = __importDefault(require("./debug-console-log"));
9
- exports.DebugConsoleLog = debug_console_log_1.default;
10
- exports.default = logger_1.default;
@@ -1,4 +0,0 @@
1
- import winston from 'winston';
2
- declare const logger: winston.Logger;
3
- export declare const httpMorganInfo: (options: any) => void;
4
- export default logger;
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.httpMorganInfo = void 0;
7
- const winston_1 = __importDefault(require("winston"));
8
- const { createLogger } = winston_1.default;
9
- require('dotenv').config();
10
- const { env } = process;
11
- const isProd = env.NODE_ENV === 'production';
12
- const infoEnvNmaes = [
13
- 'production',
14
- 'staging',
15
- 'test',
16
- ];
17
- const serializeError = (error) => {
18
- const fields = ['code', 'status', 'statusCode', 'message', 'messageData', 'name', 'stack', 'stackTrace'];
19
- return fields.reduce((v, field) => (Object.assign(Object.assign({}, v), { [field]: error[field] })), {});
20
- };
21
- const getLevel = () => {
22
- if (env.LOG_LEVEL)
23
- return env.LOG_LEVEL;
24
- if (infoEnvNmaes.includes(env.NODE_ENV || ''))
25
- return 'info';
26
- if (env.NODE_ENV === 'development')
27
- return 'debug';
28
- return 'debug';
29
- };
30
- const enumerateErrorFormat = winston_1.default.format((info) => {
31
- // fix for this crap: https://github.com/googleapis/nodejs-logging-winston/issues/285
32
- // eslint-disable-next-line no-param-reassign
33
- info.severity = info.level.toUpperCase();
34
- if (info instanceof Error) {
35
- return Object.assign({
36
- message: info.message,
37
- stack: info.stack,
38
- }, info);
39
- }
40
- // eslint-disable-next-line array-callback-return
41
- Object.keys(info).map((k) => {
42
- if (info[k] instanceof Error) {
43
- // eslint-disable-next-line no-param-reassign
44
- info[k] = serializeError(info[k]);
45
- }
46
- });
47
- return info;
48
- });
49
- const getFormat = () => {
50
- if (isProd) {
51
- return winston_1.default.format.combine(enumerateErrorFormat(), winston_1.default.format.json());
52
- }
53
- return winston_1.default.format.combine(enumerateErrorFormat(), winston_1.default.format.splat(), winston_1.default.format.colorize(), winston_1.default.format.simple());
54
- };
55
- const logger = createLogger({
56
- level: getLevel(),
57
- format: getFormat(),
58
- transports: [
59
- new winston_1.default.transports.Console(),
60
- ],
61
- exitOnError: false,
62
- });
63
- const httpMorganInfo = (options) => {
64
- logger.info(options.url, {
65
- httpRequest: {
66
- status: options.status,
67
- requestUrl: options.url,
68
- requestMethod: options.method,
69
- responseSize: options['content-length'],
70
- latency: {
71
- seconds: parseInt(options['response-time'], 10) / 1000,
72
- nanos: parseInt(options['response-time'], 10) * 1000000,
73
- },
74
- userAgent: options['user-agent'],
75
- },
76
- });
77
- };
78
- exports.httpMorganInfo = httpMorganInfo;
79
- exports.default = logger;
@@ -1,44 +0,0 @@
1
- const Events = require('@autofleet/events');
2
- import logger from './logger';
3
-
4
-
5
- interface EntityObject {
6
- entityId: string;
7
- entityType: string;
8
- businessModelId?: string;
9
- fleetId?: string;
10
- demandSourceId?: string;
11
- }
12
-
13
- const events = new Events({ logger });
14
-
15
- export default class DebugConsoleLog {
16
- entites: EntityObject;
17
- constructor(entites: EntityObject) {
18
- this.entites = entites;
19
- }
20
-
21
- private generateLevelLog(level: 'info' | 'warn'| 'error') {
22
- return async (msg: string, payload: any, additonalEntityies?: any) => {
23
- logger[level](msg, payload);
24
- events.send('log_events', 1, {
25
- action: 'logEvent',
26
- level,
27
- ...this.entites,
28
- payload: JSON.stringify(payload),
29
- });
30
- }
31
- }
32
-
33
- async info(msg: string, payload?: any, additonalEntityies?: any) {
34
- return this.generateLevelLog('info')(msg, payload, additonalEntityies);
35
- }
36
-
37
- async warn(msg: string, payload?: any, additonalEntityies?: any) {
38
- return this.generateLevelLog('warn')(msg, payload, additonalEntityies);
39
- }
40
-
41
- async error(msg: string, payload?: any, additonalEntityies?: any) {
42
- return this.generateLevelLog('error')(msg, payload, additonalEntityies);
43
- }
44
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- import logger from './logger';
2
- import DebugConsoleLog from './debug-console-log';
3
-
4
- export {
5
- DebugConsoleLog
6
- };
7
-
8
- export default logger;
package/src/logger.ts DELETED
@@ -1,91 +0,0 @@
1
- import winston from 'winston';
2
-
3
- const { createLogger } = winston;
4
- require('dotenv').config();
5
-
6
- const { env } = process;
7
-
8
- const isProd = env.NODE_ENV === 'production';
9
-
10
- const infoEnvNmaes = [
11
- 'production',
12
- 'staging',
13
- 'test',
14
- ];
15
-
16
- const serializeError = (error: any) => {
17
- const fields = ['code', 'status', 'statusCode', 'message', 'messageData', 'name', 'stack', 'stackTrace'];
18
- return fields.reduce((v, field) => ({ ...v, [field]: error[field] }), {});
19
- };
20
-
21
- const getLevel = () => {
22
- if (env.LOG_LEVEL) return env.LOG_LEVEL;
23
- if (infoEnvNmaes.includes(env.NODE_ENV || '')) return 'info';
24
- if (env.NODE_ENV === 'development') return 'debug';
25
- return 'debug';
26
- };
27
-
28
- const enumerateErrorFormat = winston.format((info) => {
29
- // fix for this crap: https://github.com/googleapis/nodejs-logging-winston/issues/285
30
- // eslint-disable-next-line no-param-reassign
31
- info.severity = info.level.toUpperCase();
32
- if (info instanceof Error) {
33
- return Object.assign({
34
- message: info.message,
35
- stack: info.stack,
36
- }, info);
37
- }
38
-
39
- // eslint-disable-next-line array-callback-return
40
- Object.keys(info).map((k) => {
41
- if (info[k] instanceof Error) {
42
- // eslint-disable-next-line no-param-reassign
43
- info[k] = serializeError(info[k]);
44
- }
45
- });
46
-
47
- return info;
48
- });
49
-
50
- const getFormat = () => {
51
- if (isProd) {
52
- return winston.format.combine(
53
- enumerateErrorFormat(),
54
- winston.format.json(),
55
- );
56
- }
57
-
58
- return winston.format.combine(
59
- enumerateErrorFormat(),
60
- winston.format.splat(),
61
- winston.format.colorize(),
62
- winston.format.simple(),
63
- );
64
- };
65
-
66
- const logger = createLogger({
67
- level: getLevel(),
68
- format: getFormat(),
69
- transports: [
70
- new winston.transports.Console(),
71
- ],
72
- exitOnError: false,
73
- });
74
-
75
- export const httpMorganInfo = (options: any) => {
76
- logger.info(options.url, {
77
- httpRequest: {
78
- status: options.status,
79
- requestUrl: options.url,
80
- requestMethod: options.method,
81
- responseSize: options['content-length'],
82
- latency: {
83
- seconds: parseInt(options['response-time'], 10) / 1000,
84
- nanos: parseInt(options['response-time'], 10) * 1000000,
85
- },
86
- userAgent: options['user-agent'],
87
- },
88
- });
89
- };
90
-
91
- export default logger;
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "module": "commonjs",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "esModuleInterop": true
9
- }
10
- }