-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Logger. Update menu transform option
- Loading branch information
Paul Varache
committed
Mar 8, 2018
1 parent
0ac76ab
commit ea2de65
Showing
8 changed files
with
293 additions
and
39 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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const Shell = require('./shell'); | ||
const ShellMenu = require('./menu'); | ||
const Logger = require('./logger'); | ||
|
||
module.exports = { | ||
Shell, | ||
ShellMenu, | ||
Logger, | ||
}; |
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,73 @@ | ||
const path = require('path'); | ||
const bunyan = require('bunyan'); | ||
const bunyanDebugStream = require('bunyan-debug-stream'); | ||
const { app } = require('electron'); | ||
|
||
const loggers = new Map(); | ||
|
||
const defaultOptions = { | ||
level: 'info', | ||
file: { | ||
level: 'warn', | ||
period: '1d', | ||
count: 7, | ||
}, | ||
devMode: { | ||
level: 'debug', | ||
file: { | ||
level: 'debug', | ||
}, | ||
}, | ||
}; | ||
|
||
const Logger = { | ||
getLogger(opts, name = null) { | ||
const loggerName = name || app.getName(); | ||
const fileOptions = Object.assign({}, defaultOptions.file, opts.file || {}); | ||
const options = Object.assign({}, defaultOptions, opts); | ||
if (!loggers.has(loggerName)) { | ||
const streams = [{ | ||
level: options.level, | ||
type: 'raw', | ||
stream: bunyanDebugStream(), | ||
name: 'stream', | ||
}]; | ||
// Setting the file property to false will disable it | ||
if (opts.file !== false) { | ||
streams.push({ | ||
level: fileOptions.level, | ||
type: 'rotating-file', | ||
path: path.join(app.getPath('userData'), `${loggerName}.log`), | ||
name: 'file', | ||
period: fileOptions.period, | ||
count: fileOptions.count, | ||
}); | ||
} | ||
const logger = bunyan.createLogger({ | ||
name: loggerName, | ||
streams, | ||
serializers: bunyanDebugStream.serializers, | ||
}); | ||
loggers.set(loggerName, logger); | ||
} | ||
return loggers.get(loggerName); | ||
}, | ||
enableDevMode(opts, name = null) { | ||
const loggerName = name || app.getName(); | ||
if (!loggers.has(loggerName)) { | ||
return; | ||
} | ||
const level = opts.devMode | ||
&& opts.devMode.level | ||
? opts.devMode.level : defaultOptions.devMode.level; | ||
const fileLevel = opts.devMode | ||
&& opts.devMode.file | ||
&& opts.devMode.file.level | ||
? opts.devMode.file.level : defaultOptions.devMode.file.level; | ||
const logger = loggers.get(loggerName); | ||
logger.levels('stream', level); | ||
logger.levels('file', fileLevel); | ||
}, | ||
}; | ||
|
||
module.exports = Logger; |
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
Oops, something went wrong.