Skip to content

Commit

Permalink
feat(config): make the logging configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeltour committed Dec 13, 2017
1 parent f63e1a5 commit 5a3e4a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/ace-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"env-paths": "^1.0.0",
"@daisy/ace-config": "^0.0.1",
"fs-extra": "^4.0.2",
"winston": "^2.4.0"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/ace-logger/src/defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"logging": {
"level": "info",
"fileName": "ace.log"
}
}
13 changes: 7 additions & 6 deletions packages/ace-logger/src/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
'use strict';

const envPaths = require('env-paths');
const { config, paths } = require('@daisy/ace-config');
const fs = require('fs-extra');
const path = require('path');
const winston = require('winston');
const defaults = require('./defaults');

const acePaths = envPaths('DAISY Ace', { suffix: null });
const logConfig = config.get('logging', defaults.logging);

module.exports.initLogger = function initLogger(options = {}) {
// Check logging directoy exists
if (!fs.existsSync(acePaths.log)) {
fs.ensureDirSync(acePaths.log);
if (!fs.existsSync(paths.log)) {
fs.ensureDirSync(paths.log);
}

// OS-dependant path to log file
const logfile = path.join(acePaths.log, 'ace.log');
const logfile = path.join(paths.log, logConfig.fileName);

// clear old log file
if (fs.existsSync(logfile)) {
fs.removeSync(logfile);
}

// set up logger
const level = (options.verbose) ? 'verbose' : 'info';
const level = (options.verbose) ? 'verbose' : logConfig.level;
winston.configure({
level,
transports: [
Expand Down

0 comments on commit 5a3e4a4

Please sign in to comment.