Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error on setting as global logger #275

Closed
rubiin opened this issue Dec 29, 2020 · 6 comments
Closed

error on setting as global logger #275

rubiin opened this issue Dec 29, 2020 · 6 comments

Comments

@rubiin
Copy link

rubiin commented Dec 29, 2020

when I set it as global logger, I get

UnhandledPromiseRejectionWarning: TypeError: instance.getTimestamp is not a function

@rubiin rubiin changed the title error on setting as globla logger error on setting as global logger Dec 30, 2020
@rubiin
Copy link
Author

rubiin commented Dec 30, 2020

I am using like this:

import {
	MiddlewareConsumer,
	Module,
	NestModule,
	RequestMethod,
} from '@nestjs/common';
import { CustomerModule } from './modules/customer/customer.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import * as typeormConfig from './typeorm.config';
import { LoggerMiddleware } from './common/middlewares/logger.middleware';
import { SchedularModule } from './modules/schedular/schedular.module';
import { utilities, WinstonModule } from 'nest-winston';
import { format, transports } from 'winston';
import { TokenModule } from '@modules/token/token.module';
import { AuthMiddleWare } from '@common/middlewares/auth.middleware';

@Module({
	imports: [
		WinstonModule.forRoot({
			format: format.combine(
				format.timestamp({
					format: 'YYYY-MM-DD HH:mm:ss',
				}),
				format.errors({ stack: true }),
				format.splat(),
				format.json(),
			),
			defaultMeta: { service: 'Orbis-employee' },
			transports: [
				new transports.File({
					filename: 'logs/error.log',
					level: 'error',
				}),
				new transports.File({
					filename: 'logs/info.log',
					level: 'info',
				}),
				new transports.Console({
					format: format.combine(
						format.timestamp(),
						utilities.format.nestLike(),
					),
				}),
			],
			exceptionHandlers: [
				new transports.File({
					filename: 'logs/exceptions.log',
				}),
			],
		}),
		CustomerModule,
		TypeOrmModule.forRoot(typeormConfig),
		SchedularModule,
		TokenModule,
	],
	controllers: [],
	providers: [],
})
export class AppModule implements NestModule {
	configure(consumer: MiddlewareConsumer) {
		consumer
			.apply(LoggerMiddleware)
			.forRoutes({ path: '*', method: RequestMethod.ALL });

		consumer.apply(AuthMiddleWare).forRoutes(
			{ path: 'employee/', method: RequestMethod.GET },
			{ path: 'employee/', method: RequestMethod.POST },
			{ path: 'employee/:idx', method: RequestMethod.GET },
			{ path: 'employee/:idx', method: RequestMethod.PUT },
			{ path: 'employee/:idx', method: RequestMethod.DELETE },
			{ path: 'employee/pending', method: RequestMethod.GET },
			{ path: 'employee/pending/:idx', method: RequestMethod.GET },
			{ path: 'employee/verify/:idx', method: RequestMethod.PUT },
			{
				path: 'employee/reset-device/:idx',
				method: RequestMethod.PUT,
			},
		);
	}
}


@rubiin
Copy link
Author

rubiin commented Dec 30, 2020

and in main.ts\

	if (process.env.NODE_ENV === 'production') {
		app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
	}

@gremo
Copy link
Owner

gremo commented Dec 30, 2020

Well, there is too much code to debug or try to get a clue on which can cause that error. I would suggest to to remove all the modules/dependencies and only us the WinstonModule. Try to setup a minimal example so I can reproduce the error, OK?

@rubiin
Copy link
Author

rubiin commented Dec 30, 2020

let me try to setup a minimal example

@rubiin
Copy link
Author

rubiin commented Dec 30, 2020

Fixed it. I was using Logger.log inside bootstrap after replacing it by console.log, the issue resolved

@gremo
Copy link
Owner

gremo commented Dec 30, 2020

Glad to know! So, I'll close this isse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants