balena-cli/lib/utils/logging.coffee
Cameron Diver 3ff5880ae3
Allow resin-cli deploy to also upload build logs if present
If build is ran through `resin deploy`, then logs will be stored and
uploaded to the database, where the dashboard can display them

Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
2017-05-04 13:11:50 +01:00

46 lines
1.3 KiB
CoffeeScript

eol = require('os').EOL
exports.getLogStreams = ->
{ StreamLogger } = require('resin-stream-logger')
colors = require('colors')
_ = require('lodash')
logger = new StreamLogger()
logger.addPrefix('build', colors.blue('[Build]'))
logger.addPrefix('info', colors.cyan('[Info]'))
logger.addPrefix('debug', colors.magenta('[Debug]'))
logger.addPrefix('success', colors.green('[Success]'))
logger.addPrefix('warn', colors.yellow('[Warn]'))
logger.addPrefix('error', colors.red('[Error]'))
streams =
build: logger.createLogStream('build'),
info: logger.createLogStream('info'),
debug: logger.createLogStream('debug'),
success: logger.createLogStream('success'),
warn: logger.createLogStream('warn'),
error: logger.createLogStream('error')
_.mapKeys streams, (stream, key) ->
if key isnt 'debug'
stream.pipe(process.stdout)
else
stream.pipe(process.stdout) if process.env.DEBUG?
streams
exports.logInfo = (logStreams, msg) ->
logStreams.info.write(msg + eol)
exports.logDebug = (logStreams, msg) ->
logStreams.debug.write(msg + eol)
exports.logSuccess = (logStreams, msg) ->
logStreams.success.write(msg + eol)
exports.logWarn = (logStreams, msg) ->
logStreams.warn.write(msg + eol)
exports.logError = (logStreams, msg) ->
logStreams.error.write(msg + eol)