Skip to content

Commit

Permalink
feat: support log to file
Browse files Browse the repository at this point in the history
and delay the root command initialization
  • Loading branch information
e-cloud committed Sep 19, 2016
1 parent 3b2a59b commit 326941a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions base/brickyard-cli.js
Expand Up @@ -6,10 +6,10 @@ const Liftoff = require('liftoff')
const Command = require('commander').Command
const packageInfo = require('../package.json')
const butil = require('../lib/util')
const logger = require('../lib/logger')
const _ = require('lodash')

const rootCmd = initRootCmd(packageInfo)

boot(rootCmd.opts())
boot(require('minimist')(process.argv.slice(2)))

/**
* boot up the whole command app
Expand All @@ -28,6 +28,18 @@ function boot(argv) {
v8flags: ['--harmony']
})

if (argv.backlog) {
let logPath = _.isBoolean(argv.backlog) ? 'logs/build.log' : argv.backlog

logger.configure({
appenders: [
{ type: 'console' },
{ type: 'file', filename: logPath, maxLogSize: 1000000, backups: 10 }
],
replaceConsole: true
})
}

app.launch({
configPath: argv.config
}, env => {
Expand All @@ -39,6 +51,8 @@ function boot(argv) {
brickyard.setLogLevel(argv.loglevel)
}

const rootCmd = initRootCmd(packageInfo)

brickyard.cli.load(rootCmd, env.configPath ? require(env.configPath).commands : null)
.spread((cmdName, options) => {
const cmdOptions = butil.assignWithValid({}, options, rootCmd.opts())
Expand Down Expand Up @@ -72,6 +86,7 @@ function initRootCmd(pkgInfo) {
.usage('[cmd] [options]')
.option('--config <path>', 'config path')
.option('--no-color', 'output without color')
.option('--backlog [dir]', 'output without color')
.option('--loglevel <level>', 'output log verbosity. Available levels are: trace,debug,info,warn,error,fatal')
.option('-V, --verbose', 'output log verbosely. Same as debug level. Prior to loglevel argument', Boolean, false)

Expand Down

0 comments on commit 326941a

Please sign in to comment.