nextrans-logger 0.2.10 → 0.2.20

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/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*.{ts, js}]
4
+ indent_size = 2
5
+
6
+ [*.md]
7
+ trim_trailing_whitespace = false
8
+
9
+ [*]
10
+ quote_type = single
@@ -0,0 +1,6 @@
1
+ {
2
+ "editor.tabSize": 2,
3
+ "prettier.singleQuote": true,
4
+ "javascript.preferences.quoteStyle": "single",
5
+ "typescript.preferences.quoteStyle": "single"
6
+ }
package/lib/index.cjs CHANGED
@@ -47,12 +47,14 @@ function formatMessage(log, env) {
47
47
  message.push(log === null || log === void 0 ? void 0 : log.options);
48
48
  }
49
49
  const output = message
50
- .map((data) => (typeof data === 'object' ? '\n```' + JSON.stringify(data, null, '\t') + '```' : `${data}`))
50
+ .map((data) => typeof data === 'object'
51
+ ? '\n```' + JSON.stringify(data, null, '\t') + '```'
52
+ : `${data}`)
51
53
  .join(' ');
52
54
  return output;
53
55
  }
54
56
  class Logging {
55
- constructor({ enable = false, slackWebhook, cloudwatchOption, env = 'DEVELOPMENT' }) {
57
+ constructor({ enable = false, slackWebhook, cloudwatchOption, env = 'DEVELOPMENT', }) {
56
58
  this.env = 'DEVELOPMENT';
57
59
  this.enable = false;
58
60
  this.env = env;
@@ -73,7 +75,10 @@ class Logging {
73
75
  var _a, _b, _c, _d;
74
76
  const transportsData = [
75
77
  new winston_1.transports.Console({
76
- format: this.formatPrint(winston_1.format.colorize({ all: true, colors: { info: 'green', error: 'red', warn: 'yellow' } })),
78
+ format: this.formatPrint(winston_1.format.colorize({
79
+ all: true,
80
+ colors: { info: 'green', error: 'red', warn: 'yellow' },
81
+ })),
77
82
  handleExceptions: true,
78
83
  level: 'debug',
79
84
  }),
@@ -116,48 +121,55 @@ class Logging {
116
121
  }
117
122
  this.log = log;
118
123
  }
119
- format(arg) {
120
- if (arg instanceof Error || typeof arg !== 'object') {
124
+ format(args) {
125
+ return args
126
+ .map((arg) => {
127
+ if (arg instanceof Error) {
128
+ let logString = arg.message;
129
+ logString += '\n';
130
+ logString += '```' + (arg === null || arg === void 0 ? void 0 : arg.stack) + '```';
131
+ return logString;
132
+ }
133
+ if (typeof arg === 'object') {
134
+ return JSON.stringify(arg, null, '\t');
135
+ }
121
136
  return arg;
122
- }
123
- if (typeof arg === 'object') {
124
- return JSON.stringify(arg, null, '\t');
125
- }
126
- return arg;
137
+ })
138
+ .join(': ');
127
139
  }
128
140
  error(...args) {
129
141
  if (!this.log)
130
142
  this.setLog();
131
143
  if (process.env.NODE_ENV !== 'test') {
132
- this.log.error(args.map((arg) => this.format(arg)).join(': '));
144
+ this.log.error(this.format(args));
133
145
  }
134
146
  }
135
147
  info(...args) {
136
148
  if (!this.log)
137
149
  this.setLog();
138
150
  if (process.env.NODE_ENV !== 'test') {
139
- this.log.info(args.map((arg) => this.format(arg)).join(': '));
151
+ this.log.info(this.format(args));
140
152
  }
141
153
  }
142
154
  warning(...args) {
143
155
  if (!this.log)
144
156
  this.setLog();
145
157
  if (process.env.NODE_ENV !== 'test') {
146
- this.log.warning(args.map((arg) => this.format(arg)).join(': '));
158
+ this.log.warning(this.format(args));
147
159
  }
148
160
  }
149
161
  warn(...args) {
150
162
  if (!this.log)
151
163
  this.setLog();
152
164
  if (process.env.NODE_ENV !== 'test') {
153
- this.log.warn(args.map((arg) => this.format(arg)).join(': '));
165
+ this.log.warn(this.format(args));
154
166
  }
155
167
  }
156
168
  debug(...args) {
157
169
  if (!this.log)
158
170
  this.setLog();
159
171
  if (process.env.NODE_ENV !== 'test') {
160
- this.log.debug(args.map((arg) => this.format(arg)).join(': '));
172
+ this.log.debug(this.format(args));
161
173
  }
162
174
  }
163
175
  }
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import * as logform from 'logform';
1
2
  import winston from 'winston';
2
3
  import { LogObject } from 'winston-cloudwatch';
3
- import * as logform from 'logform';
4
4
  export type ErrorType = 'error' | 'info' | 'warn' | 'debug';
5
5
  export interface CloudwatchOptions {
6
6
  logGroupName: string;
@@ -23,11 +23,11 @@ export default class Logging {
23
23
  protected slackWebhook?: string;
24
24
  protected cloudwatchOption?: CloudwatchOptions;
25
25
  protected log: winston.Logger;
26
- constructor({ enable, slackWebhook, cloudwatchOption, env }: LoggingOptions);
26
+ constructor({ enable, slackWebhook, cloudwatchOption, env, }: LoggingOptions);
27
27
  protected lineFormat(log: LogObject): string;
28
- protected formatPrint(...formats: logform.Format[]): winston.Logform.Format;
28
+ protected formatPrint(...formats: logform.Format[]): logform.Format;
29
29
  protected setLog(): void;
30
- protected format(arg: unknown): unknown;
30
+ protected format(args: unknown[]): string;
31
31
  error(...args: unknown[]): void;
32
32
  info(...args: unknown[]): void;
33
33
  warning(...args: unknown[]): void;
package/lib/index.js CHANGED
@@ -41,7 +41,9 @@ function formatMessage(log, env) {
41
41
  message.push(log?.options);
42
42
  }
43
43
  const output = message
44
- .map((data) => (typeof data === 'object' ? '\n```' + JSON.stringify(data, null, '\t') + '```' : `${data}`))
44
+ .map((data) => typeof data === 'object'
45
+ ? '\n```' + JSON.stringify(data, null, '\t') + '```'
46
+ : `${data}`)
45
47
  .join(' ');
46
48
  return output;
47
49
  }
@@ -51,7 +53,7 @@ export default class Logging {
51
53
  slackWebhook;
52
54
  cloudwatchOption;
53
55
  log;
54
- constructor({ enable = false, slackWebhook, cloudwatchOption, env = 'DEVELOPMENT' }) {
56
+ constructor({ enable = false, slackWebhook, cloudwatchOption, env = 'DEVELOPMENT', }) {
55
57
  this.env = env;
56
58
  this.enable = enable;
57
59
  if (slackWebhook && enable)
@@ -69,7 +71,10 @@ export default class Logging {
69
71
  setLog() {
70
72
  const transportsData = [
71
73
  new transports.Console({
72
- format: this.formatPrint(format.colorize({ all: true, colors: { info: 'green', error: 'red', warn: 'yellow' } })),
74
+ format: this.formatPrint(format.colorize({
75
+ all: true,
76
+ colors: { info: 'green', error: 'red', warn: 'yellow' },
77
+ })),
73
78
  handleExceptions: true,
74
79
  level: 'debug',
75
80
  }),
@@ -109,48 +114,55 @@ export default class Logging {
109
114
  }
110
115
  this.log = log;
111
116
  }
112
- format(arg) {
113
- if (arg instanceof Error || typeof arg !== 'object') {
117
+ format(args) {
118
+ return args
119
+ .map((arg) => {
120
+ if (arg instanceof Error) {
121
+ let logString = arg.message;
122
+ logString += '\n';
123
+ logString += '```' + arg?.stack + '```';
124
+ return logString;
125
+ }
126
+ if (typeof arg === 'object') {
127
+ return JSON.stringify(arg, null, '\t');
128
+ }
114
129
  return arg;
115
- }
116
- if (typeof arg === 'object') {
117
- return JSON.stringify(arg, null, '\t');
118
- }
119
- return arg;
130
+ })
131
+ .join(': ');
120
132
  }
121
133
  error(...args) {
122
134
  if (!this.log)
123
135
  this.setLog();
124
136
  if (process.env.NODE_ENV !== 'test') {
125
- this.log.error(args.map((arg) => this.format(arg)).join(': '));
137
+ this.log.error(this.format(args));
126
138
  }
127
139
  }
128
140
  info(...args) {
129
141
  if (!this.log)
130
142
  this.setLog();
131
143
  if (process.env.NODE_ENV !== 'test') {
132
- this.log.info(args.map((arg) => this.format(arg)).join(': '));
144
+ this.log.info(this.format(args));
133
145
  }
134
146
  }
135
147
  warning(...args) {
136
148
  if (!this.log)
137
149
  this.setLog();
138
150
  if (process.env.NODE_ENV !== 'test') {
139
- this.log.warning(args.map((arg) => this.format(arg)).join(': '));
151
+ this.log.warning(this.format(args));
140
152
  }
141
153
  }
142
154
  warn(...args) {
143
155
  if (!this.log)
144
156
  this.setLog();
145
157
  if (process.env.NODE_ENV !== 'test') {
146
- this.log.warn(args.map((arg) => this.format(arg)).join(': '));
158
+ this.log.warn(this.format(args));
147
159
  }
148
160
  }
149
161
  debug(...args) {
150
162
  if (!this.log)
151
163
  this.setLog();
152
164
  if (process.env.NODE_ENV !== 'test') {
153
- this.log.debug(args.map((arg) => this.format(arg)).join(': '));
165
+ this.log.debug(this.format(args));
154
166
  }
155
167
  }
156
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextrans-logger",
3
- "version": "0.2.10",
3
+ "version": "0.2.20",
4
4
  "description": "Logging for nextrans app service",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",
@@ -14,7 +14,7 @@
14
14
  "author": "nextrans-team",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@aws-sdk/client-cloudwatch-logs": "^3.290.0",
17
+ "@aws-sdk/client-cloudwatch-logs": "^3.347.0",
18
18
  "moment": "^2.29.4",
19
19
  "winston": "^3.8.2",
20
20
  "winston-cloudwatch": "^6.1.1",