diff --git a/src/consola.js b/src/consola.js index 95dd85e3..25b830e9 100644 --- a/src/consola.js +++ b/src/consola.js @@ -1,4 +1,5 @@ import defaultTypes from './types' +import { assignToLogObj } from './utils' export default class Consola { constructor (options = {}) { @@ -67,15 +68,13 @@ export default class Consola { logObj.message = [arg1, arg2].concat(args).join(' ') } else { // [str] [obj?] - if (typeof arg2 === 'object') { - Object.assign(logObj, arg2) - } + assignToLogObj(logObj, arg2) logObj.message = arg1 } } else { // [obj] if (typeof arg1 === 'object') { - Object.assign(logObj, arg1) + assignToLogObj(logObj, arg1) } } diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 00000000..7e819b2c --- /dev/null +++ b/src/utils.js @@ -0,0 +1,13 @@ +const VALID_LOGOBJ_KEYS = [ + 'message', 'date', 'scope', + 'clear', 'badge', 'additional', 'stack', 'additionalStyle', 'icon' +] + +export function assignToLogObj (logObj, obj) { + for (const key of VALID_LOGOBJ_KEYS) { + const val = obj[key] + if (typeof val !== 'undefined') { + logObj[key] = val + } + } +}