diff --git a/dist/lib/logged.d.ts b/dist/lib/logged.d.ts index c3ccb29..cd20ae4 100644 --- a/dist/lib/logged.d.ts +++ b/dist/lib/logged.d.ts @@ -18,6 +18,7 @@ interface OverrideBuildOptions { /** @deprecated use `errorLogLevel: 'skip'` instead */ skipErrorLog: boolean; } +export declare const REQUEST_LOG_ID = "__nestlogged_request_log_id__"; export declare function LoggedFunction, R>(options?: Partial): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R | Promise>) => void; export declare function LoggedRoute, R>(route?: string, options?: Partial): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(...args: F) => R>) => void; export declare function LoggedGuard, R>(options?: Partial): (_target: any, key: string, descriptor: TypedPropertyDescriptor<(context: ExecutionContext, ...args: F) => R>) => void; diff --git a/dist/lib/logged.js b/dist/lib/logged.js index cb60f4c..06c8f4f 100644 --- a/dist/lib/logged.js +++ b/dist/lib/logged.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.LoggedMiddleware = exports.LoggedInterceptor = exports.LoggedGuard = exports.LoggedRoute = exports.LoggedFunction = exports.LoggedController = exports.LoggedInjectable = void 0; +exports.LoggedMiddleware = exports.LoggedInterceptor = exports.LoggedGuard = exports.LoggedRoute = exports.LoggedFunction = exports.REQUEST_LOG_ID = exports.LoggedController = exports.LoggedInjectable = void 0; const common_1 = require("@nestjs/common"); const logger_1 = require("./logger"); const reflected_1 = require("./reflected"); @@ -110,7 +110,7 @@ function createCallLogIdentifyMessage(message, type, key, route) { return `${message} ${callLogIdentifyMessageDictionary[type]} ${key}`; return `${message} ${callLogIdentifyMessageDictionary[type]}`; } -const REQUEST_LOG_ID = '__nestlogged_request_log_id__'; +exports.REQUEST_LOG_ID = '__nestlogged_request_log_id__'; function overrideBuild(type, originalFunction, baseLogger, metadatas, key, returnsData, logged, route) { return function (...args) { // Creating ScopedLogger @@ -135,26 +135,26 @@ function overrideBuild(type, originalFunction, baseLogger, metadatas, key, retur } else { let req = ctx.switchToHttp().getRequest(); - if (req[REQUEST_LOG_ID] === undefined) { - req[REQUEST_LOG_ID] = logger_1.ScopedLogger.createScopeId(); + if (req[exports.REQUEST_LOG_ID] === undefined) { + req[exports.REQUEST_LOG_ID] = logger_1.ScopedLogger.createScopeId(); } - args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromRoot(baseLogger, key, req[REQUEST_LOG_ID]); + args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromRoot(baseLogger, key, req[exports.REQUEST_LOG_ID]); } } else if (type === 'middleware') { let req = args[0]; - if (req[REQUEST_LOG_ID] === undefined) { - req[REQUEST_LOG_ID] = logger_1.ScopedLogger.createScopeId(); + if (req[exports.REQUEST_LOG_ID] === undefined) { + req[exports.REQUEST_LOG_ID] = logger_1.ScopedLogger.createScopeId(); } - args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromRoot(baseLogger, key, req[REQUEST_LOG_ID]); + args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromRoot(baseLogger, key, req[exports.REQUEST_LOG_ID]); } else if (type === 'route') { // args[metadatas.scopedLoggerInjectableParam] is now Request object, thanks to code in @LoggedRoute!!!! let req = args[metadatas.scopedLoggerInjectableParam]; - if (req[REQUEST_LOG_ID] === undefined) { - req[REQUEST_LOG_ID] = logger_1.ScopedLogger.createScopeId(); + if (req[exports.REQUEST_LOG_ID] === undefined) { + req[exports.REQUEST_LOG_ID] = logger_1.ScopedLogger.createScopeId(); } - args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromRoot(baseLogger, key, req[REQUEST_LOG_ID]); + args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromRoot(baseLogger, key, req[exports.REQUEST_LOG_ID]); } } injectedLogger = args[metadatas.scopedLoggerInjectableParam]; diff --git a/dist/lib/utils.d.ts b/dist/lib/utils.d.ts new file mode 100644 index 0000000..f1429df --- /dev/null +++ b/dist/lib/utils.d.ts @@ -0,0 +1,2 @@ +import { ScopedLogger } from "./logger"; +export declare function getRequestLogger(functionName: string, req: any): ScopedLogger; diff --git a/dist/lib/utils.js b/dist/lib/utils.js new file mode 100644 index 0000000..e4ab114 --- /dev/null +++ b/dist/lib/utils.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getRequestLogger = void 0; +const common_1 = require("@nestjs/common"); +const logger_1 = require("./logger"); +const logged_1 = require("./logged"); +const logger = new common_1.Logger(); +function getRequestLogger(functionName, req) { + return new logger_1.ScopedLogger(logger, [functionName], req[logged_1.REQUEST_LOG_ID]); +} +exports.getRequestLogger = getRequestLogger; diff --git a/dist/package.json b/dist/package.json index ad64373..ee3045f 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "nestlogged", - "version": "3.2.0-beta.3", + "version": "3.2.0-beta.4", "description": "A NestJS Logger Decorator Library", "main": "lib/index.js", "repository": "https://git.psw.kr/p-sw/nestlogged", diff --git a/package.json b/package.json index 277ff3e..5f508aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nestlogged", - "version": "3.2.0-beta.3", + "version": "3.2.0-beta.4", "description": "A NestJS Logger Decorator Library", "main": "./dist/lib/index.js", "repository": "https://git.psw.kr/p-sw/nestlogged",