-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from innomaxx/master
Custom logger instead of built-in console methods, fix #43
- Loading branch information
Showing
9 changed files
with
64 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import createDebug from 'debug'; | ||
|
||
const log = createDebug('nanoexpress:log'); | ||
log.namespace = `[${log.namespace}]`; | ||
log.color = 2; | ||
|
||
const error = createDebug('nanoexpress:error'); | ||
error.namespace = `[${error.namespace}]`; | ||
error.color = 1; | ||
|
||
// Environment checks | ||
if (!process.env.DEBUG) { | ||
// DEBUG passed -> default library flow | ||
// DEBUG not passed -> check own directive | ||
if (process.env.NANOEXPRESS_LOGGING) { | ||
// Extract logging levels | ||
const levels = process.env.NANOEXPRESS_LOGGING.split(','); | ||
// Enable whitelisted levels | ||
log.enabled = levels.includes('log'); | ||
error.enabled = levels.includes('error'); | ||
} else { | ||
// Development environment -> enable all | ||
log.enabled = error.enabled = process.env.NODE_ENV === 'development'; | ||
} | ||
} | ||
|
||
export default { log, 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
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
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
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