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

feat: Add emoji support #1

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
node_modules

# Mac OS
.DS_Store
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 } = options
const emojiIcon = emoji ? Emoji.get(emoji) : ''

return `[${level} ${datetime()}]: ${message}`
return `${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