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

format logging information (?) #129

Open
JonathanLoscalzo opened this issue Aug 10, 2018 · 5 comments
Open

format logging information (?) #129

JonathanLoscalzo opened this issue Aug 10, 2018 · 5 comments
Assignees

Comments

@JonathanLoscalzo
Copy link

With console and file, I design my own format for log:

...
format: winston.format.combine(
            winston.format.colorize(),
            winston.format.timestamp(),
            winston.format.printf(info => `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}`)
        )
....

with printf

How Could I format with a similar approach with winston-mongodb? :-)

@samuelgoldenbaum
Copy link

yip, needed

@KarlNilsson
Copy link

Any update on this? Trying to use this as a middleware error logger in my express application, with the following code:

app.use(
    WinstonExpress.errorLogger({
      transports: [
        new MongoDB.MongoDB({
          level: 'error',
          db: `${loggerDBConfig.database}/logging`,
          options: {
            useNewUrlParser: true,
            useUnifiedTopology: true,
            auth: {
              user: loggerDBConfig.username,
              password: loggerDBConfig.password,
            },
          },
        }),
      ],
      format: winston.format.combine(
        winston.format.timestamp(),
        errorLogFormat
      ),
    })
  );

It seems like the format is not even applied for the MongoDB transport. It never hits my debugger breakpoint. It does do that if I add another transport, such as winston.transports.File(...). My current output to MongoDB looks like this

{
    _id: ObjectId('5ee0ea740d745a01c38b0f6f'),
    timestamp: ISODate('2020-06-10T14:13:08.422Z'),
    level: 'error',
    message: 'middlewareError',
    meta: null
}

Not very useful as of now. What I'm trying to accomplish in my errorLogFormat function is to extract data.meta.message which contains the actual error message. Any pointers on how to achieve this?

@BaalDev-Solutions
Copy link

This is a needed feature. The logger itself is not really useful without this

@BaalDev-Solutions
Copy link

@JonathanLoscalzo, @samuelgoldenbaum, @KarlNilsson. There is a dirty trick you can you do for overcoming this problem without changing all your implementation. Create two loggers, one without the MongoDb transport and other with it. Then in the logger that does not have the MongoDb transport activate add a format function, and in that function call to your other logger with the desired format.

Dirty and not really efficient. But works.

@zolero
Copy link

zolero commented Aug 31, 2020

Could you add this feature @yurijmikhalevich? This is important to do some detailed reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants