-
Notifications
You must be signed in to change notification settings - Fork 726
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
No logger is set up #908
Comments
@maxxims I'll consider your proposal |
@igolubic for sharing your solution please use "Awesome" repos. Thanks for understanding. |
For what it's worth, my solution to this right now is to have this at the top of all my classes where I'd like a logger:
Having said that, I could see there being some sense in making this injectable module/service too, so there's a single place they could processed and filtered. |
I had another chance to think about this and came up with the following: import { Module } from '@nestjs/common';
import { AppLogger } from './app.logger.js';
/* logger module */
@Module({
providers: [AppLogger],
exports: [AppLogger],
})
export class LoggerModule {}
/* app logger service */
@Injectable({ scope: Scope.TRANSIENT })
export class AppLogger extends ConsoleLogger {}
/* example usage module */
@Module({
imports: [
LoggerModule,
// etc
],
controllers: [],
providers: [FilesService],
exports: [FilesService],
})
export class FilesModule {}
/* example usage service */
@Injectable()
export class FilesService {
constructor(
protected readonly logger: AppLogger
) {
logger.setContext(FilesService.name);
}
async upload(file: Express.Multer.File): Promise<FileEntity> {
this.logger.verbose(this.upload.name);
//etc
}
} |
I've had some more time to think about this, I recommend the module solution for those that have centralized logging needs, like storing to file or uploading to a particular service or varying by environment, however I think Nest's default is the best go-to approach as it does not involve another module: export class FilesService {
private readonly logger = new Logger(FilesService.name);
private readonly s3: S3;
constructor(
@InjectRepository(FileEntity)
private readonly fileRepository: Repository<FileEntity>,
@Inject(FilesConfig.KEY)
private config: ConfigType<typeof FilesConfig>,
) {
this.logger.verbose(this.constructor.name);
// ...
}
async upload(file: Express.Multer.File): Promise<FileEntity> {
this.logger.verbose(this.upload.name);
// ...
}
} If you ever want to re-use your code in another Nest project, having an |
Consider using Ogma Logger. |
An important part of any new project is having a good logging system set up from the very first beginning.
Taking into consideration the current best practices, could you please add a nice logging system to the boilerplate?
The text was updated successfully, but these errors were encountered: