I am using winston with winston-loggly-bulk to log messages to Loggly. I want to log all requests that my server receives. With morgan, I would do it simply like this:
app.use(morgan('dev'));
Can we do something similar with winston?
I am using winston with winston-loggly-bulk to log messages to Loggly. I want to log all requests that my server receives. With morgan, I would do it simply like this:
app.use(morgan('dev'));
Can we do something similar with winston?
Copyright © 2021 Jogjafile Inc.
To make it work, I combined
winstonandmorganpackages.1. Step
Create a
loggerthat you will use in your server to log messages toLoggly. For that, you can usewinstonandwinston-loggly-bulk. You can create a custom format for logging, and I also added part of the code that will check if the environment is not aproductionand in that case, it will log messages in the console as well (good practice for development).2. Step
Import your
loggerin part of the code where you would usemorganfor logging requests, and streammorganmessages in to thelogger. Again, I checked if the environment is aproduction, since I don't want to log requests indevelopment.