Skip to content

Commit

Permalink
Refactor examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 15, 2017
1 parent a6b6ec8 commit 0de11aa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 49 deletions.
56 changes: 21 additions & 35 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,63 @@
'use strict'

require('date-utils')
var Acho = require('..')
var setDateout = require('set-dateout')
const acho = require('..')
const setDateout = require('set-dateout')

var base = Acho({})
const base = acho({})

var diff = Acho({
const diff = acho({
diff: true
})

var label = Acho({
const label = acho({
align: false,
keyword: 'worker#1'
})

var production = Acho({
color: false,
align: false
const visit = acho({
types: require('acho-skin-cli'),
keyword: 'symbol'
})

var visit = Acho({
keyword: 'visit'
const log = acho({
keyword: 'log'
})

var getStep = (function () {
var start = 0
const getStep = (function () {
let start = 0
return function (value) {
if (value) start += value
else ++start
return start
}
})()

var messageTimeout = (function () {
const messageTimeout = (function () {
return function (level, message, logger, time) {
setDateout(function () {
logger[level](message)
}, new Date().add({seconds: getStep(0.8)}))
}
})()

var lineBreakTimeout = (function () {
const lineBreakTimeout = (function () {
return function (time) {
setDateout(function () {
console.log()
}, new Date().add({seconds: getStep(time || 0.2)}))
}
})()

messageTimeout('info', 'Hackable', base)
messageTimeout('debug', 'Logging', base)
messageTimeout('warn', 'for NodeJS and Browser', base)
console.log()
messageTimeout('info', 'The', base)
messageTimeout('debug', 'Hackable', base)
messageTimeout('warn', 'Log', base)
messageTimeout('error', 'in less than', base)
messageTimeout('fatal', '10KB!.', base)

lineBreakTimeout(1)

messageTimeout('info', 'Do you wanna to know more?', base)

lineBreakTimeout()

messageTimeout('debug', 'support diff', diff)
messageTimeout('debug', 'between messages', diff)

Expand All @@ -71,21 +68,10 @@ messageTimeout('warn', 'easily', label)

lineBreakTimeout()

messageTimeout('error', 'automatically color and align disabled', production)
messageTimeout('error', 'under production scenario', production)

lineBreakTimeout()

messageTimeout('debug', 'and more more more...', base)

lineBreakTimeout()
messageTimeout('info', 'pretty serialization', log)

messageTimeout('debug', 'string interpolation', base)
messageTimeout('debug', 'logs align', base)
messageTimeout('info', 'custom levels and transports', base)
messageTimeout('info', 'object serialization', base)
messageTimeout('info', {foo: 'bar', hello: 'world'}, base)
messageTimeout('info', { foo: 'bar', hello: 'world' }, log)

lineBreakTimeout()

messageTimeout('debug', 'https://github.com/Kikobeats/acho', visit)
messageTimeout('success', 'See more at https://github.com/Kikobeats/acho', visit)
20 changes: 12 additions & 8 deletions examples/interpolation.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
'use strict'

var Acho = require('..')
var acho = Acho()
const acho = require('..')
const log = acho()

acho.info('formatting plain text: hello world')
acho.info('formatting with number interpolation %d', 123)
acho.info('formatting with float interpolation %d', 3.14)
acho.info('formatting with string interpolation %s', 'hello world')
acho.info('formatting with object interpolation %j', {hello: 'world', foo: 'bar'})
console.log()

acho.info('formatting with object interpolation %J', {
log.info('format text', 'hello world')
log.info('format number interpolation %d', 123)
log.info('format float interpolation %d', 3.14)
log.info('format string interpolation %s', 'hello world')
log.info('format object interpolation %j', {
hello: 'world', foo: 'bar'
})

log.info('format beauty object interpolation %J', {
hello: 'world',
foo: 'bar',
deep: {
Expand Down
12 changes: 6 additions & 6 deletions examples/levels.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'use strict'

var Acho = require('..')
var acho = Acho({
const Acho = require('..')
const acho = Acho({
diff: true,
timestamp: 1000,
upperCase: true,
// upperCase: true,
context: 'generated'
// keyword: 'symbol'
})

var levels = Object.keys(acho.types)
const levels = Object.keys(acho.types)

var fixtureObj = {
const fixtureObj = {
foo: 'bar',
hello: 'world'
}

var fixtureArr = [1, 2, 3, 4, 5]
const fixtureArr = [1, 2, 3, 4, 5]

acho.debug('%j', fixtureObj)
acho.debug(fixtureObj)
Expand Down

0 comments on commit 0de11aa

Please sign in to comment.