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

Pass full data argument to formatMessage method #27

Merged
merged 2 commits into from
Sep 25, 2021

Conversation

arnidan
Copy link
Contributor

@arnidan arnidan commented Sep 4, 2021

No description provided.

@arnidan
Copy link
Contributor Author

arnidan commented Sep 6, 2021

@ivanmarban

Hi, could you review the PR?

@ivanmarban
Copy link
Owner

I need to find some free time to review it. Sorry for the inconvenience. Thanks for your PR by the way :)

@ivanmarban
Copy link
Owner

ivanmarban commented Sep 11, 2021

Hi, I think this PR has the same behavior as Winston's use of info object. Here is an example that does the same as your test code:

const logger = require('winston')
const TelegramLogger = require('winston-telegram')

logger.add(
  new TelegramLogger({
    token: 'TELEGRAM_TOKEN',
    chatId: 'CHAT_ID',
    level: 'info',
    unique: true,
    formatMessage: function (options) {
      let message = options.message
      if (options.level === 'info') {
        message = '[Info] ' + message
      }

      if (options.metadata.superUrgent) {
        message += '!!!'
      }

      return message
    }
  })
)

const info = {
  level: 'info',
  message: 'Hey! Log something?',
  metadata: { superUrgent: true }
}

logger.log(info)

// Output: [Info] Hey! Log something?!!!

From my point of view, I see this feature redundant.

@arnidan
Copy link
Contributor Author

arnidan commented Sep 12, 2021

Here you force to use the metadata param to send meta. But winston doc says:

Properties besides level and message are considered as "meta"
const { level, message, ...meta } = info;

There is also an example of usage metadata: https://github.com/winstonjs/winston/blob/master/examples/metadata.js

In the PR I tried not to break your logic and gave an option to use full info object

@ivanmarban
Copy link
Owner

ivanmarban commented Sep 17, 2021

Thanks. I will make a release as soon as I understand how to replace Travis CI in favor of Github actions.

@ivanmarban ivanmarban merged commit c7f8a79 into ivanmarban:master Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants