@quartz-labs/logger 1.0.3 → 1.1.1
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/README.md +19 -0
- package/dist/logger.d.ts +13 -1
- package/dist/logger.js +11 -4
- package/dist/logger.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img width="2500" alt="Quartz" src="https://cdn.prod.website-files.com/67504dd7fde047775f88c355/67b380029cf6f3d8e10349bf_docs_banner.jpg" />
|
|
3
|
+
|
|
4
|
+
<h1 style="margin-top:20px;">Quartz Logger</h1>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
This repository is Quartz's open-source logger package. You can install using:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
yarn add @quartz-labs/logger
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Links
|
|
14
|
+
|
|
15
|
+
Website and waitlist: [quartzpay.io](https://quartzpay.io/)
|
|
16
|
+
|
|
17
|
+
X: [@quartzpay](https://x.com/quartzpay)
|
|
18
|
+
|
|
19
|
+
Contact: [diego@quartzpay.io](mailto:diego@quartzpay.io)
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { type Logger } from "winston";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the AppLogger class.
|
|
4
|
+
*
|
|
5
|
+
* @property {string} name - The name of the application, included in the logs and emails.
|
|
6
|
+
* @property {number} dailyErrorCacheTimeMs - The time in milliseconds to cache errors for before sending an email. Cleared daily. Eg: 1000 * 60 * 60 will send one email per hour if the same error is repeated, specifying how many times it occurred in the hour.
|
|
7
|
+
*/
|
|
2
8
|
export interface AppLoggerOptions {
|
|
3
9
|
name: string;
|
|
4
10
|
dailyErrorCacheTimeMs?: number;
|
|
5
11
|
}
|
|
6
12
|
export declare class AppLogger {
|
|
13
|
+
private name;
|
|
7
14
|
protected logger: Logger;
|
|
8
15
|
private dailyErrorCache;
|
|
9
16
|
private dailyErrorCacheTimeMs;
|
|
17
|
+
/**
|
|
18
|
+
* Constructor for the AppLogger class.
|
|
19
|
+
*
|
|
20
|
+
* @param {AppLoggerOptions} options - The {@link AppLoggerOptions} to set up the logger.
|
|
21
|
+
*/
|
|
10
22
|
constructor(options: AppLoggerOptions);
|
|
11
|
-
protected
|
|
23
|
+
protected sendEmail(subject: string, message: string): Promise<void>;
|
|
12
24
|
}
|
package/dist/logger.js
CHANGED
|
@@ -3,10 +3,17 @@ import winston, { createLogger, transports } from "winston";
|
|
|
3
3
|
import nodemailer from "nodemailer";
|
|
4
4
|
import config from "./config.js";
|
|
5
5
|
export class AppLogger {
|
|
6
|
+
name;
|
|
6
7
|
logger;
|
|
7
8
|
dailyErrorCache = new Map();
|
|
8
9
|
dailyErrorCacheTimeMs;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor for the AppLogger class.
|
|
12
|
+
*
|
|
13
|
+
* @param {AppLoggerOptions} options - The {@link AppLoggerOptions} to set up the logger.
|
|
14
|
+
*/
|
|
9
15
|
constructor(options) {
|
|
16
|
+
this.name = options.name;
|
|
10
17
|
if (options.dailyErrorCacheTimeMs === undefined || options.dailyErrorCacheTimeMs < 0) {
|
|
11
18
|
this.dailyErrorCacheTimeMs = 0;
|
|
12
19
|
}
|
|
@@ -42,8 +49,8 @@ export class AppLogger {
|
|
|
42
49
|
// Only send email if error has not been sent in the last errorEmailCacheTime seconds
|
|
43
50
|
if (now - cacheEntry.lastSent > this.dailyErrorCacheTimeMs) {
|
|
44
51
|
const emailSubject = this.dailyErrorCacheTimeMs > 0
|
|
45
|
-
? `${
|
|
46
|
-
: `${
|
|
52
|
+
? `${this.name} Error (${cacheEntry.count} occurrences in past ${dailyErrorCacheTimeMinutes} minutes)`
|
|
53
|
+
: `${this.name} Error`;
|
|
47
54
|
for (const admin of config.EMAIL_TO) {
|
|
48
55
|
mailTransporter.sendMail({
|
|
49
56
|
from: config.EMAIL_FROM,
|
|
@@ -87,7 +94,7 @@ export class AppLogger {
|
|
|
87
94
|
this.logger.error(reason);
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
|
-
async
|
|
97
|
+
async sendEmail(subject, message) {
|
|
91
98
|
try {
|
|
92
99
|
const mailTransporter = nodemailer.createTransport({
|
|
93
100
|
host: config.EMAIL_HOST,
|
|
@@ -101,7 +108,7 @@ export class AppLogger {
|
|
|
101
108
|
await Promise.all(config.EMAIL_TO.map(admin => mailTransporter.sendMail({
|
|
102
109
|
from: config.EMAIL_FROM,
|
|
103
110
|
to: admin,
|
|
104
|
-
subject: `${subject}`,
|
|
111
|
+
subject: `${this.name} | ${subject}`,
|
|
105
112
|
text: message,
|
|
106
113
|
})));
|
|
107
114
|
}
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,OAAO,EAAE,EAAE,YAAY,EAAe,UAAU,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,MAAM,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,OAAO,EAAE,EAAE,YAAY,EAAe,UAAU,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,MAAM,MAAM,aAAa,CAAC;AAejC,MAAM,OAAO,SAAS;IACV,IAAI,CAAS;IAEX,MAAM,CAAS;IAEjB,eAAe,GAAG,IAAI,GAAG,EAA2B,CAAC;IACrD,qBAAqB,CAAS;IAEtC;;;;OAIG;IACH,YAAY,OAAyB;QACjC,IAAI,CA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