@ditjenpajakri/elasticsearch-logging 1.0.0 → 2.0.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/README.md +19 -3
- package/lib.js +15 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
@
|
|
1
|
+
@ditjenpajakri/elasticsearch-logging
|
|
2
|
+
|
|
3
|
+
## Add to existing project
|
|
2
4
|
|
|
3
5
|
```
|
|
4
|
-
|
|
6
|
+
yarn global add @ditjenpajakri/elasticsearch-logging
|
|
7
|
+
|
|
8
|
+
# or npm install -g @ditjenpajakri/elasticsearch-logging
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Setup the environment variables
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
LOG_ES_HOST Elasticsearch node. Default: http://localhost:9200
|
|
15
|
+
LOG_ES_USER Elasticsearch username
|
|
16
|
+
LOG_ES_PASS Elasticsearch password
|
|
17
|
+
LOG_ES_INDEX Elasticsearch Index. Default: DJP-%{DATE}
|
|
18
|
+
LOG_ES_FLUSH_BYTES Bytes size before flushing to Elasticsearch
|
|
19
|
+
LOG_ES_FLUSH_INTERVAL Interval time before flushing to Elasticsearch (in ms). Default: 30000 miliseconds
|
|
20
|
+
LOG_ES_REJECT_UNAUTHORIZED Reject Unauthorized for Self Signed Cert SSL. If not set to true, it will be set to false.
|
|
5
21
|
```
|
|
6
22
|
|
|
7
23
|
```
|
|
8
24
|
node server.js | log-to-es
|
|
9
|
-
|
|
25
|
+
```
|
package/lib.js
CHANGED
|
@@ -30,6 +30,8 @@ function initializeBulkHandler (opts, client, splitter) {
|
|
|
30
30
|
client.connectionPool.resurrect({ name: 'elasticsearch-js' })
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
console.log(client)
|
|
33
35
|
|
|
34
36
|
const bulkInsert = client.helpers.bulk({
|
|
35
37
|
datasource: splitter,
|
|
@@ -43,10 +45,9 @@ function initializeBulkHandler (opts, client, splitter) {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
return {
|
|
46
|
-
|
|
48
|
+
create: {
|
|
47
49
|
_index: getIndexName(date),
|
|
48
|
-
_type: type,
|
|
49
|
-
op_type: opType
|
|
50
|
+
// _type: type,
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
},
|
|
@@ -66,7 +67,7 @@ function initializeBulkHandler (opts, client, splitter) {
|
|
|
66
67
|
if (buildIndexName) {
|
|
67
68
|
return buildIndexName(time)
|
|
68
69
|
}
|
|
69
|
-
return index.replace('%{DATE}', time.substring(0, 10))
|
|
70
|
+
return index.replace('%{DATE}', time.substring ? time.substring(0, 10) : "")
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
|
|
@@ -93,11 +94,11 @@ function pinoElasticSearch(opts = {}) {
|
|
|
93
94
|
if (typeof value !== 'object') {
|
|
94
95
|
value = {
|
|
95
96
|
data: value,
|
|
96
|
-
|
|
97
|
+
['@timestamp']: setDateTimeString(value)
|
|
97
98
|
}
|
|
98
99
|
} else {
|
|
99
100
|
if (value['@timestamp'] === undefined) {
|
|
100
|
-
value
|
|
101
|
+
value['@timestamp'] = setDateTimeString(value)
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
return value
|
|
@@ -107,7 +108,9 @@ function pinoElasticSearch(opts = {}) {
|
|
|
107
108
|
node: opts.node,
|
|
108
109
|
auth: opts.auth,
|
|
109
110
|
// cloud: opts.cloud,
|
|
110
|
-
|
|
111
|
+
tls: {
|
|
112
|
+
rejectUnauthorized: false
|
|
113
|
+
}
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
if (opts.caFingerprint) {
|
|
@@ -125,7 +128,7 @@ function pinoElasticSearch(opts = {}) {
|
|
|
125
128
|
const client = new Client(clientOpts)
|
|
126
129
|
console.log("Logging to elasticsearch...");
|
|
127
130
|
console.log("Any line showing up here means that the line was not logged to elasticsearch.");
|
|
128
|
-
client.on('resurrect', () => {
|
|
131
|
+
client.diagnostic.on('resurrect', () => {
|
|
129
132
|
initializeBulkHandler(opts, client, splitter)
|
|
130
133
|
})
|
|
131
134
|
|
|
@@ -145,6 +148,7 @@ function start(opts) {
|
|
|
145
148
|
console.error('Elasticsearch client error:', error)
|
|
146
149
|
})
|
|
147
150
|
stream.on('insertError', (error) => {
|
|
151
|
+
console.log(JSON.stringify(error))
|
|
148
152
|
console.error('Elasticsearch server error:', error)
|
|
149
153
|
})
|
|
150
154
|
|
|
@@ -160,8 +164,9 @@ if (require.main === module) {
|
|
|
160
164
|
username: process.env.LOG_ES_USER || 'elastic',
|
|
161
165
|
password: process.env.LOG_ES_PASS || 'changeme'
|
|
162
166
|
},
|
|
163
|
-
index: process.env.LOG_ES_INDEX || '
|
|
167
|
+
index: process.env.LOG_ES_INDEX || 'DJP-%{DATE}',
|
|
164
168
|
flushBytes: process.env.LOG_ES_FLUSH_BYTES ? parseInt(process.env.LOG_ES_FLUSH_BYTES) : undefined,
|
|
165
|
-
|
|
169
|
+
flushInterval: process.env.LOG_ES_FLUSH_INTERVAL ? parseInt(process.env.LOG_ES_FLUSH_INTERVAL) : undefined,
|
|
170
|
+
rejectUnauthorized: process.env.LOG_ES_REJECT_UNAUTHORIZED === 'true' ? true : false,
|
|
166
171
|
})
|
|
167
172
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditjenpajakri/elasticsearch-logging",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Elasticsearch ",
|
|
5
5
|
"main": "lib.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@elastic/elasticsearch": "
|
|
19
|
+
"@elastic/elasticsearch": "8",
|
|
20
20
|
"pump": "^3.0.0",
|
|
21
21
|
"split2": "^4.2.0"
|
|
22
22
|
},
|