Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
feat: Add emoji support
Browse files Browse the repository at this point in the history
Update readme.md
  • Loading branch information
Caio Alcantara committed Apr 10, 2019
1 parent cc79d9c commit a09f40e
Show file tree
Hide file tree
Showing 7 changed files with 5,487 additions and 19 deletions.
Binary file added .github/hoopa-logger-example-emoji.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
16 changes: 13 additions & 3 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const logger = require ('../.')
const logger = require('../.')

console.log(`With emoji\n`)
// With Emoji
logger.info('This is information!', { emoji: 'information_source' })
logger.warn('This is a warning!', { emoji: 'interrobang' })
logger.error('This is a problem!', { emoji: 'collision' })
logger.debug('This is a debug! ', { emoji: 'face_with_monocle' })
logger.verbose('This is a verbose!', { emoji: 'hash' })

console.log(`\n\n Without emoji\n`)
// Without Emoji
logger.info('This is information!')
logger.warn('This is a warning!')
logger.error('This is a problem!')
logger.debug('This is a debug!')
logger.verbose('This is a verbose!')
logger.debug('This is a debug! ')
logger.verbose('This is a verbose!')
31 changes: 16 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const winston = require('winston')
const Emoji = require('node-emoji')

const { config } = winston

Expand All @@ -20,24 +21,24 @@ const datetime = () => {
}

const messageTemplate = options => {
const level = config.addColors(options.level)
const { message = '' } = options
const level = `${config.addColors(options.level)}`
const { message = '', emoji = null } = options
const emojiIcon = emoji ? Emoji.get(emoji) : null

return `[${level} ${datetime()}]: ${message}`
return `[${emoji ? `${emojiIcon} -` : '-'} ${level} ${datetime()}]: ${message}`
}

const logger = winston.createLogger({
format: winston.format.combine(
winston.format.colorize(),
winston.format.printf(options => messageTemplate(options))
),
transports: [new winston.transports.Console({
level: 'error',
level: 'warn',
level: 'info',
level: 'verbose',
level: 'debug',
})],
format: winston.format.combine(winston.format.colorize(), winston.format.printf(options => messageTemplate(options))),
transports: [
new winston.transports.Console({
level: 'error',
level: 'warn',
level: 'info',
level: 'verbose',
level: 'debug',
}),
],
})

module.exports = logger
module.exports = logger
Loading

0 comments on commit a09f40e

Please sign in to comment.