@valora/logging
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -12,7 +12,8 @@ import Logger, { LogLevel } from 'bunyan'; | ||
}): Logger; | ||
export declare function createLoggingMiddleware({ projectId, logger, }: { | ||
export declare function createLoggingMiddleware({ projectId, logger, excludeHttpRequestField, }: { | ||
projectId: string; | ||
logger: Logger; | ||
excludeHttpRequestField?: boolean; | ||
}): (req: ServerRequest, res: ServerResponse, next: Function) => void; | ||
export declare function createDetailedRequestSerializers(): Logger.Serializers; | ||
export {}; |
@@ -75,4 +75,4 @@ "use strict"; | ||
// This logs the request and response objects for all requests. | ||
// It also shows nicely formatted request logs for Cloud Functions in Logs Explorer (App Engine does this automatically). | ||
function createLoggingMiddleware({ projectId, logger, }) { | ||
// It also shows nicely formatted request log in Logs Explorer. | ||
function createLoggingMiddleware({ projectId, logger, excludeHttpRequestField, }) { | ||
function makeChildLogger(trace, span) { | ||
@@ -84,2 +84,3 @@ return logger.child({ [logging_bunyan_1.LOGGING_TRACE_KEY]: trace, [logging_bunyan_1.LOGGING_SPAN_KEY]: span }, true /* simple child */); | ||
const { requestUrl } = httpRequest; | ||
const googleServiceName = getGoogleServiceName(); | ||
const cloudFunctionName = process.env.K_SERVICE; | ||
@@ -91,6 +92,3 @@ logger.info({ | ||
res, | ||
// Note: Contrary to what the documentation says for `makeMiddleware`, | ||
// Cloud Functions (at least the gen1 version we use) doesn't already log the httpRequest | ||
// So we do it ourselves | ||
...(cloudFunctionName | ||
...(googleServiceName && !excludeHttpRequestField | ||
? { | ||
@@ -104,3 +102,4 @@ // This shows the nicely formatted request log in Logs Explorer. | ||
// from the summary line which are otherwise present when httpRequest is not set | ||
requestUrl: requestUrl?.startsWith('/') && | ||
requestUrl: cloudFunctionName && | ||
requestUrl?.startsWith('/') && | ||
!requestUrl.startsWith(`/${cloudFunctionName}`) | ||
@@ -107,0 +106,0 @@ ? `/${cloudFunctionName}${requestUrl}` |
{ | ||
"name": "@valora/logging", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"main": "dist/logging.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/logging.d.ts", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31107