@@ -35,10 +35,17 @@ function sendBuffer() {
35
35
headers : { "Hostname" : os . hostname ( ) }
36
36
} ;
37
37
38
- if ( ! config . html ) {
39
- msg . text = body ;
38
+ if ( true === config . attachment . enable ) {
39
+ msg [ config . html ? "html" : "text" ] = config . attachment . message ;
40
+ msg . attachments = [
41
+ {
42
+ filename : config . attachment . filename ,
43
+ contentType : 'text/x-log' ,
44
+ content : body
45
+ }
46
+ ] ;
40
47
} else {
41
- msg . html = body ;
48
+ msg [ config . html ? "html" : "text" ] = body ;
42
49
}
43
50
44
51
if ( config . sender ) {
@@ -82,20 +89,28 @@ function scheduleSend() {
82
89
* It can either send an email on each event or group several
83
90
* logging events gathered during specified interval.
84
91
*
85
- * @param config appender configuration data
92
+ * @param _config appender configuration data
86
93
* config.sendInterval time between log emails (in seconds), if 0
87
94
* then every event sends an email
88
95
* config.shutdownTimeout time to give up remaining emails (in seconds; defaults to 5).
89
96
* @param _layout a function that takes a logevent and returns a string (defaults to basicLayout).
90
97
*/
91
98
function smtpAppender ( _config , _layout ) {
92
99
config = _config ;
100
+
101
+ if ( ! config . attachment ) {
102
+ config . attachment = { } ;
103
+ }
104
+
105
+ config . attachment . enable = ! ! config . attachment . enable ;
106
+ config . attachment . message = config . attachment . message || "See logs as attachment" ;
107
+ config . attachment . filename = config . attachment . filename || "default.log" ;
93
108
layout = _layout || layouts . basicLayout ;
94
109
subjectLayout = layouts . messagePassThroughLayout ;
95
110
sendInterval = config . sendInterval * 1000 || 0 ;
96
-
111
+
97
112
shutdownTimeout = ( 'shutdownTimeout' in config ? config . shutdownTimeout : 5 ) * 1000 ;
98
-
113
+
99
114
return function ( loggingEvent ) {
100
115
unsentCount ++ ;
101
116
logEventBuffer . push ( loggingEvent ) ;
@@ -118,7 +133,8 @@ function configure(_config) {
118
133
function shutdown ( cb ) {
119
134
if ( shutdownTimeout > 0 ) {
120
135
setTimeout ( function ( ) {
121
- if ( sendTimer ) clearTimeout ( sendTimer ) ;
136
+ if ( sendTimer )
137
+ clearTimeout ( sendTimer ) ;
122
138
sendBuffer ( ) ;
123
139
} , shutdownTimeout ) ;
124
140
}
0 commit comments