Giter Site home page Giter Site logo

Comments (7)

ivanmarban avatar ivanmarban commented on August 22, 2024

I'm not sure if I understand correctly but does this feature of winston do what you are requesting ?

Could you provide a complete example of your needs ?

from winston-telegram.

ivanmarban avatar ivanmarban commented on August 22, 2024

Let me know if this is what are you looking for:

const { createLogger, format, transports } = require('winston')
const TelegramLogger = require('winston-telegram')

// Ignore log messages if they have { private: true }
const ignorePrivate = format((info, opts) => {
  if (info.private) { return false }
  return info
})

const logger = createLogger({
  format: format.combine(
    ignorePrivate(),
    format.json()
  ),
  transports: [
    new transports.Console(),
    new TelegramLogger({
      token: 'TOKEN',
      chatId: 'CHAT_ID',
      level: 'error',
      unique: true
    })
  ]
})

// Outputs: {"level":"error","message":"Public error to share"}
logger.log({
  level: 'error',
  message: 'Public error to share'
})

// Messages with { private: true } will not be written when logged.
logger.log({
  private: true,
  level: 'error',
  message: 'This is super secret - hide it.'
})

from winston-telegram.

nicoandmee avatar nicoandmee commented on August 22, 2024

In a way yes but I was more thinking - not to ignore messages, but rather to selectively send them to Telegram, if {private: true} let's say in this instance. I know at a previous job we had this, just a slack bot instead of TG.
It would be invoked like this: logger.info('Login Success', { channel: '@nico' }). <-- This would go to channel specified.
But logger.info('cache-hit-1337') <-- this would only go to console.

The examples are contrived, but hopefully it's clear. 😓

from winston-telegram.

fr20587 avatar fr20587 commented on August 22, 2024

There is an example for NestJS?

from winston-telegram.

ivanmarban avatar ivanmarban commented on August 22, 2024

Sorry @fr20587 but I'm not familiar with NestJS.

@nicoandmee I'm sorry but I wasn't able to find time to take a look at your proposition for the moment.

from winston-telegram.

WildEgor avatar WildEgor commented on August 22, 2024

@nicoandmee you can try my fork (wip):
https://github.com/WildEgor/winston-telegram

https://github.com/WildEgor/winston-telegram/blob/develop/examples/simple-log/src/index.ts#L26

from winston-telegram.

ivanmarban avatar ivanmarban commented on August 22, 2024

After checking again @nicoandmee request, from my understanding, I think that there are two things:

  • Be able to selectively choose what transport to use to log the message with a unique logger defined. Not possible AFAIK
  • Be able to selectively choose what TG chatId should the log message be sent. That is the example from @WildEgor fork.

I'm closing this issue as there wasn't any activity or response since my last comment.

If anyone finds interesting to investigate and implement the second point, fell free to open a new issue.

from winston-telegram.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.