-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
archetype-react-app: Add debug logger using winston (#220)
* Add more comprehensive debug logs for problem diagnosis * Print out all configs in console scenario && add debug level * Updated verbose & debug function Minor changes & keep format with other console log Linter Updates: using spread operator instead of .apply() Update let into const Eslint Error Fixes * Code review * coed review && refactoring logging.js
- Loading branch information
Showing
15 changed files
with
97 additions
and
29 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
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
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
25 changes: 25 additions & 0 deletions
25
packages/electrode-archetype-react-app/lib/console-logger.js
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,25 @@ | ||
"use strict"; | ||
|
||
function makeConsoleLogger() { | ||
const levels = ["info", "warn", "error", "debug", "verbose"]; | ||
|
||
function log(level, params) { | ||
const args = Array.prototype.slice.call(params); | ||
args.unshift(`${level.toUpperCase()}:`); | ||
|
||
if (console[level]) { | ||
console[level].apply(console, args); // eslint-disable-line | ||
} else { | ||
console.log.apply(console, args); // eslint-disable-line | ||
} | ||
} | ||
|
||
return levels.reduce((a, l) => { | ||
a[l] = function () { | ||
log(l, arguments); | ||
}; | ||
return a; | ||
}, {}); | ||
} | ||
|
||
module.exports = makeConsoleLogger(); |
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 @@ | ||
const archetype = require("../config/archetype"); | ||
const devRequire = archetype.devRequire; | ||
|
||
const winstonLogger = require("./winston-logger"); | ||
|
||
module.exports = devRequire ? winstonLogger(devRequire("winston")) : require("./console-logger"); |
25 changes: 25 additions & 0 deletions
25
packages/electrode-archetype-react-app/lib/winston-logger.js
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,25 @@ | ||
"use strict"; | ||
|
||
const makeWinstonLogger = (winston) => { | ||
return new (winston.Logger)({ | ||
exceptionHandlers: [ | ||
new (winston.transports.File)({ | ||
filename: "archetype-exceptions.log" | ||
}) | ||
], | ||
transports: [ | ||
new (winston.transports.Console)({ | ||
level: "info", | ||
colorize: true, | ||
prettyPrint: true | ||
}), | ||
new (winston.transports.File)({ | ||
name: "archetype-debug-file", | ||
filename: "archetype-debug.log", | ||
level: "debug" | ||
}) | ||
] | ||
}); | ||
}; | ||
|
||
module.exports = makeWinstonLogger; |
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