saalogg
Advanced tools
Comparing version 0.0.1 to 0.1.1
37
index.js
@@ -7,27 +7,28 @@ | ||
let err = console.error | ||
let warn = console.warn | ||
let log = console.log | ||
const err = console.error | ||
const warn = console.warn | ||
const log = console.log | ||
// If production env, date is important. If dev, time is enough | ||
let formatFunc = process.env.NODE_ENV === 'production' | ||
? ['toISOString'] | ||
: ['toLocaleTimeString'] | ||
function printMsg (logFn, msg, color) { | ||
console.error = (...msg) => { | ||
let date = new Date()[formatFunc]().replace(/\s.*/, '') | ||
err(chalk.red('[' + date + ']'), util.format.apply(this, msg)) | ||
} | ||
// Since I'm Spanish, I find the Spanish formatting | ||
// the most clear one | ||
const now = new Date().toLocaleString('es') | ||
console.warn = (...msg) => { | ||
let date = new Date()[formatFunc]().replace(/\s.*/, '') | ||
warn(chalk.yellow('[' + date + ']'), util.format.apply(this, msg)) | ||
// If production env, date is important. If dev, time is enough | ||
const formattedDate = process.env.NODE_ENV === 'production' | ||
? now.replace(/\/[0-9]{4}/, '') | ||
: now.replace(/.* /, '') | ||
logFn( | ||
chalk[color](`[${formattedDate}]`), | ||
util.format.apply(this, msg) | ||
) | ||
} | ||
console.log = (...msg) => { | ||
let date = new Date()[formatFunc]().replace(/\s.*/, '') | ||
log(chalk.blue('[' + date + ']'), util.format.apply(this, msg)) | ||
} | ||
console.log = (...msg) => printMsg(log , msg, 'blue') | ||
console.warn = (...msg) => printMsg(warn, msg, 'yellow') | ||
console.error = (...msg) => printMsg(err , msg, 'red') | ||
loaded = true | ||
} | ||
{ | ||
"name": "saalogg", | ||
"version": "0.0.1", | ||
"version": "0.1.1", | ||
"description": "Just a simple logging tool", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Saalogg | ||
*Just a simple looging tool* | ||
###What this is about | ||
### What this is about | ||
I just wanted to play a bit with the console object, and overwrite it | ||
@@ -14,3 +14,3 @@ to log a timestamp with different colours regarding the function used. | ||
###LICENSE | ||
### LICENSE | ||
MIT |
@@ -12,7 +12,7 @@ const expect = require('chai').expect | ||
}) | ||
it('logs objects', () => { | ||
console.log({a:1, b: 2, c: {c: 3}}) | ||
}) | ||
it('logs variables', () => { | ||
@@ -26,8 +26,8 @@ let myStr = 'This is dog' | ||
}) | ||
it('logs errors', () => { | ||
console.error('This is an error') | ||
}) | ||
}) | ||
Sorry, the diff of this file is not supported yet
2491