feature: request logging middleware for express#182
Conversation
60b028b to
59e95b5
Compare
|
Tests are expected to fail until a new version of |
|
I've extracted much of the logic to googleapis/nodejs-logging#248. |
59e95b5 to
5b51759
Compare
|
New version of winston is out now. This is ready to review. |
| import * as context from '@opencensus/propagation-stackdriver'; | ||
| import * as http from 'http'; | ||
|
|
||
| // TODO: move this code to @google-cloud/logging so that it can be shared |
There was a problem hiding this comment.
Do you have a bug open somewhere to track that?
|
👋 @ofrobots is this ready to go? |
|
Actually it turns out I still need to do a bit more work on this. |
|
Currently blocked on googleapis/nodejs-logging#376 being released. |
8eb5860 to
4990356
Compare
|
Okay, this is ready for review for realz this time. |
| options = Object.assign({}, defaultOptions, options); | ||
|
|
||
| const loggingWinstonApp = new LoggingWinston( | ||
| {...options, logName: `${options.logName}_${APP_LOG_SUFFIX}`}); |
There was a problem hiding this comment.
Would this always replace both the user and default option for logName?
There was a problem hiding this comment.
Yes. The middleware is opinionated. It may need to create two different log streams: one for the app logs and potentially one for the request logs (when not running on GAE/GCF). The app log will always uniformly have the _applog suffix. We want to 1) distinguish the app log from the request log and 2) have uniform naming regardless of the deployment environment.
It is conceivable that we might want to make ${APP_LOG_SUFFIX} a user-configurable option, but I don't see the need for it yet.
888893d to
f386df3
Compare
|
Is there any documentation on how to enable this or does it just magically starting working inside express? Thank you for doing this! |
|
Hi @shaunc869 this is not publicly exposed at this point unfortunately 😞. This is currently blocked by issues related to TypeScript and our transparent support for both winston2 and winston3 out of the same module: #278. I would suggest subscribing to that issue. |
|
I just saw the merge come through, looks like we're close on this maybe? |
|
@shaunc869 yes, this should get released around the end of the month. If you wanted to kick the tires, you can install the module from the master branch and play around: |
|
Sounds great I'll do that tonight any special instructions for this to work with express? |
|
The readme on the master branch has some instructions. |
|
Dumb question, now my import is failing and I can't see why, can these not be mixed?
|
|
The way you are importing |
|
Sorry I rebuilt and now I'm down to: For the code: |
|
Either import * as LoggingWinston from '@google-cloud/logging-winston';
const loggingWinston = new LoggingWinston.LoggingWinston({
projectId: 'highlevel-backend',
keyFilename: './lib/highlevel-backend.json',
serviceContext: {
service: process.env.GAE_SERVICE,
version: process.env.GAE_VERSION,
},
});or import {LoggingWinston} from '@google-cloud/logging-winston';
const loggingWinston = new LoggingWinston({
projectId: 'highlevel-backend',
keyFilename: './lib/highlevel-backend.json',
serviceContext: {
service: process.env.GAE_SERVICE,
version: process.env.GAE_VERSION,
},
});should work. Let me know if it doesn't. |
|
Awesome first one totally worked, now I threw in a test method: It runs fine, but nothing prints to the console on my localhost, should it? |
|
@shaunc869 Yeah, that is a problem – the express middleware configures only a stackdriver transport for winston. This is a bug. However, in order to keep the discussion focussed, I am going to open a new bug rather than continuing to work on this closed issue: #303 |
Similar to
logging-bunyan, this PR implements a request correlating middleware for express. This is WIP, but opening now to get early feedback.