Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Dharandas committed Aug 17, 2021
1 parent 7353795 commit 349783a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions example/logger/src/example.api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ExampleModule } from './example.module';
import {
Expand All @@ -10,10 +10,10 @@ import {

async function bootstrap() {
const logger = createStackdriverLoggerTool();
const app = await NestFactory.create(ExampleModule, {
const app: INestApplication = await NestFactory.create(ExampleModule, {
logger,
});
app.useLogger(createStackdriverLoggerTool(app as any));
app.useLogger(createStackdriverLoggerTool(app));
const configService = app.get(ConfigService);
if (configService.get<string>('FORCE_REQUEST_TRACE') === 'true') {
app.use(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestjs-pino-stackdriver",
"version": "2.1.2",
"version": "2.1.3",
"description": "NestJS Pino logger with Stackdriver support",
"author": "Jacob Dharandas Méndez <[email protected]>",
"license": "MIT",
Expand Down
8 changes: 5 additions & 3 deletions src/tools/create-logger.tool.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { v4 } from 'uuid';
import * as path from 'path';
import { INestApplication } from '@nestjs/common';
import { Context, RequestType } from 'nestjs-context';
import { Logger } from '../services';
import { LoggerConfig } from '../config';
import { ModuleRegisterType } from '../types';
import { isNestApplication } from '../type-guards';
import { INestApplicationContext } from '@nestjs/common/interfaces/nest-application-context.interface';

export const createLoggerTool: (
configOrApp: INestApplication | ModuleRegisterType,
configOrApp: INestApplicationContext | ModuleRegisterType,
contextName?: string,
) => Logger = (
configOrApp: INestApplication | ModuleRegisterType = {} as ModuleRegisterType,
configOrApp:
| INestApplicationContext
| ModuleRegisterType = {} as ModuleRegisterType,
contextName = process.argv[1]
? path.basename(process.argv[1], path.extname(process.argv[1]))
: path.basename(__filename),
Expand Down
6 changes: 4 additions & 2 deletions src/tools/create-stackdriver-logger.tool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { isEmpty } from 'lodash';
import { INestApplication } from '@nestjs/common';
import {
LoggerConfigType,
createLoggerTool,
isNestApplication,
ModuleRegisterType,
PredefinedConfig,
} from '..';
import { INestApplicationContext } from '@nestjs/common/interfaces/nest-application-context.interface';

export const createStackdriverLoggerConfig: (
config: LoggerConfigType,
Expand All @@ -19,7 +19,9 @@ export const createStackdriverLoggerConfig: (
} as LoggerConfigType);

export const createStackdriverLoggerTool = (
configOrApp: INestApplication | LoggerConfigType = {} as LoggerConfigType,
configOrApp:
| INestApplicationContext
| LoggerConfigType = {} as LoggerConfigType,
contextName?: string,
) => {
if (isNestApplication(configOrApp)) {
Expand Down
4 changes: 2 additions & 2 deletions src/type-guards/is-nest-application.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INestApplication } from '@nestjs/common';
import * as util from 'util';
import { INestApplicationContext } from '@nestjs/common/interfaces/nest-application-context.interface';

export const isNestApplication = (app: any): app is INestApplication => {
export const isNestApplication = (app: any): app is INestApplicationContext => {
return util.types.isProxy(app) && typeof app.get === 'function';
};

0 comments on commit 349783a

Please sign in to comment.