-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reload loggers after rotating (#5)
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = agent => { | ||
// reload logger to new fd after rotating | ||
agent.messenger.on('log-reload', () => { | ||
agent.loggers.reload('got log-reload message'); | ||
agent.coreLogger.info('[egg-logrotator] agent logger reload: got log-reload message'); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
// reload logger to new fd after rotating | ||
app.messenger.on('log-reload', () => { | ||
app.loggers.reload('got log-reload message'); | ||
app.coreLogger.info('[egg-logrotator] app logger reload: got log-reload message'); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = agent => { | ||
agent.coreLogger.warn('agent warn'); | ||
agent.coreLogger.error('agent error'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
|
||
module.exports = app => { | ||
app.get('/log', function* () { | ||
this.logger.warn('%s %s', this.method, this.path); | ||
this.logger.error(new Error('error')); | ||
this.body = { | ||
method: this.method, | ||
path: this.path, | ||
}; | ||
}); | ||
|
||
app.get('/rotate', function* () { | ||
const schedule = path.join(__dirname, '../../../../app/schedule/rotate_by_file'); | ||
console.log(schedule); | ||
yield app.runSchedule(schedule); | ||
this.body = 'done'; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "logger-reload" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters