UNPKG

@ogma/nestjs-module

Version:

A NestJS module for the Ogma logger

80 lines (79 loc) 3.54 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var OgmaModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.OgmaModule = void 0; const common_1 = require("@nestjs/common"); const ogma_provider_1 = require("./ogma.provider"); const ogma_core_module_1 = require("./ogma-core.module"); /** * The NestJS module for the Ogma Logger. Not much to say here */ let OgmaModule = OgmaModule_1 = class OgmaModule { /** * Synchronous registration of the OgmaModule for NestJS. The options you can pass * are optional, and if nothing is passed the default value is `{}` * @param options The options for the OgmaModule * @returns a configured dynamic module for Nest to worry about later */ static forRoot(options) { return ogma_core_module_1.OgmaCoreModule.forRoot(options || {}); } /** * Asynchronous registration of the OgmaModule for NestJS. * @param options Asynchronous NestJS Module options for the OgmaModule * @returns a configured dynamic module for Nest to worry about later * @see https://dev.to/nestjs/advanced-nestjs-how-to-build-completely-dynamic-nestjs-modules-1370 */ static forRootAsync(options) { return ogma_core_module_1.OgmaCoreModule.forRootAsync(options); } /** * Creates a new OgmaService based on the given context and possible options. * Original options from the `forRoot` or `forRootAsync` options are merged with new options * * @param context string context for the OgmaService to use in logging * @param options object options in creation of OgmaService * @param options.addRequestId boolean if logger should add requestId to each log */ static forFeature(context, options = { addRequestId: false }) { const providers = this.createProviders(context, options); return { module: OgmaModule_1, providers, exports: providers, }; } /** * Creates several new OgmaServices based on the given contexts and possible options. * Original options from the `forRoot` or `forRootAsync` options are merged with new options */ static forFeatures(contexts) { const providers = contexts.map((ctx) => { if (typeof ctx === 'object') { return this.createProviders(ctx.context, ctx.options)[0]; } return this.createProviders(ctx)[0]; }); return { module: OgmaModule_1, providers, exports: providers, }; } static createProviders(context, options = { addRequestId: false }) { if (options.addRequestId) { return (0, ogma_provider_1.createRequestScopedLoggerProviders)(context); } return (0, ogma_provider_1.createLoggerProviders)(context); } }; exports.OgmaModule = OgmaModule; exports.OgmaModule = OgmaModule = OgmaModule_1 = __decorate([ (0, common_1.Module)({}) ], OgmaModule);