-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a logger. Fix UniFi error messages. Implemented additiona…
…l UniFi logging
- Loading branch information
1 parent
a0a3933
commit 88fbf7c
Showing
5 changed files
with
85 additions
and
27 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,42 @@ | ||
/** | ||
* Import base packages | ||
*/ | ||
const log = require('js-logger'); | ||
|
||
/** | ||
* Check if we are using the dev version | ||
*/ | ||
const dev = process.env.NODE_ENV !== 'production'; | ||
|
||
/** | ||
* Setup logger | ||
*/ | ||
const consoleLogger = log.createDefaultHandler({ | ||
formatter: (messages, context) => { | ||
// Get current date, change this to the current timezone, then generate a date-time string | ||
const utcDate = new Date(); | ||
const offset = utcDate.getTimezoneOffset(); | ||
const date = new Date(utcDate.getTime() - (offset * 60 * 1000)); | ||
const dateTimeString = date.toISOString().replace('T', ' ').replace('Z', ''); | ||
|
||
// Prefix each log message with a timestamp and log level | ||
messages.unshift(`${dateTimeString} ${context.level.name}${context.level.name === 'INFO' || context.level.name === 'WARN' ? ' ' : ''}`); | ||
} | ||
}); | ||
|
||
/** | ||
* Set all logger handlers | ||
*/ | ||
log.setHandler((messages, context) => { | ||
consoleLogger(messages, context); | ||
}); | ||
|
||
/** | ||
* Set log level | ||
*/ | ||
log.setLevel(dev ? log.TRACE : log.INFO); | ||
|
||
/** | ||
* Export the application logger | ||
*/ | ||
module.exports = log; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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