File tree 4 files changed +21
-0
lines changed
4 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ npm install log4js @log4js-node/logstash-http
14
14
* ` logChannel ` - ` string ` (optional) - also used to identify your application's logs [ but in a more specific way]
15
15
* ` logType ` - ` string ` (optional) - used for the ` type ` field in the logstash data
16
16
* ` timeout ` - ` integer ` (optional, defaults to 5000ms) - the timeout for the HTTP request.
17
+ * ` agent ` - ` http.Agent | https.Agent ` (optional) - used to configure the requests being sent out if needed.
17
18
18
19
This appender will also pick up Logger context values from the events, and add them as ` p_ ` values in the logFaces event. See the example below for more details.
19
20
Original file line number Diff line number Diff line change @@ -34,13 +34,18 @@ function format(logData) {
34
34
* "logChannel": "test", // channel of the application
35
35
* "url": "http://lfs-server/_bulk", // logstash receiver servlet URL
36
36
* }
37
+ * @param {import('../types').LogstashHTTPAppender } config
37
38
*/
38
39
function logstashHTTPAppender ( config ) {
39
40
const sender = axios . create ( {
40
41
baseURL : config . url ,
41
42
timeout : config . timeout || 5000 ,
42
43
headers : { 'Content-Type' : 'application/x-ndjson' } ,
43
44
withCredentials : true ,
45
+ // The user should pass in the correct Agent type for their url
46
+ // since their url won't change after config this should be fine
47
+ httpAgent : config . agent ,
48
+ httpsAgent : config . agent ,
44
49
} ) ;
45
50
46
51
return function log ( event ) {
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const { Agent } = require ( 'http' ) ;
3
4
const test = require ( 'tap' ) . test ;
4
5
const sandbox = require ( '@log4js-node/sandboxed-module' ) ;
5
6
const appender = require ( '../../lib' ) ;
@@ -64,18 +65,25 @@ test('logstashappender', (batch) => {
64
65
} ) ;
65
66
66
67
batch . test ( 'when using HTTP receivers' , ( t ) => {
68
+ const agent = new Agent ( ) ;
67
69
const setup = setupLogging ( 'myCategory' , {
68
70
application : 'logstash-sample' ,
69
71
logType : 'application' ,
70
72
logChannel : 'sample' ,
71
73
url : 'http://localhost/receivers/rx1'
74
+ agent ,
72
75
} ) ;
73
76
74
77
t . test ( 'axios should be configured' , ( assert ) => {
75
78
assert . equal ( setup . fakeAxios . config . baseURL , 'http://localhost/receivers/rx1' ) ;
76
79
assert . equal ( setup . fakeAxios . config . timeout , 5000 ) ;
77
80
assert . equal ( setup . fakeAxios . config . withCredentials , true ) ;
78
81
assert . same ( setup . fakeAxios . config . headers , { 'Content-Type' : 'application/x-ndjson' } ) ;
82
+ // For some reason with the sandboxed tests, the instanceof Agent doesn't exist.
83
+ assert . match ( setup . fakeAxios . config , {
84
+ httpAgent : Object ,
85
+ httpsAgent : Object ,
86
+ } ) ;
79
87
assert . end ( ) ;
80
88
} ) ;
81
89
Original file line number Diff line number Diff line change
1
+ import type { Agent as httpAgent } from 'http' ;
2
+ import type { Agent as httpsAgent } from 'https' ;
3
+
1
4
export interface LogstashHTTPAppender extends Appender {
2
5
type : '@log4js-node/logstashHTTP' ;
3
6
url : string ;
4
7
timeout ?: number ; //defaults to 5000
5
8
application ?: string ;
6
9
logChannel ?: string ;
7
10
logType ?: string ;
11
+ /** An http.Agent or https.Agent to allow configuring behavior as needed.
12
+ * Make sure you use the correct type base on your url
13
+ */
14
+ agent ?: httpAgent | httpsAgent ;
8
15
}
You can’t perform that action at this time.
0 commit comments