[local-sync] 🎨 logger

If the first argument to our local-sync logger is an object
(this is bunyan's api, and it's how we log from isomorphic-core and cloud-* packages
in order to have structured json logs for logstash), make sure we log
the object last and the string that comes as the second argument first.
This commit is contained in:
Juan Tejada 2017-02-08 18:24:35 -08:00
parent 2eeae66b2d
commit 9a3470bacb
2 changed files with 9 additions and 5 deletions

View file

@ -88,6 +88,6 @@ server.register(plugins, (err) => {
server.start((startErr) => {
if (startErr) { throw startErr; }
global.Logger.info({url: server.info.uri}, 'API running');
global.Logger.log('API running', {url: server.info.uri});
});
});

View file

@ -38,23 +38,27 @@ function Logger(boundArgs = {}) {
loggerFns.forEach((logFn) => {
logger[logFn] = (...args) => {
if (!ENABLE_LOGGING && logFn !== "error") {
return () => {}
return
}
const {accountId, accountEmail, ...otherArgs} = boundArgs
const prefix = accountEmail || accountId
const suffix = !_.isEmpty(otherArgs) ? otherArgs : '';
let [first, ...extraArgs] = args
if (_.isObject(first)) {
[first, extraArgs] = [extraArgs, [first]]
}
if (prefix) {
const color = getColorForPrefix(prefix)
const [first, ...extraArgs] = args
return console[logFn](
console[logFn](
`%c<${prefix}> %c${first}`,
`color: ${color}`,
`color: #333333`,
...extraArgs,
suffix
)
return
}
return console[logFn](...args, suffix)
console[logFn](`${first}`, ...extraArgs, suffix)
}
})
logger.child = (extraBoundArgs) => Logger({...boundArgs, ...extraBoundArgs})