How to use the @google-cloud/logging.middleware.express function in @google-cloud/logging

To help you get started, we’ve selected a few @google-cloud/logging examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-logging-bunyan / src / middleware / express.ts View on Github external
// automatically.
  let emitRequestLog;
  if (env !== GCPEnv.APP_ENGINE && env !== GCPEnv.CLOUD_FUNCTIONS) {
    const loggingBunyanReq = new LoggingBunyan(options);
    const requestLogger = bunyan.createLogger({
      name: options.logName!,
      streams: [loggingBunyanReq.stream(options.level as types.LogLevel)],
    });
    emitRequestLog = (httpRequest: HttpRequest, trace: string) => {
      requestLogger.info({[LOGGING_TRACE_KEY]: trace, httpRequest});
    };
  }

  return {
    logger,
    mw: commonMiddleware.express.makeMiddleware(
      projectId,
      makeChildLogger,
      emitRequestLog
    ),
  };

  function makeChildLogger(trace: string) {
    return logger.child({[LOGGING_TRACE_KEY]: trace}, true /* simple child */);
  }
}

@google-cloud/logging

Cloud Logging Client Library for Node.js

Apache-2.0
Latest version published 3 months ago

Package Health Score

88 / 100
Full package analysis