Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support custom emojis #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ const logger = pino({
logger.info('hi')
```

## Custom emojis
When using pino-colada programmatically, you can define custom emojis. This is useful
when you define custom levels and want to provide emojis for them or if you want to
override any default emoji.

```
const pino = require('pino')
const logger = pino({
prettyPrint: {
customEmojis: {
info: '✅',
success: '✅',
fail: '❌'
}
},
prettifier: require('pino-colada'),
customLevels: {
success: 31,
fail: 32
}
})

logger.info ('hi');
logger.success ('hi');
logger.fail ('hi');
```


# Install
```bash
npm install pino-colada
Expand Down
21 changes: 10 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ function isPinoLog (log) {

module.exports = PinoColada

function PinoColada () {
function PinoColada (opts) {
const pinoInstance = this;

const { customEmojis } = opts;
if (!!customEmojis) {
emojiLog = Object.assign ({}, emojiLog, customEmojis);
}

return parse

function parse (inputData) {
Expand All @@ -47,19 +54,11 @@ function PinoColada () {

if (!obj.level) return inputData + nl
if (!obj.message) obj.message = obj.msg
if (typeof obj.level === 'number') convertLogNumber(obj)
if (typeof obj.level === 'number') obj.level = pinoInstance.levels.labels[obj.level]

return output(obj) + nl
}

function convertLogNumber (obj) {
if (obj.level === 10) obj.level = 'trace'
if (obj.level === 20) obj.level = 'debug'
if (obj.level === 30) obj.level = 'info'
if (obj.level === 40) obj.level = 'warn'
if (obj.level === 50) obj.level = 'error'
if (obj.level === 60) obj.level = 'fatal'
}

function output (obj) {
var output = []
Expand Down Expand Up @@ -128,7 +127,7 @@ function PinoColada () {

function formatMessage (obj) {
var msg = formatMessageName(obj.message)
var pretty
var pretty = msg
if (obj.level === 'error') pretty = chalk.red(msg)
if (obj.level === 'trace') pretty = chalk.white(msg)
if (obj.level === 'warn') pretty = chalk.magenta(msg)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@hapi/hapi": "^18.0.0",
"hapi-pino": "^6.3.0",
"merry": "^4.0.0",
"pino": "^6.9.0",
"pino-http": "^4.3.0",
"standard": "^14.0.0"
},
Expand Down