You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When setting rotation file, it should not crash "randomly".
Current Behavior
Without knowing what happened, the logger crash. I'm using several projects with the same stack, the same Logger module but, when running during the night, some crashed and the other ones are still running (no crash of the logger).
I tried to resolve the problem and found this issue but it seems to be fixed since npm v5.4.1.
Here the report of npm doctor
λ npm doctor
npm WARN verifyCachedFiles Content garbage-collected: 1001 (35181061 bytes)
npm WARN verifyCachedFiles Cache issues have been fixed
Check Value Recommendation
npm ping OK
npm -v v5.6.0 Use npm v6.2.0
node -v v8.10.0 Use node v8.11.3
npm config get registry https://registry.npmjs.org/
which git C:\Users\ngigou\installationFolder\git\cmd\git.EXE
Perms check on cached files ok
Perms check on global node_modules ok
Perms check on local node_modules ok
Verify cache contents verified 4988 tarballs
Here two examples of the crash of the app:
# some correct logs here...
14:55:06.323Z INFO project_name: Database:: checkAuthToDb:: models synchronized successfully
# some hours later...
events.js:183
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, unlink 'C:\Users\ngigou\dev\apps\project_name\logs\project_name-error-2018-07-17.log'
00:00:00.423Z INFO project_name: Server index:: Closing connection with the server...
[nodemon] app crashed - waiting for file changes before starting...
or even (small difference, stat instead of unlink)
# some correct logs here...
14:55:06.323Z INFO project_name: Database:: checkAuthToDb:: models synchronized successfully
# some hours later...
events.js:183
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, stat 'C:\Users\ngigou\dev\apps\project_name\logs\project_name-error-2018-07-17.log'
00:00:00.423Z INFO project_name: Server index:: Closing connection with the server...
[nodemon] app crashed - waiting for file changes before starting...
Possible Solution
Could it be a asynchronous issue when trying to rotate files?
Some logs from previous days aren't zipped but some are (the days concerned by the crash), compression issue?
Seen this issue but I really need to have two different files, is it impossible to split streams to different depending on the criticity?
Code
The Logger is imported as a node module (-> parentConfigPath) but can be run locally, without parent project (for dev usage).
importloggerfrom'my-logger-name'
lib/Logger.js
importbunyanfrom'bunyan'importpathfrom'path'importRotatingFileStreamfrom'bunyan-rotating-file-stream'constprefix='Logger::'constparentConfigPath='../../../../config/config'constlocalConfigPath='../../config/config'classLogger{/** * @description Construct a Logger. * @see https://www.npmjs.com/package/bunyan-rotating-file-stream */constructor(){this.options=this._getConfig()this.logger=bunyan.createLogger({name: this.options.LOG_FILENAME,streams: [{stream: newRotatingFileStream({path: `${this.options.LOG_FOLDER_NAME}/${this.options.LOG_FILENAME}-%Y-%m-%d.log`,period: this.options.LOG_PERIOD,totalFiles: this.options.LOG_NB_COPIES,rotateExisting: this.options.LOG_DAILY_ROTATE,threshold: this.options.LOG_MAX_SIZE,totalSize: this.options.LOG_TOTAL_SIZE,gzip: this.options.LOG_COMPRESS_OLD_LOGS}),level: this.options.LOG_LEVEL},{stream: newRotatingFileStream({path: `${this.options.LOG_FOLDER_NAME}/${this.options.LOG_ERROR_FILENAME}-%Y-%m-%d.log`,period: this.options.LOG_PERIOD,totalFiles: this.options.LOG_NB_COPIES,rotateExisting: this.options.LOG_DAILY_ROTATE,threshold: this.options.LOG_MAX_SIZE,totalSize: this.options.LOG_TOTAL_SIZE,gzip: this.options.LOG_COMPRESS_OLD_LOGS}),level: this.options.LOG_ERROR_LEVEL},{stream: process.stdout,level: this.options.LOG_LEVEL}]})}/** * @private * @description Check if the parent folder of the logger folder is node_modules/ or not. * @returns {Boolean} - True if the logger is in node_modules. False otherwise. */_hasNodeModulesAsParent(){constparentFolderName=path.resolve(__dirname,'../../..')returnparentFolderName.endsWith('node_modules')}/** * @private * @description Get the config data. * @returns {Object} - The data config caught from config files. */_getConfig(){letconfigif(this._hasNodeModulesAsParent()){config=require(parentConfigPath)}else{config=require(localConfigPath)}returnconfig}}exportdefaultnewLogger()
Seems to be resolved when using only one file instead of two. Would be better to be able to split streams within different files depending on the log level.
Still waiting to be sure it's fixed. It's not because it didn't crashed yet that it's solved.
Hi,
Expected Behavior
When setting rotation file, it should not crash "randomly".
Current Behavior
Without knowing what happened, the logger crash. I'm using several projects with the same stack, the same Logger module but, when running during the night, some crashed and the other ones are still running (no crash of the logger).
I tried to resolve the problem and found this issue but it seems to be fixed since npm v5.4.1.
Here the report of
npm doctor
Here two examples of the crash of the app:
or even (small difference,
stat
instead ofunlink
)Possible Solution
Code
The Logger is imported as a node module (-> parentConfigPath) but can be run locally, without parent project (for dev usage).
lib/Logger.js
config/config.js
Context (Environment)
package-lock.json
@Rcomian
Thanks
The text was updated successfully, but these errors were encountered: