@contrast/agent 4.32.11 → 4.32.12
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/node_modules/file-stream-rotator/FileStreamRotator.js +200 -41
- package/node_modules/file-stream-rotator/LICENSE.txt +17 -0
- package/node_modules/file-stream-rotator/README.md +16 -1
- package/node_modules/file-stream-rotator/package.json +5 -5
- package/node_modules/file-stream-rotator/tests/every-minute-test.js +32 -15
- package/node_modules/file-stream-rotator/tests/every-second-test.js +16 -7
- package/node_modules/file-stream-rotator/tests/large-test.js +33 -0
- package/node_modules/file-stream-rotator/tests/rotate-on-size-without-date.js +103 -0
- package/node_modules/object-hash/dist/object_hash.js +1 -2
- package/node_modules/object-hash/index.js +33 -21
- package/node_modules/object-hash/package.json +20 -18
- package/node_modules/object-hash/readme.markdown +20 -5
- package/node_modules/winston-daily-rotate-file/README.md +81 -12
- package/node_modules/winston-daily-rotate-file/daily-rotate-file.js +69 -30
- package/node_modules/winston-daily-rotate-file/index.d.ts +119 -72
- package/node_modules/winston-daily-rotate-file/package.json +20 -19
- package/node_modules/winston-transport/.eslintrc +1 -1
- package/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -1
- package/node_modules/winston-transport/CHANGELOG.md +11 -0
- package/node_modules/winston-transport/dist/index.js +2 -2
- package/node_modules/winston-transport/index.d.ts +2 -0
- package/node_modules/winston-transport/index.js +2 -2
- package/node_modules/winston-transport/node_modules/readable-stream/README.md +106 -0
- package/node_modules/winston-transport/node_modules/readable-stream/errors-browser.js +127 -0
- package/node_modules/winston-transport/node_modules/readable-stream/errors.js +116 -0
- package/node_modules/winston-transport/node_modules/readable-stream/experimentalWarning.js +17 -0
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_duplex.js +41 -46
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_passthrough.js +1 -11
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_readable.js +271 -263
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_transform.js +18 -42
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_writable.js +101 -147
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
- package/node_modules/winston-transport/node_modules/readable-stream/package.json +72 -0
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/readable-browser.js +2 -0
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/readable.js +5 -8
- package/node_modules/winston-transport/package.json +16 -14
- package/package.json +6 -6
- package/node_modules/colors/LICENSE +0 -25
- package/node_modules/colors/README.md +0 -221
- package/node_modules/colors/examples/normal-usage.js +0 -82
- package/node_modules/colors/examples/safe-string.js +0 -79
- package/node_modules/colors/index.d.ts +0 -136
- package/node_modules/colors/lib/colors.js +0 -211
- package/node_modules/colors/lib/custom/trap.js +0 -46
- package/node_modules/colors/lib/custom/zalgo.js +0 -110
- package/node_modules/colors/lib/extendStringPrototype.js +0 -110
- package/node_modules/colors/lib/index.js +0 -13
- package/node_modules/colors/lib/maps/america.js +0 -10
- package/node_modules/colors/lib/maps/rainbow.js +0 -12
- package/node_modules/colors/lib/maps/random.js +0 -11
- package/node_modules/colors/lib/maps/zebra.js +0 -5
- package/node_modules/colors/lib/styles.js +0 -95
- package/node_modules/colors/lib/system/has-flag.js +0 -35
- package/node_modules/colors/lib/system/supports-colors.js +0 -151
- package/node_modules/colors/package.json +0 -49
- package/node_modules/colors/safe.d.ts +0 -48
- package/node_modules/colors/safe.js +0 -10
- package/node_modules/colors/themes/generic-logging.js +0 -12
- package/node_modules/core-util-is/LICENSE +0 -19
- package/node_modules/core-util-is/README.md +0 -3
- package/node_modules/core-util-is/float.patch +0 -604
- package/node_modules/core-util-is/lib/util.js +0 -107
- package/node_modules/core-util-is/package.json +0 -36
- package/node_modules/core-util-is/test.js +0 -68
- package/node_modules/cycle/README.md +0 -49
- package/node_modules/cycle/cycle.js +0 -170
- package/node_modules/cycle/package.json +0 -16
- package/node_modules/fast-safe-stringify/.travis.yml +0 -8
- package/node_modules/fast-safe-stringify/CHANGELOG.md +0 -17
- package/node_modules/fast-safe-stringify/LICENSE +0 -23
- package/node_modules/fast-safe-stringify/benchmark.js +0 -137
- package/node_modules/fast-safe-stringify/index.d.ts +0 -8
- package/node_modules/fast-safe-stringify/index.js +0 -161
- package/node_modules/fast-safe-stringify/package.json +0 -50
- package/node_modules/fast-safe-stringify/readme.md +0 -154
- package/node_modules/fast-safe-stringify/test-stable.js +0 -311
- package/node_modules/fast-safe-stringify/test.js +0 -304
- package/node_modules/isarray/.npmignore +0 -1
- package/node_modules/isarray/.travis.yml +0 -4
- package/node_modules/isarray/Makefile +0 -6
- package/node_modules/isarray/README.md +0 -60
- package/node_modules/isarray/component.json +0 -19
- package/node_modules/isarray/index.js +0 -5
- package/node_modules/isarray/package.json +0 -49
- package/node_modules/isarray/test.js +0 -20
- package/node_modules/object-hash/.jshintrc +0 -19
- package/node_modules/object-hash/.travis.yml +0 -35
- package/node_modules/object-hash/bower.json +0 -15
- package/node_modules/object-hash/dist/object_hash.js.map +0 -1
- package/node_modules/object-hash/dist/object_hash_test.js +0 -4737
- package/node_modules/object-hash/gulpfile.js +0 -97
- package/node_modules/object-hash/karma.conf.js +0 -69
- package/node_modules/object-hash/test/blob.js +0 -41
- package/node_modules/object-hash/test/index.js +0 -290
- package/node_modules/object-hash/test/object-classes.js +0 -106
- package/node_modules/object-hash/test/old-crypto.js +0 -60
- package/node_modules/object-hash/test/replacer.js +0 -36
- package/node_modules/object-hash/test/types.js +0 -174
- package/node_modules/object-hash/test/writeToStream.js +0 -27
- package/node_modules/process-nextick-args/index.js +0 -45
- package/node_modules/process-nextick-args/license.md +0 -19
- package/node_modules/process-nextick-args/package.json +0 -29
- package/node_modules/process-nextick-args/readme.md +0 -18
- package/node_modules/readable-stream/.travis.yml +0 -34
- package/node_modules/readable-stream/README.md +0 -58
- package/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +0 -60
- package/node_modules/readable-stream/duplex-browser.js +0 -1
- package/node_modules/readable-stream/duplex.js +0 -1
- package/node_modules/readable-stream/lib/internal/streams/BufferList.js +0 -79
- package/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -74
- package/node_modules/readable-stream/package.json +0 -56
- package/node_modules/readable-stream/passthrough.js +0 -1
- package/node_modules/readable-stream/transform.js +0 -1
- package/node_modules/readable-stream/writable-browser.js +0 -1
- package/node_modules/readable-stream/writable.js +0 -8
- package/node_modules/winston-compat/.gitattributes +0 -1
- package/node_modules/winston-compat/.node-version +0 -1
- package/node_modules/winston-compat/CHANGELOG.md +0 -17
- package/node_modules/winston-compat/LICENSE +0 -22
- package/node_modules/winston-compat/README.md +0 -2
- package/node_modules/winston-compat/index.js +0 -295
- package/node_modules/winston-compat/lib/transport.js +0 -135
- package/node_modules/winston-compat/node_modules/fecha/CHANGELOG.md +0 -11
- package/node_modules/winston-compat/node_modules/fecha/LICENSE +0 -22
- package/node_modules/winston-compat/node_modules/fecha/README.md +0 -259
- package/node_modules/winston-compat/node_modules/fecha/fecha.d.ts +0 -47
- package/node_modules/winston-compat/node_modules/fecha/fecha.js +0 -334
- package/node_modules/winston-compat/node_modules/fecha/fecha.min.js +0 -1
- package/node_modules/winston-compat/node_modules/fecha/package.json +0 -44
- package/node_modules/winston-compat/node_modules/logform/.babelrc +0 -3
- package/node_modules/winston-compat/node_modules/logform/.eslintrc +0 -7
- package/node_modules/winston-compat/node_modules/logform/.gitattributes +0 -1
- package/node_modules/winston-compat/node_modules/logform/.travis.yml +0 -17
- package/node_modules/winston-compat/node_modules/logform/CHANGELOG.md +0 -103
- package/node_modules/winston-compat/node_modules/logform/LICENSE +0 -21
- package/node_modules/winston-compat/node_modules/logform/README.md +0 -170
- package/node_modules/winston-compat/node_modules/logform/align.js +0 -14
- package/node_modules/winston-compat/node_modules/logform/browser.js +0 -36
- package/node_modules/winston-compat/node_modules/logform/cli.js +0 -52
- package/node_modules/winston-compat/node_modules/logform/colorize.js +0 -118
- package/node_modules/winston-compat/node_modules/logform/combine.js +0 -66
- package/node_modules/winston-compat/node_modules/logform/dist/align.js +0 -14
- package/node_modules/winston-compat/node_modules/logform/dist/browser.js +0 -37
- package/node_modules/winston-compat/node_modules/logform/dist/cli.js +0 -75
- package/node_modules/winston-compat/node_modules/logform/dist/colorize.js +0 -147
- package/node_modules/winston-compat/node_modules/logform/dist/combine.js +0 -66
- package/node_modules/winston-compat/node_modules/logform/dist/format.js +0 -69
- package/node_modules/winston-compat/node_modules/logform/dist/index.js +0 -54
- package/node_modules/winston-compat/node_modules/logform/dist/json.js +0 -27
- package/node_modules/winston-compat/node_modules/logform/dist/label.js +0 -19
- package/node_modules/winston-compat/node_modules/logform/dist/levels.js +0 -15
- package/node_modules/winston-compat/node_modules/logform/dist/logstash.js +0 -32
- package/node_modules/winston-compat/node_modules/logform/dist/metadata.js +0 -63
- package/node_modules/winston-compat/node_modules/logform/dist/ms.js +0 -18
- package/node_modules/winston-compat/node_modules/logform/dist/pad-levels.js +0 -118
- package/node_modules/winston-compat/node_modules/logform/dist/pretty-print.js +0 -20
- package/node_modules/winston-compat/node_modules/logform/dist/printf.js +0 -40
- package/node_modules/winston-compat/node_modules/logform/dist/simple.js +0 -36
- package/node_modules/winston-compat/node_modules/logform/dist/splat.js +0 -147
- package/node_modules/winston-compat/node_modules/logform/dist/timestamp.js +0 -28
- package/node_modules/winston-compat/node_modules/logform/dist/uncolorize.js +0 -31
- package/node_modules/winston-compat/node_modules/logform/examples/combine.js +0 -14
- package/node_modules/winston-compat/node_modules/logform/examples/filter.js +0 -30
- package/node_modules/winston-compat/node_modules/logform/examples/invalid.js +0 -6
- package/node_modules/winston-compat/node_modules/logform/examples/metadata.js +0 -78
- package/node_modules/winston-compat/node_modules/logform/examples/padLevels.js +0 -39
- package/node_modules/winston-compat/node_modules/logform/examples/volume.js +0 -25
- package/node_modules/winston-compat/node_modules/logform/format.js +0 -52
- package/node_modules/winston-compat/node_modules/logform/index.d.ts +0 -53
- package/node_modules/winston-compat/node_modules/logform/index.js +0 -52
- package/node_modules/winston-compat/node_modules/logform/json.js +0 -26
- package/node_modules/winston-compat/node_modules/logform/label.js +0 -19
- package/node_modules/winston-compat/node_modules/logform/levels.js +0 -12
- package/node_modules/winston-compat/node_modules/logform/logstash.js +0 -29
- package/node_modules/winston-compat/node_modules/logform/metadata.js +0 -61
- package/node_modules/winston-compat/node_modules/logform/ms.js +0 -18
- package/node_modules/winston-compat/node_modules/logform/package.json +0 -51
- package/node_modules/winston-compat/node_modules/logform/pad-levels.js +0 -83
- package/node_modules/winston-compat/node_modules/logform/pretty-print.js +0 -16
- package/node_modules/winston-compat/node_modules/logform/printf.js +0 -26
- package/node_modules/winston-compat/node_modules/logform/simple.js +0 -33
- package/node_modules/winston-compat/node_modules/logform/splat.js +0 -125
- package/node_modules/winston-compat/node_modules/logform/timestamp.js +0 -30
- package/node_modules/winston-compat/node_modules/logform/tsconfig.json +0 -22
- package/node_modules/winston-compat/node_modules/logform/uncolorize.js +0 -27
- package/node_modules/winston-compat/package.json +0 -46
- package/node_modules/winston-compat/test/clone.test.js +0 -25
- package/node_modules/winston-compat/test/helpers.js +0 -256
- package/node_modules/winston-compat/test/timestamp.test.js +0 -14
- package/node_modules/winston-compat/test/transports/transport.js +0 -205
- package/node_modules/winston-compat/test/winston-compat.test.js +0 -18
- package/node_modules/winston-daily-rotate-file/.eslintrc.js +0 -11
- package/node_modules/winston-daily-rotate-file/.node-version +0 -1
- package/node_modules/winston-daily-rotate-file/.travis.yml +0 -15
- package/node_modules/winston-daily-rotate-file/node_modules/semver/CHANGELOG.md +0 -70
- package/node_modules/winston-daily-rotate-file/node_modules/semver/LICENSE +0 -15
- package/node_modules/winston-daily-rotate-file/node_modules/semver/README.md +0 -443
- package/node_modules/winston-daily-rotate-file/node_modules/semver/bin/semver.js +0 -174
- package/node_modules/winston-daily-rotate-file/node_modules/semver/package.json +0 -32
- package/node_modules/winston-daily-rotate-file/node_modules/semver/range.bnf +0 -16
- package/node_modules/winston-daily-rotate-file/node_modules/semver/semver.js +0 -1596
- package/node_modules/winston-daily-rotate-file/test/memory-stream.js +0 -38
- package/node_modules/winston-daily-rotate-file/test/random-string.js +0 -31
- package/node_modules/winston-daily-rotate-file/test/transport-tests.js +0 -250
- package/node_modules/winston-transport/.nyc_output/1c69f3e4-4c25-457d-9df5-dfa761729528.json +0 -1
- package/node_modules/winston-transport/.nyc_output/processinfo/1c69f3e4-4c25-457d-9df5-dfa761729528.json +0 -1
- package/node_modules/winston-transport/.travis.yml +0 -17
- package/node_modules/winston-transport/tsconfig.json +0 -22
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/CONTRIBUTING.md +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/GOVERNANCE.md +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/LICENSE +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/internal/streams/stream-browser.js +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/internal/streams/stream.js +0 -0
|
@@ -49,6 +49,19 @@ var EventEmitter = require('events');
|
|
|
49
49
|
*
|
|
50
50
|
* - `file_options` An object passed to the stream. This can be used to specify flags, encoding, and mode.
|
|
51
51
|
* See https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options. Default `{ flags: 'a' }`.
|
|
52
|
+
*
|
|
53
|
+
* - `utc` Use UTC time for date in filename. Defaults to 'FALSE'
|
|
54
|
+
*
|
|
55
|
+
* - `extension` File extension to be appended to the filename. This is useful when using size restrictions as the rotation
|
|
56
|
+
* adds a count (1,2,3,4,...) at the end of the filename when the required size is met.
|
|
57
|
+
*
|
|
58
|
+
* - `watch_log` Watch the current file being written to and recreate it in case of accidental deletion. Defaults to 'FALSE'
|
|
59
|
+
*
|
|
60
|
+
* - `create_symlink` Create a tailable symlink to the current active log file. Defaults to 'FALSE'
|
|
61
|
+
*
|
|
62
|
+
* - `symlink_name` Name to use when creating the symbolic link. Defaults to 'current.log'
|
|
63
|
+
*
|
|
64
|
+
* - `audit_hash_type` Use specified hashing algorithm for audit. Defaults to 'md5'. Use 'sha256' for FIPS compliance.
|
|
52
65
|
*
|
|
53
66
|
* To use with Express / Connect, use as below.
|
|
54
67
|
*
|
|
@@ -117,7 +130,7 @@ var _checkDailyAndTest = function (freqType) {
|
|
|
117
130
|
* @returns {*}
|
|
118
131
|
*/
|
|
119
132
|
FileStreamRotator.getFrequency = function (frequency) {
|
|
120
|
-
var _f = frequency.toLowerCase().match(/^(\d+)([
|
|
133
|
+
var _f = frequency.toLowerCase().match(/^(\d+)([mh])$/)
|
|
121
134
|
if(_f){
|
|
122
135
|
return _checkNumAndType(_f[2], parseInt(_f[1]));
|
|
123
136
|
}
|
|
@@ -137,7 +150,7 @@ FileStreamRotator.getFrequency = function (frequency) {
|
|
|
137
150
|
*/
|
|
138
151
|
FileStreamRotator.parseFileSize = function (size) {
|
|
139
152
|
if(size && typeof size == "string"){
|
|
140
|
-
var _s = size.toLowerCase().match(/^((?:0\.)?\d+)([
|
|
153
|
+
var _s = size.toLowerCase().match(/^((?:0\.)?\d+)([kmg])$/);
|
|
141
154
|
if(_s){
|
|
142
155
|
switch(_s[2]){
|
|
143
156
|
case 'k':
|
|
@@ -156,27 +169,29 @@ FileStreamRotator.parseFileSize = function (size) {
|
|
|
156
169
|
* Returns date string for a given format / date_format
|
|
157
170
|
* @param format
|
|
158
171
|
* @param date_format
|
|
172
|
+
* @param {boolean} utc
|
|
159
173
|
* @returns {string}
|
|
160
174
|
*/
|
|
161
|
-
FileStreamRotator.getDate = function (format, date_format) {
|
|
175
|
+
FileStreamRotator.getDate = function (format, date_format, utc) {
|
|
162
176
|
date_format = date_format || DATE_FORMAT;
|
|
177
|
+
let currentMoment = utc ? moment.utc() : moment().local()
|
|
163
178
|
if (format && staticFrequency.indexOf(format.type) !== -1) {
|
|
164
179
|
switch (format.type) {
|
|
165
180
|
case 'm':
|
|
166
|
-
var minute = Math.floor(
|
|
167
|
-
return
|
|
181
|
+
var minute = Math.floor(currentMoment.minutes() / format.digit) * format.digit;
|
|
182
|
+
return currentMoment.minutes(minute).format(date_format);
|
|
168
183
|
break;
|
|
169
184
|
case 'h':
|
|
170
|
-
var hour = Math.floor(
|
|
171
|
-
return
|
|
185
|
+
var hour = Math.floor(currentMoment.hour() / format.digit) * format.digit;
|
|
186
|
+
return currentMoment.hour(hour).format(date_format);
|
|
172
187
|
break;
|
|
173
188
|
case 'daily':
|
|
174
189
|
case 'custom':
|
|
175
190
|
case 'test':
|
|
176
|
-
return
|
|
191
|
+
return currentMoment.format(date_format);
|
|
177
192
|
}
|
|
178
193
|
}
|
|
179
|
-
return
|
|
194
|
+
return currentMoment.format(date_format);
|
|
180
195
|
}
|
|
181
196
|
|
|
182
197
|
/**
|
|
@@ -190,6 +205,7 @@ FileStreamRotator.getDate = function (format, date_format) {
|
|
|
190
205
|
* @property {Number} auditLogSettings.keep.amount
|
|
191
206
|
* @property {String} auditLogSettings.auditLog
|
|
192
207
|
* @property {Array} auditLogSettings.files
|
|
208
|
+
* @property {String} auditLogSettings.hashType
|
|
193
209
|
*/
|
|
194
210
|
FileStreamRotator.setAuditLog = function (max_logs, audit_file, log_file){
|
|
195
211
|
var _rtn = null;
|
|
@@ -239,13 +255,17 @@ FileStreamRotator.setAuditLog = function (max_logs, audit_file, log_file){
|
|
|
239
255
|
* @param {Number} audit.keep.amount
|
|
240
256
|
* @param {String} audit.auditLog
|
|
241
257
|
* @param {Array} audit.files
|
|
258
|
+
* @param {String} audit.hashType
|
|
259
|
+
* @param {Boolean} verbose
|
|
242
260
|
*/
|
|
243
|
-
FileStreamRotator.writeAuditLog = function(audit){
|
|
261
|
+
FileStreamRotator.writeAuditLog = function(audit, verbose){
|
|
244
262
|
try{
|
|
245
263
|
mkDirForFile(audit.auditLog);
|
|
246
264
|
fs.writeFileSync(audit.auditLog, JSON.stringify(audit,null,4));
|
|
247
265
|
}catch(e){
|
|
248
|
-
|
|
266
|
+
if (verbose) {
|
|
267
|
+
console.error(new Date(),"[FileStreamRotator] Failed to store log audit at:", audit.auditLog,"Error:", e);
|
|
268
|
+
}
|
|
249
269
|
}
|
|
250
270
|
};
|
|
251
271
|
|
|
@@ -256,19 +276,83 @@ FileStreamRotator.writeAuditLog = function(audit){
|
|
|
256
276
|
* @param file.hash
|
|
257
277
|
* @param file.name
|
|
258
278
|
* @param file.date
|
|
279
|
+
* @param file.hashType
|
|
280
|
+
* @param {Boolean} verbose
|
|
259
281
|
*/
|
|
260
|
-
function removeFile(file){
|
|
261
|
-
if(file.hash === crypto.createHash(
|
|
282
|
+
function removeFile(file, verbose){
|
|
283
|
+
if(file.hash === crypto.createHash(file.hashType).update(file.name + "LOG_FILE" + file.date).digest("hex")){
|
|
262
284
|
try{
|
|
263
285
|
if (fs.existsSync(file.name)) {
|
|
264
286
|
fs.unlinkSync(file.name);
|
|
265
287
|
}
|
|
266
288
|
}catch(e){
|
|
267
|
-
|
|
289
|
+
if (verbose) {
|
|
290
|
+
console.error(new Date(), "[FileStreamRotator] Could not remove old log file: ", file.name);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Create symbolic link to current log file
|
|
298
|
+
* @param {String} logfile
|
|
299
|
+
* @param {String} name Name to use for symbolic link
|
|
300
|
+
* @param {Boolean} verbose
|
|
301
|
+
*/
|
|
302
|
+
function createCurrentSymLink(logfile, name, verbose) {
|
|
303
|
+
let symLinkName = name || "current.log"
|
|
304
|
+
let logPath = path.dirname(logfile)
|
|
305
|
+
let logfileName = path.basename(logfile)
|
|
306
|
+
let current = logPath + "/" + symLinkName
|
|
307
|
+
try {
|
|
308
|
+
let stats = fs.lstatSync(current)
|
|
309
|
+
if(stats.isSymbolicLink()){
|
|
310
|
+
fs.unlinkSync(current)
|
|
311
|
+
fs.symlinkSync(logfileName, current)
|
|
312
|
+
}
|
|
313
|
+
} catch (err) {
|
|
314
|
+
if(err && err.code == "ENOENT") {
|
|
315
|
+
try {
|
|
316
|
+
fs.symlinkSync(logfileName, current)
|
|
317
|
+
} catch (e) {
|
|
318
|
+
if (verbose) {
|
|
319
|
+
console.error(new Date(), "[FileStreamRotator] Could not create symlink file: ", current, ' -> ', logfileName);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
268
322
|
}
|
|
269
323
|
}
|
|
270
324
|
}
|
|
271
325
|
|
|
326
|
+
/**
|
|
327
|
+
*
|
|
328
|
+
* @param {String} logfile
|
|
329
|
+
* @param {Boolean} verbose
|
|
330
|
+
* @param {function} cb
|
|
331
|
+
*/
|
|
332
|
+
function createLogWatcher(logfile, verbose, cb){
|
|
333
|
+
if(!logfile) return null
|
|
334
|
+
// console.log("Creating log watcher")
|
|
335
|
+
try {
|
|
336
|
+
let stats = fs.lstatSync(logfile)
|
|
337
|
+
return fs.watch(logfile, function(event,filename){
|
|
338
|
+
// console.log(Date(), event, filename)
|
|
339
|
+
if(event == "rename"){
|
|
340
|
+
try {
|
|
341
|
+
let stats = fs.lstatSync(logfile)
|
|
342
|
+
// console.log("STATS:", stats)
|
|
343
|
+
}catch(err){
|
|
344
|
+
// console.log("ERROR:", err)
|
|
345
|
+
cb(err,logfile)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
}catch(err){
|
|
350
|
+
if(verbose){
|
|
351
|
+
console.log(new Date(),"[FileStreamRotator] Could not add watcher for " + logfile);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
272
356
|
/**
|
|
273
357
|
* Write audit json object to disk
|
|
274
358
|
* @param {String} logfile
|
|
@@ -277,9 +361,12 @@ function removeFile(file){
|
|
|
277
361
|
* @param {Boolean} audit.keep.days
|
|
278
362
|
* @param {Number} audit.keep.amount
|
|
279
363
|
* @param {String} audit.auditLog
|
|
364
|
+
* @param {String} audit.hashType
|
|
280
365
|
* @param {Array} audit.files
|
|
366
|
+
* @param {EventEmitter} stream
|
|
367
|
+
* @param {Boolean} verbose
|
|
281
368
|
*/
|
|
282
|
-
FileStreamRotator.addLogToAudit = function(logfile, audit){
|
|
369
|
+
FileStreamRotator.addLogToAudit = function(logfile, audit, stream, verbose){
|
|
283
370
|
if(audit && audit.files){
|
|
284
371
|
// Based on contribution by @nickbug - https://github.com/nickbug
|
|
285
372
|
var index = audit.files.findIndex(function(file) {
|
|
@@ -293,7 +380,7 @@ FileStreamRotator.addLogToAudit = function(logfile, audit){
|
|
|
293
380
|
audit.files.push({
|
|
294
381
|
date: time,
|
|
295
382
|
name: logfile,
|
|
296
|
-
hash: crypto.createHash(
|
|
383
|
+
hash: crypto.createHash(audit.hashType).update(logfile + "LOG_FILE" + time).digest("hex")
|
|
297
384
|
});
|
|
298
385
|
|
|
299
386
|
if(audit.keep.days){
|
|
@@ -302,7 +389,9 @@ FileStreamRotator.addLogToAudit = function(logfile, audit){
|
|
|
302
389
|
if(file.date > oldestDate){
|
|
303
390
|
return true;
|
|
304
391
|
}
|
|
305
|
-
|
|
392
|
+
file.hashType = audit.hashType
|
|
393
|
+
removeFile(file, verbose);
|
|
394
|
+
stream.emit("logRemoved", file)
|
|
306
395
|
return false;
|
|
307
396
|
});
|
|
308
397
|
audit.files = recentFiles;
|
|
@@ -310,14 +399,16 @@ FileStreamRotator.addLogToAudit = function(logfile, audit){
|
|
|
310
399
|
var filesToKeep = audit.files.splice(-audit.keep.amount);
|
|
311
400
|
if(audit.files.length > 0){
|
|
312
401
|
audit.files.filter(function(file){
|
|
313
|
-
|
|
402
|
+
file.hashType = audit.hashType
|
|
403
|
+
removeFile(file, verbose);
|
|
404
|
+
stream.emit("logRemoved", file)
|
|
314
405
|
return false;
|
|
315
406
|
})
|
|
316
407
|
}
|
|
317
408
|
audit.files = filesToKeep;
|
|
318
409
|
}
|
|
319
410
|
|
|
320
|
-
FileStreamRotator.writeAuditLog(audit);
|
|
411
|
+
FileStreamRotator.writeAuditLog(audit, verbose);
|
|
321
412
|
}
|
|
322
413
|
|
|
323
414
|
return audit;
|
|
@@ -334,6 +425,12 @@ FileStreamRotator.addLogToAudit = function(logfile, audit){
|
|
|
334
425
|
* @param options.max_logs
|
|
335
426
|
* @param options.audit_file
|
|
336
427
|
* @param options.file_options
|
|
428
|
+
* @param options.utc
|
|
429
|
+
* @param options.extension File extension to be added at the end of the filename
|
|
430
|
+
* @param options.watch_log
|
|
431
|
+
* @param options.create_symlink
|
|
432
|
+
* @param options.symlink_name
|
|
433
|
+
* @param options.audit_hash_type Hash to be used to add to the audit log (md5, sha256)
|
|
337
434
|
* @returns {Object} stream
|
|
338
435
|
*/
|
|
339
436
|
FileStreamRotator.getStream = function (options) {
|
|
@@ -351,6 +448,11 @@ FileStreamRotator.getStream = function (options) {
|
|
|
351
448
|
}
|
|
352
449
|
|
|
353
450
|
let auditLog = self.setAuditLog(options.max_logs, options.audit_file, options.filename);
|
|
451
|
+
// Thanks to Means88 for PR.
|
|
452
|
+
if (auditLog != null) {
|
|
453
|
+
auditLog.hashType = (options.audit_hash_type !== undefined ? options.audit_hash_type : 'md5');
|
|
454
|
+
}
|
|
455
|
+
self.verbose = (options.verbose !== undefined ? options.verbose : true);
|
|
354
456
|
|
|
355
457
|
var fileSize = null;
|
|
356
458
|
var fileCount = 0;
|
|
@@ -364,8 +466,8 @@ FileStreamRotator.getStream = function (options) {
|
|
|
364
466
|
if(!options.date_format){
|
|
365
467
|
dateFormat = "YYYY-MM-DD";
|
|
366
468
|
}
|
|
367
|
-
if(moment().format(dateFormat) != moment().
|
|
368
|
-
if(
|
|
469
|
+
if(moment().format(dateFormat) != moment().endOf("day").format(dateFormat) || moment().format(dateFormat) == moment().add(1,"day").format(dateFormat)){
|
|
470
|
+
if(self.verbose){
|
|
369
471
|
console.log(new Date(),"[FileStreamRotator] Changing type to custom as date format changes more often than once a day or not every day");
|
|
370
472
|
}
|
|
371
473
|
frequencyMetaData.type = "custom";
|
|
@@ -373,18 +475,16 @@ FileStreamRotator.getStream = function (options) {
|
|
|
373
475
|
}
|
|
374
476
|
|
|
375
477
|
if (frequencyMetaData) {
|
|
376
|
-
curDate = (options.frequency ? self.getDate(frequencyMetaData,dateFormat) : "");
|
|
478
|
+
curDate = (options.frequency ? self.getDate(frequencyMetaData,dateFormat, options.utc) : "");
|
|
377
479
|
}
|
|
378
480
|
|
|
481
|
+
options.create_symlink = options.create_symlink || false;
|
|
482
|
+
options.extension = options.extension || ""
|
|
379
483
|
var filename = options.filename;
|
|
380
484
|
var oldFile = null;
|
|
381
485
|
var logfile = filename + (curDate ? "." + curDate : "");
|
|
382
486
|
if(filename.match(/%DATE%/)){
|
|
383
|
-
logfile = filename.replace(/%DATE%/g,(curDate?curDate:self.getDate(null,dateFormat)));
|
|
384
|
-
}
|
|
385
|
-
var verbose = (options.verbose !== undefined ? options.verbose : true);
|
|
386
|
-
if (verbose) {
|
|
387
|
-
console.log(new Date(),"[FileStreamRotator] Logging to: ", logfile);
|
|
487
|
+
logfile = filename.replace(/%DATE%/g,(curDate?curDate:self.getDate(null,dateFormat, options.utc)));
|
|
388
488
|
}
|
|
389
489
|
|
|
390
490
|
if(fileSize){
|
|
@@ -394,7 +494,7 @@ FileStreamRotator.getStream = function (options) {
|
|
|
394
494
|
if(auditLog && auditLog.files && auditLog.files instanceof Array && auditLog.files.length > 0){
|
|
395
495
|
var lastEntry = auditLog.files[auditLog.files.length - 1].name;
|
|
396
496
|
if(lastEntry.match(t_log)){
|
|
397
|
-
var lastCount = lastEntry.match(t_log + "\\.(\\d+)
|
|
497
|
+
var lastCount = lastEntry.match(t_log + "\\.(\\d+)");
|
|
398
498
|
// Thanks for the PR contribution from @andrefarzat - https://github.com/andrefarzat
|
|
399
499
|
if(lastCount){
|
|
400
500
|
t_log = lastEntry;
|
|
@@ -402,10 +502,15 @@ FileStreamRotator.getStream = function (options) {
|
|
|
402
502
|
}
|
|
403
503
|
}
|
|
404
504
|
}
|
|
505
|
+
|
|
506
|
+
if (fileCount == 0 && t_log == logfile) {
|
|
507
|
+
t_log += options.extension
|
|
508
|
+
}
|
|
509
|
+
|
|
405
510
|
while(f = fs.existsSync(t_log)){
|
|
406
511
|
lastLogFile = t_log;
|
|
407
512
|
fileCount++;
|
|
408
|
-
t_log = logfile + "." + fileCount;
|
|
513
|
+
t_log = logfile + "." + fileCount + options.extension;
|
|
409
514
|
}
|
|
410
515
|
if(lastLogFile){
|
|
411
516
|
var lastLogFileStats = fs.statSync(lastLogFile);
|
|
@@ -416,15 +521,21 @@ FileStreamRotator.getStream = function (options) {
|
|
|
416
521
|
}
|
|
417
522
|
}
|
|
418
523
|
logfile = t_log;
|
|
524
|
+
} else {
|
|
525
|
+
logfile += options.extension
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (self.verbose) {
|
|
529
|
+
console.log(new Date(),"[FileStreamRotator] Logging to: ", logfile);
|
|
419
530
|
}
|
|
420
531
|
|
|
421
532
|
mkDirForFile(logfile);
|
|
422
533
|
|
|
423
534
|
var file_options = options.file_options || {flags: 'a'};
|
|
424
535
|
var rotateStream = fs.createWriteStream(logfile, file_options);
|
|
425
|
-
if (curDate && frequencyMetaData && (staticFrequency.indexOf(frequencyMetaData.type) > -1)) {
|
|
426
|
-
if (verbose) {
|
|
427
|
-
console.log(new Date(),"[FileStreamRotator] Rotating file: ", frequencyMetaData.type);
|
|
536
|
+
if ((curDate && frequencyMetaData && (staticFrequency.indexOf(frequencyMetaData.type) > -1)) || fileSize > 0) {
|
|
537
|
+
if (self.verbose) {
|
|
538
|
+
console.log(new Date(),"[FileStreamRotator] Rotating file: ", frequencyMetaData?frequencyMetaData.type:"", fileSize?"size: " + fileSize:"");
|
|
428
539
|
}
|
|
429
540
|
var stream = new EventEmitter();
|
|
430
541
|
stream.auditLog = auditLog;
|
|
@@ -433,30 +544,71 @@ FileStreamRotator.getStream = function (options) {
|
|
|
433
544
|
};
|
|
434
545
|
BubbleEvents(rotateStream,stream);
|
|
435
546
|
|
|
547
|
+
stream.on('close', function(){
|
|
548
|
+
if (logWatcher) {
|
|
549
|
+
logWatcher.close()
|
|
550
|
+
}
|
|
551
|
+
})
|
|
552
|
+
|
|
436
553
|
stream.on("new",function(newLog){
|
|
437
|
-
|
|
554
|
+
// console.log("new log", newLog)
|
|
555
|
+
stream.auditLog = self.addLogToAudit(newLog,stream.auditLog, stream, self.verbose)
|
|
556
|
+
if(options.create_symlink){
|
|
557
|
+
createCurrentSymLink(newLog, options.symlink_name, self.verbose)
|
|
558
|
+
}
|
|
559
|
+
if(options.watch_log){
|
|
560
|
+
stream.emit("addWatcher", newLog)
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
var logWatcher;
|
|
565
|
+
stream.on("addWatcher", function(newLog){
|
|
566
|
+
if (logWatcher) {
|
|
567
|
+
logWatcher.close()
|
|
568
|
+
}
|
|
569
|
+
if(!options.watch_log){
|
|
570
|
+
return
|
|
571
|
+
}
|
|
572
|
+
// console.log("ADDING WATCHER", newLog)
|
|
573
|
+
logWatcher = createLogWatcher(newLog, self.verbose, function(err,newLog){
|
|
574
|
+
stream.emit('createLog', newLog)
|
|
575
|
+
})
|
|
576
|
+
})
|
|
438
577
|
|
|
578
|
+
stream.on("createLog",function(file){
|
|
579
|
+
try {
|
|
580
|
+
let stats = fs.lstatSync(file)
|
|
581
|
+
}catch(err){
|
|
582
|
+
if(rotateStream && rotateStream.end == "function"){
|
|
583
|
+
rotateStream.end();
|
|
584
|
+
}
|
|
585
|
+
rotateStream = fs.createWriteStream(file, file_options);
|
|
586
|
+
stream.emit('new',file);
|
|
587
|
+
BubbleEvents(rotateStream,stream);
|
|
588
|
+
}
|
|
439
589
|
});
|
|
440
590
|
|
|
591
|
+
|
|
441
592
|
stream.write = (function (str, encoding) {
|
|
442
|
-
var newDate = this.getDate(frequencyMetaData,dateFormat);
|
|
593
|
+
var newDate = frequencyMetaData ? this.getDate(frequencyMetaData, dateFormat, options.utc) : curDate;
|
|
443
594
|
if (newDate != curDate || (fileSize && curSize > fileSize)) {
|
|
444
|
-
var newLogfile = filename + (curDate ? "." + newDate : "");
|
|
595
|
+
var newLogfile = filename + (curDate && frequencyMetaData ? "." + newDate : "");
|
|
445
596
|
if(filename.match(/%DATE%/) && curDate){
|
|
446
597
|
newLogfile = filename.replace(/%DATE%/g,newDate);
|
|
447
598
|
}
|
|
448
599
|
|
|
449
600
|
if(fileSize && curSize > fileSize){
|
|
450
601
|
fileCount++;
|
|
451
|
-
newLogfile += "." + fileCount;
|
|
602
|
+
newLogfile += "." + fileCount + options.extension;
|
|
452
603
|
}else{
|
|
453
604
|
// reset file count
|
|
454
605
|
fileCount = 0;
|
|
606
|
+
newLogfile += options.extension
|
|
455
607
|
}
|
|
456
608
|
curSize = 0;
|
|
457
609
|
|
|
458
|
-
if (verbose) {
|
|
459
|
-
console.log(new Date(),"[FileStreamRotator] Changing logs from %s to %s", logfile, newLogfile);
|
|
610
|
+
if (self.verbose) {
|
|
611
|
+
console.log(new Date(),require('util').format("[FileStreamRotator] Changing logs from %s to %s", logfile, newLogfile));
|
|
460
612
|
}
|
|
461
613
|
curDate = newDate;
|
|
462
614
|
oldFile = logfile;
|
|
@@ -482,10 +634,11 @@ FileStreamRotator.getStream = function (options) {
|
|
|
482
634
|
process.nextTick(function(){
|
|
483
635
|
stream.emit('new',logfile);
|
|
484
636
|
})
|
|
637
|
+
stream.emit('new',logfile)
|
|
485
638
|
return stream;
|
|
486
639
|
} else {
|
|
487
|
-
if (verbose) {
|
|
488
|
-
console.log(new Date(),"[FileStreamRotator] File won't be rotated: ", options.frequency,
|
|
640
|
+
if (self.verbose) {
|
|
641
|
+
console.log(new Date(),"[FileStreamRotator] File won't be rotated: ", options.frequency, options.size);
|
|
489
642
|
}
|
|
490
643
|
process.nextTick(function(){
|
|
491
644
|
rotateStream.emit('new',logfile);
|
|
@@ -512,7 +665,13 @@ var mkDirForFile = function(pathWithFile){
|
|
|
512
665
|
// console.log("STATS ERROR",e)
|
|
513
666
|
// }
|
|
514
667
|
if (!fs.existsSync(fullPath)) {
|
|
515
|
-
|
|
668
|
+
try{
|
|
669
|
+
fs.mkdirSync(fullPath);
|
|
670
|
+
}catch(e){
|
|
671
|
+
if(e.code !== 'EEXIST'){
|
|
672
|
+
throw e;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
516
675
|
}
|
|
517
676
|
return fullPath;
|
|
518
677
|
},
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright © 2022 Roger Castells
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
5
|
+
associated documentation files (the “Software”), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
|
|
8
|
+
the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
11
|
+
portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
14
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
15
|
+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
16
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
17
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -33,7 +33,14 @@ npm install file-stream-rotator
|
|
|
33
33
|
stream in a loop, if the application terminates or log rotates, data pending to be flushed might be lost.
|
|
34
34
|
- *file_options* An object passed to the stream. This can be used to specify flags, encoding, and mode.
|
|
35
35
|
See https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options. Default `{ flags: 'a' }`.
|
|
36
|
-
|
|
36
|
+
- *utc* Use UTC time for date in filename. Defaults to 'FALSE'
|
|
37
|
+
- *extension* File extension to be appended to the filename. This is useful when using size restrictions as the rotation
|
|
38
|
+
adds a count (1,2,3,4,...) at the end of the filename when the required size is met.
|
|
39
|
+
- *watch_log* Watch the current file being written to and recreate it in case of accidental deletion. Defaults to 'FALSE'
|
|
40
|
+
- *create_symlink* Create a tailable symlink to the current active log file. Defaults to 'FALSE'
|
|
41
|
+
- *symlink_name* Name to use when creating the symbolic link. Defaults to 'current.log'
|
|
42
|
+
- *audit_hash_type* Use specified hashing algorithm for audit. Defaults to 'md5'. Use 'sha256' for FIPS compliance.
|
|
43
|
+
|
|
37
44
|
|
|
38
45
|
## Example Usage
|
|
39
46
|
```javascript
|
|
@@ -70,6 +77,13 @@ npm install file-stream-rotator
|
|
|
70
77
|
// Rotate on the hour or any specified number of hours and keep 10 days and store the audit file in /tmp/log-audit.json
|
|
71
78
|
var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/test.log", frequency:"1h", verbose: false, max_logs: "10d", audit_file: "/tmp/log-audit.json"});
|
|
72
79
|
|
|
80
|
+
// Rotate by file size only without date included in the name. Iteration will be added at the end.
|
|
81
|
+
var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/logfile", size:"50k", max_logs: "5", audit_file:"/tmp/logaudit.json"});
|
|
82
|
+
|
|
83
|
+
// Rotate by file size only without date included in the name. Rotation added before the extension.
|
|
84
|
+
var rotatingLogStream = require('file-stream-rotator').getStream({filename:"/tmp/logfile", size:"50k", max_logs: "5", audit_file:"/tmp/logaudit.json". extension: ".log"});
|
|
85
|
+
|
|
86
|
+
|
|
73
87
|
//.....
|
|
74
88
|
|
|
75
89
|
// Use new stream in express
|
|
@@ -83,6 +97,7 @@ You can listen to the *open*, *close*, *error* and *finish* events generated by
|
|
|
83
97
|
|
|
84
98
|
* *rotate*: that will pass two parameters to the callback: (*oldFilename*, *newFilename*)
|
|
85
99
|
* *new*: that will pass one parameter to the callback: *newFilename*
|
|
100
|
+
* *logRemoved*: that will pass one parameter to the callback: {*date*: unix_timestamp, *name*: filename_deleted, *hash*: log_file_unique_idenfifier}
|
|
86
101
|
|
|
87
102
|
You can also limit the size of each file by adding the size option using "k", "m" and "g" to specify the size of the file in kiloybytes, megabytes or gigabytes. When it rotates a file based on size, it will add a number to the end and increment it for every time the file rotates in the given period as shown below.
|
|
88
103
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-stream-rotator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Automated stream rotation useful for log files",
|
|
5
5
|
"main": "FileStreamRotator.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"author": "Roger Castells",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"moment": "^2.
|
|
28
|
+
"moment": "^2.29.1"
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
,"_resolved": "https://registry.npmjs.org/file-stream-rotator/-/file-stream-rotator-0.
|
|
32
|
-
,"_integrity": "sha512-
|
|
33
|
-
,"_from": "file-stream-rotator@0.
|
|
31
|
+
,"_resolved": "https://registry.npmjs.org/file-stream-rotator/-/file-stream-rotator-0.6.1.tgz"
|
|
32
|
+
,"_integrity": "sha512-u+dBid4PvZw17PmDeRcNOtCP9CCK/9lRN2w+r1xIS7yOL9JFrIBKTvrYsxT4P0pGtThYTn++QS5ChHaUov3+zQ=="
|
|
33
|
+
,"_from": "file-stream-rotator@0.6.1"
|
|
34
34
|
}
|
|
@@ -4,15 +4,24 @@ var moment = require('moment');
|
|
|
4
4
|
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"dont-rotate", verbose: true, date_format: "YYYY-MM-DD.HH.mm.ss"});
|
|
5
5
|
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"daily", verbose: true, date_format: "YYYYMMDD"});
|
|
6
6
|
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"daily", verbose: true});
|
|
7
|
+
|
|
8
|
+
const symLinkName = "tail.log"
|
|
9
|
+
|
|
7
10
|
var rotatingLogStream = require('../FileStreamRotator').getStream({
|
|
8
|
-
filename: "
|
|
11
|
+
filename: "logs/1m/testlog-%DATE%",
|
|
9
12
|
frequency: "1m",
|
|
10
13
|
verbose: true,
|
|
11
14
|
date_format: "YYYY-MM-DD.HH.mm",
|
|
12
|
-
size: "
|
|
15
|
+
size: "100k",
|
|
13
16
|
max_logs: "10",
|
|
14
17
|
audit_file: "/tmp/audit.json",
|
|
15
|
-
end_stream: false
|
|
18
|
+
end_stream: false,
|
|
19
|
+
utc: true,
|
|
20
|
+
extension: ".log",
|
|
21
|
+
create_symlink: true,
|
|
22
|
+
watch_log: true,
|
|
23
|
+
// symlink_name: "tail.log"
|
|
24
|
+
symlink_name: symLinkName
|
|
16
25
|
});
|
|
17
26
|
|
|
18
27
|
rotatingLogStream.on("error", function () {
|
|
@@ -40,29 +49,37 @@ rotatingLogStream.on("new", function (newFile) {
|
|
|
40
49
|
console.log(Date.now(), Date(), "stream new", newFile);
|
|
41
50
|
})
|
|
42
51
|
|
|
52
|
+
rotatingLogStream.on("logRemoved", function (newFile) {
|
|
53
|
+
console.log(Date.now(), Date(), "stream logRemoved", newFile);
|
|
54
|
+
})
|
|
55
|
+
|
|
43
56
|
// console.log(rotatingLogStream.on, rotatingLogStream.end, rotatingLogStream)
|
|
44
57
|
|
|
45
58
|
|
|
46
|
-
var rotatingLogStream1 = require('../FileStreamRotator').getStream({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
59
|
+
// var rotatingLogStream1 = require('../FileStreamRotator').getStream({
|
|
60
|
+
// filename: "/tmp/a/logs/1m-1/testlog-%DATE%.log",
|
|
61
|
+
// frequency: "1m",
|
|
62
|
+
// verbose: true,
|
|
63
|
+
// date_format: "YYYY-MM-DD.HH.mm",
|
|
64
|
+
// size: "50k",
|
|
65
|
+
// max_logs: "10",
|
|
66
|
+
// audit_file: "/tmp/audit-1.json",
|
|
67
|
+
// end_stream: false
|
|
68
|
+
// });
|
|
56
69
|
|
|
57
70
|
var counter = 0;
|
|
58
71
|
var i = setInterval(function () {
|
|
59
72
|
counter++;
|
|
60
73
|
rotatingLogStream.write(Date() + "\t" + "testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890\n")
|
|
61
|
-
rotatingLogStream1.write(Date() + "\t" + "testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890\n")
|
|
74
|
+
// rotatingLogStream1.write(Date() + "\t" + "testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890\n")
|
|
62
75
|
if (counter == 5000) {
|
|
63
76
|
clearInterval(i);
|
|
64
77
|
rotatingLogStream.end("end\n");
|
|
65
|
-
rotatingLogStream1.end("end\n");
|
|
78
|
+
// rotatingLogStream1.end("end\n");
|
|
66
79
|
}
|
|
67
80
|
}, 10);
|
|
68
81
|
|
|
82
|
+
// var i = setTimeout(function () {
|
|
83
|
+
// rotatingLogStream.emit("createLog")
|
|
84
|
+
// }, 10000);
|
|
85
|
+
|
|
@@ -5,18 +5,23 @@ var moment = require('moment');
|
|
|
5
5
|
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"daily", verbose: true, date_format: "YYYYMMDD"});
|
|
6
6
|
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"daily", verbose: true});
|
|
7
7
|
var rotatingLogStream = require('../FileStreamRotator').getStream({
|
|
8
|
-
filename:"
|
|
8
|
+
filename:"logs/1s/testlog-%DATE%.log",
|
|
9
9
|
frequency:"custom",
|
|
10
10
|
verbose: true,
|
|
11
11
|
date_format: "YYYY-MM-DD.HH.mm",
|
|
12
|
-
size:"50k",
|
|
12
|
+
size:"50k",
|
|
13
13
|
max_logs: "5",
|
|
14
|
-
audit_file:"
|
|
15
|
-
end_stream:
|
|
14
|
+
audit_file:"audit-1s.json",
|
|
15
|
+
end_stream: false,
|
|
16
|
+
utc: true,
|
|
17
|
+
extension: ".logs",
|
|
18
|
+
watch_log: true,
|
|
19
|
+
audit_hash_type: 'sha256'
|
|
16
20
|
});
|
|
17
21
|
|
|
18
|
-
rotatingLogStream.on("error",function(){
|
|
19
|
-
console.log(Date.now(), Date(), "stream error")
|
|
22
|
+
rotatingLogStream.on("error",function(err){
|
|
23
|
+
console.log(Date.now(), Date(), "stream error", err)
|
|
24
|
+
process.exit()
|
|
20
25
|
})
|
|
21
26
|
|
|
22
27
|
|
|
@@ -40,6 +45,10 @@ rotatingLogStream.on("new",function(newFile){
|
|
|
40
45
|
console.log(Date.now(), Date(), "stream new",newFile);
|
|
41
46
|
})
|
|
42
47
|
|
|
48
|
+
rotatingLogStream.on("addWatcher", function(newLog){
|
|
49
|
+
console.log(Date.now(), Date(), "stream add watcher",newLog);
|
|
50
|
+
})
|
|
51
|
+
|
|
43
52
|
// console.log(rotatingLogStream.on, rotatingLogStream.end, rotatingLogStream)
|
|
44
53
|
|
|
45
54
|
var counter = 0;
|
|
@@ -48,7 +57,7 @@ var i = setInterval(function(){
|
|
|
48
57
|
// rotatingLogStream.write(Date() + "\ttesting 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890\n")
|
|
49
58
|
rotatingLogStream.write(Date() + "ニューバランスの100年を超える長い歴史\n")
|
|
50
59
|
// if(counter == 2000){
|
|
51
|
-
if(counter ==
|
|
60
|
+
if(counter == 400){
|
|
52
61
|
clearInterval(i);
|
|
53
62
|
console.log(Date() + "\tEND STREAM");
|
|
54
63
|
rotatingLogStream.end("end\n");
|