@log4js-node/smtp 1.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -17,7 +17,7 @@ npm install @log4js-node/smtp
17
17
  * `auth` - `object` (optional) - authentication details
18
18
  * `user` - `string`
19
19
  * `pass` - `string`
20
- * `transport` - `object` (optional, if not present will use `SMTP`) - see nodemailer docs for transport options
20
+ * `transport` - `object` (optional, if not present will use `SMTP`) - see [`nodemailer`](https://nodemailer.com/smtp/) docs for transport options
21
21
  * `plugin` - `string` (optional, defaults to `smtp`) - the nodemailer transport plugin to use
22
22
  * `options` - `object` - configuration for the transport plugin
23
23
  * `attachment` - `object` (optional) - send logs as email attachment
@@ -30,7 +30,9 @@ npm install @log4js-node/smtp
30
30
  * `subject` - `string` (optional, defaults to message from first log event in batch) - subject for email
31
31
  * `sender` - `string` (optional) - who the logs should be sent as
32
32
  * `html` - `boolean` (optional, defaults to `false`) - send the email as HTML instead of plain text
33
- * `layout` - `object` (optional, defaults to basicLayout) - see [layouts](layouts.md)
33
+ * `layout` - `object` (optional, defaults to basicLayout) - see [layouts](https://log4js-node.github.io/log4js-node/layouts.html)
34
+ * `cc` - `string` (optional) - email addresses to send the carbon-copy logs to
35
+ * `bcc` - `string` (optional) - email addresses to send the blind-carbon-copy logs to
34
36
 
35
37
  ## Example (default config)
36
38
  ```javascript
@@ -72,7 +74,7 @@ This configuration will send an email once every hour, with all the log events o
72
74
  log4js.configure({
73
75
  appenders: {
74
76
  email: {
75
- type: '@log4js-node/smtp', smtp: { host: 'smtp.company.name', port: 8025 }, recipients: 'dev.team@company.name'
77
+ type: '@log4js-node/smtp', SMTP: { host: 'smtp.company.name', port: 8025 }, recipients: 'dev.team@company.name'
76
78
  }
77
79
  },
78
80
  categories: { default: { appenders: ['email'], level: 'info' } }
@@ -99,4 +101,4 @@ log4js.configure({
99
101
  }
100
102
  });
101
103
  ```
102
- A similar config can be used to specify a different transport plugin than `smtp`. See the nodemailer docs for more details.
104
+ A similar config can be used to specify a different transport plugin than `smtp`. See the [`nodemailer`](https://nodemailer.com/smtp/) docs for more details.
package/lib/index.js CHANGED
@@ -4,7 +4,7 @@ const mailer = require('nodemailer');
4
4
  const os = require('os');
5
5
 
6
6
  function getTransportOptions(config) {
7
- let options = null;
7
+ let options = {};
8
8
  if (config.SMTP) {
9
9
  options = config.SMTP;
10
10
  } else if (config.transport) {
@@ -38,6 +38,9 @@ function smtpAppender(config, layout, subjectLayout) {
38
38
  const sendInterval = config.sendInterval * 1000 || 0;
39
39
  const shutdownTimeout = ('shutdownTimeout' in config ? config.shutdownTimeout : 5) * 1000;
40
40
  const transport = mailer.createTransport(getTransportOptions(config));
41
+ transport.on('error', (error) => {
42
+ console.error('log4js.smtpAppender - Error happened', error); // eslint-disable-line no-console
43
+ });
41
44
  const logEventBuffer = [];
42
45
 
43
46
  let unsentCount = 0;
@@ -55,7 +58,9 @@ function smtpAppender(config, layout, subjectLayout) {
55
58
  const msg = {
56
59
  to: config.recipients,
57
60
  subject: config.subject || subjectLayout(firstEvent),
58
- headers: { Hostname: os.hostname() }
61
+ headers: { Hostname: os.hostname() },
62
+ cc: config.cc,
63
+ bcc: config.bcc,
59
64
  };
60
65
 
61
66
  if (config.attachment.enable === true) {
@@ -76,7 +81,7 @@ function smtpAppender(config, layout, subjectLayout) {
76
81
  }
77
82
  transport.sendMail(msg, (error) => {
78
83
  if (error) {
79
- console.error('log4js.smtpAppender - Error happened', error); //eslint-disable-line
84
+ console.error('log4js.smtpAppender - Send mail error happened', error); // eslint-disable-line no-console
80
85
  }
81
86
  transport.close();
82
87
  unsentCount -= count;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@log4js-node/smtp",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "SMTP Appender for log4js-node",
5
5
  "homepage": "https://log4js-node.github.io/log4js-node/",
6
6
  "files": [
@@ -33,6 +33,7 @@
33
33
  "commitmsg": "validate-commit-msg",
34
34
  "pretest": "eslint 'lib/**/*.js' 'test/**/*.js'",
35
35
  "test": "tap 'test/tap/**/*.js' --100",
36
+ "typings": "tsc -p types/tsconfig.json",
36
37
  "codecov": "tap 'test/tap/**/*.js' --cov --coverage-report=lcov && codecov"
37
38
  },
38
39
  "directories": {
@@ -40,20 +41,21 @@
40
41
  "lib": "lib"
41
42
  },
42
43
  "dependencies": {
43
- "debug": "^3.1.0",
44
- "nodemailer": "^4.6.4"
44
+ "debug": "^4.3.3",
45
+ "nodemailer": "^6.7.2"
45
46
  },
46
47
  "devDependencies": {
47
- "@log4js-node/sandboxed-module": "^2.1.1",
48
+ "@log4js-node/sandboxed-module": "^2.2.1",
48
49
  "codecov": "^3.0.0",
49
- "conventional-changelog": "^1.1.15",
50
- "eslint": "^4.10.0",
51
- "eslint-config-airbnb-base": "^12.1.0",
50
+ "conventional-changelog": "^3.1.25",
51
+ "eslint": "^8.7.0",
52
+ "eslint-config-airbnb-base": "^13.2.0",
52
53
  "eslint-import-resolver-node": "^0.3.1",
53
54
  "eslint-plugin-import": "^2.8.0",
54
- "husky": "^0.14.3",
55
- "nyc": "^11.5.0",
56
- "tap": "^12.0.1",
55
+ "husky": "^7.0.4",
56
+ "nyc": "^15.1.0",
57
+ "tap": "^15.1.6",
58
+ "typescript": "^4.5.5",
57
59
  "validate-commit-msg": "^2.14.0"
58
60
  },
59
61
  "browser": {
package/types/index.d.ts CHANGED
@@ -1,5 +1,64 @@
1
1
  // Type definitions for log4js SMTP appender
2
2
 
3
+ export interface BaseLayout {
4
+ type: 'basic';
5
+ }
6
+
7
+ export interface ColoredLayout {
8
+ type: 'colored' | 'coloured';
9
+ }
10
+
11
+ export interface MessagePassThroughLayout {
12
+ type: 'messagePassThrough';
13
+ }
14
+
15
+ export interface DummyLayout {
16
+ type: 'dummy';
17
+ }
18
+
19
+
20
+ export interface Level {
21
+ isEqualTo(other: string): boolean;
22
+ isEqualTo(otherLevel: Level): boolean;
23
+ isLessThanOrEqualTo(other: string): boolean;
24
+ isLessThanOrEqualTo(otherLevel: Level): boolean;
25
+ isGreaterThanOrEqualTo(other: string): boolean;
26
+ isGreaterThanOrEqualTo(otherLevel: Level): boolean;
27
+ colour: string;
28
+ level: number;
29
+ levelStr: string;
30
+ }
31
+
32
+ export interface LoggingEvent {
33
+ categoryName: string; // name of category
34
+ level: Level; // level of message
35
+ data: any[]; // objects to log
36
+ startTime: Date;
37
+ pid: number;
38
+ context: any;
39
+ cluster?: {
40
+ workerId: number;
41
+ worker: number;
42
+ };
43
+ }
44
+
45
+ export type Token = ((logEvent: LoggingEvent) => string) | string;
46
+
47
+ export interface PatternLayout {
48
+ type: 'pattern';
49
+ // specifier for the output format, using placeholders as described below
50
+ pattern: string;
51
+ // user-defined tokens to be used in the pattern
52
+ tokens?: { [name: string]: Token };
53
+ }
54
+
55
+ export interface CustomLayout {
56
+ [key: string]: any;
57
+ type: string;
58
+ }
59
+
60
+ export type Layout = BaseLayout | ColoredLayout | MessagePassThroughLayout | DummyLayout | PatternLayout | CustomLayout;
61
+
3
62
  export interface SmtpAppender {
4
63
  type: '@log4js-node/smtp';
5
64
  // (if not present will use transport field)
@@ -44,6 +103,10 @@ export interface SmtpAppender {
44
103
  html?: boolean;
45
104
  // (defaults to basicLayout)
46
105
  layout?: Layout;
106
+ // email addresses to send the carbon-copy logs to
107
+ cc?: string;
108
+ // email addresses to send the blind-carbon-copy logs to
109
+ bcc?: string;
47
110
  }
48
111
 
49
- export type Appender = Appender | SmtpAppender;
112
+ export type Appender = SmtpAppender;
@@ -0,0 +1,9 @@
1
+ {
2
+ "compileOnSave": false,
3
+ "compilerOptions": {
4
+ "strict": true,
5
+ "noUnusedParameters": true,
6
+ "noUnusedLocals": false,
7
+ "noEmit": true
8
+ }
9
+ }