@ttoss/logger 0.5.0 → 0.6.0

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/esm/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
 
3
3
  // src/index.ts
4
+ var log = {
5
+ warn: console.warn,
6
+ error: console.error,
7
+ info: console.info
8
+ };
4
9
  var setup = null;
5
10
  var configureLogger = params => {
6
11
  setup = params;
@@ -30,6 +35,10 @@ var sendNotificationToDiscord = async ({
30
35
  });
31
36
  };
32
37
  var notify = async notification => {
38
+ if (notification.log) {
39
+ const message = [notification.title, notification.message].join(": ");
40
+ log[notification.type](message);
41
+ }
33
42
  if (!setup?.project) {
34
43
  return;
35
44
  }
@@ -41,9 +50,21 @@ var notify = async notification => {
41
50
  });
42
51
  }
43
52
  };
44
- var log = {
45
- warn: console.warn,
46
- error: console.error,
47
- info: console.info
53
+ var getErrorMessage = error => {
54
+ if (error instanceof Error) {
55
+ return error.message;
56
+ }
57
+ if (typeof error === "string") {
58
+ return error;
59
+ }
60
+ return "Unknown error:" + JSON.stringify(error);
61
+ };
62
+ var notifyError = async notification => {
63
+ return notify({
64
+ type: "error",
65
+ message: getErrorMessage(notification.error),
66
+ title: notification.title,
67
+ log: notification.log
68
+ });
48
69
  };
49
- export { configureLogger, log, notify, sendNotificationToDiscord };
70
+ export { configureLogger, log, notify, notifyError, sendNotificationToDiscord };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,23 @@
1
1
  type NotificationType = 'info' | 'warn' | 'error';
2
+ declare const log: {
3
+ warn: {
4
+ (...data: any[]): void;
5
+ (message?: any, ...optionalParams: any[]): void;
6
+ };
7
+ error: {
8
+ (...data: any[]): void;
9
+ (message?: any, ...optionalParams: any[]): void;
10
+ };
11
+ info: {
12
+ (...data: any[]): void;
13
+ (message?: any, ...optionalParams: any[]): void;
14
+ };
15
+ };
2
16
  type NotificationMessage = {
3
17
  type: NotificationType;
4
18
  title?: string;
5
19
  message: string;
20
+ log?: boolean;
6
21
  };
7
22
  type Configuration = {
8
23
  discordWebhookUrl?: string;
@@ -15,19 +30,10 @@ declare const sendNotificationToDiscord: ({ notification, url, project, }: {
15
30
  project: string;
16
31
  }) => Promise<void>;
17
32
  declare const notify: (notification: NotificationMessage) => Promise<void>;
18
- declare const log: {
19
- warn: {
20
- (...data: any[]): void;
21
- (message?: any, ...optionalParams: any[]): void;
22
- };
23
- error: {
24
- (...data: any[]): void;
25
- (message?: any, ...optionalParams: any[]): void;
26
- };
27
- info: {
28
- (...data: any[]): void;
29
- (message?: any, ...optionalParams: any[]): void;
30
- };
31
- };
33
+ declare const notifyError: (notification: {
34
+ error: unknown;
35
+ title?: string;
36
+ log?: boolean;
37
+ }) => Promise<void>;
32
38
 
33
- export { configureLogger, log, notify, sendNotificationToDiscord };
39
+ export { configureLogger, log, notify, notifyError, sendNotificationToDiscord };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,23 @@
1
1
  type NotificationType = 'info' | 'warn' | 'error';
2
+ declare const log: {
3
+ warn: {
4
+ (...data: any[]): void;
5
+ (message?: any, ...optionalParams: any[]): void;
6
+ };
7
+ error: {
8
+ (...data: any[]): void;
9
+ (message?: any, ...optionalParams: any[]): void;
10
+ };
11
+ info: {
12
+ (...data: any[]): void;
13
+ (message?: any, ...optionalParams: any[]): void;
14
+ };
15
+ };
2
16
  type NotificationMessage = {
3
17
  type: NotificationType;
4
18
  title?: string;
5
19
  message: string;
20
+ log?: boolean;
6
21
  };
7
22
  type Configuration = {
8
23
  discordWebhookUrl?: string;
@@ -15,19 +30,10 @@ declare const sendNotificationToDiscord: ({ notification, url, project, }: {
15
30
  project: string;
16
31
  }) => Promise<void>;
17
32
  declare const notify: (notification: NotificationMessage) => Promise<void>;
18
- declare const log: {
19
- warn: {
20
- (...data: any[]): void;
21
- (message?: any, ...optionalParams: any[]): void;
22
- };
23
- error: {
24
- (...data: any[]): void;
25
- (message?: any, ...optionalParams: any[]): void;
26
- };
27
- info: {
28
- (...data: any[]): void;
29
- (message?: any, ...optionalParams: any[]): void;
30
- };
31
- };
33
+ declare const notifyError: (notification: {
34
+ error: unknown;
35
+ title?: string;
36
+ log?: boolean;
37
+ }) => Promise<void>;
32
38
 
33
- export { configureLogger, log, notify, sendNotificationToDiscord };
39
+ export { configureLogger, log, notify, notifyError, sendNotificationToDiscord };
package/dist/index.js CHANGED
@@ -30,9 +30,15 @@ __export(index_exports, {
30
30
  configureLogger: () => configureLogger,
31
31
  log: () => log,
32
32
  notify: () => notify,
33
+ notifyError: () => notifyError,
33
34
  sendNotificationToDiscord: () => sendNotificationToDiscord
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
37
+ var log = {
38
+ warn: console.warn,
39
+ error: console.error,
40
+ info: console.info
41
+ };
36
42
  var setup = null;
37
43
  var configureLogger = params => {
38
44
  setup = params;
@@ -62,6 +68,10 @@ var sendNotificationToDiscord = async ({
62
68
  });
63
69
  };
64
70
  var notify = async notification => {
71
+ if (notification.log) {
72
+ const message = [notification.title, notification.message].join(": ");
73
+ log[notification.type](message);
74
+ }
65
75
  if (!setup?.project) {
66
76
  return;
67
77
  }
@@ -73,15 +83,28 @@ var notify = async notification => {
73
83
  });
74
84
  }
75
85
  };
76
- var log = {
77
- warn: console.warn,
78
- error: console.error,
79
- info: console.info
86
+ var getErrorMessage = error => {
87
+ if (error instanceof Error) {
88
+ return error.message;
89
+ }
90
+ if (typeof error === "string") {
91
+ return error;
92
+ }
93
+ return "Unknown error:" + JSON.stringify(error);
94
+ };
95
+ var notifyError = async notification => {
96
+ return notify({
97
+ type: "error",
98
+ message: getErrorMessage(notification.error),
99
+ title: notification.title,
100
+ log: notification.log
101
+ });
80
102
  };
81
103
  // Annotate the CommonJS export names for ESM import in node:
82
104
  0 && (module.exports = {
83
105
  configureLogger,
84
106
  log,
85
107
  notify,
108
+ notifyError,
86
109
  sendNotificationToDiscord
87
110
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/logger",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "A simple module to configure and send notifications to services like Discord from your applications.",
5
5
  "license": "MIT",
6
6
  "contributors": [],
@@ -23,7 +23,8 @@
23
23
  "devDependencies": {
24
24
  "jest": "^29.7.0",
25
25
  "tsup": "^8.3.5",
26
- "@ttoss/config": "^1.35.2"
26
+ "@ttoss/config": "^1.35.2",
27
+ "@ttoss/test-utils": "^2.1.22"
27
28
  },
28
29
  "keywords": [],
29
30
  "publishConfig": {