Skip to content

Commit

Permalink
different log format for browser/node
Browse files Browse the repository at this point in the history
  • Loading branch information
harshjv committed Apr 10, 2019
1 parent 7b645fc commit 8d24181
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Debug.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import debug from 'debug'
debug.useColors = () => false

function isBrowser () {
return typeof process === 'undefined' ||
process.type === 'renderer' ||
process.browser === true ||
process.__nwjs
}

export default (namespace, type = 'log') => {
namespace = `liquality:cal:${namespace}`
const obj = debug(namespace)

obj.log = (...args) => {
const arr = args[0].split(' ')
const time = arr.shift()
arr.shift() // remove namespace
args[0] = arr.join(' ')
const arg0 = arr[isBrowser() ? 1 : 2]

args.shift()
args = [ arg0, ...args ]

let stack = false

Expand All @@ -31,13 +39,14 @@ export default (namespace, type = 'log') => {

console.history.push({
type,
time,
time: new Date().toISOString(),
namespace,
args,
stack
})

console[type].apply(console, args)
/* eslint-disable-next-line no-useless-call */
console[type].apply(console, [ namespace, ...args ])
}

return obj
Expand Down

0 comments on commit 8d24181

Please sign in to comment.