Comments (12)
Hi @rubiin , please post the full configuration that you are using. Also, try first to update the winston
package. It has been updated recently, maybe it's their fault.
from nest-winston.
iam importing like this in app.module
WinstonModule.forRoot({
transports: [new winston.transports.Console({
level: 'info',
handleExceptions: false,
format: winston.format.combine(
winston.format.timestamp(),
utilities.format.nestLike(),
),
and in a controller of my usermodule , i am injecting as
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger
and using the logger as this.logger.log('')
from nest-winston.
@gremo its latest
from nest-winston.
Sorry forgot to reply. Honestly, I don't know what's is going on here. Are you able to create a repository (minimal example) for this issue?
from nest-winston.
@gremo and @rubiin, I had the same problem than you. I solved passing the context (in the first argument) to log
function.
this.logger.log('Hello!!'); // exception Cannot create property 'Symbol(level)' on string 'Hello!!'
this.logger.log('info', 'Hello!!'); // it works!
from nest-winston.
@marcelom56 @rubiin if you are using WINSTON_MODULE_PROVIDER
injection token, like this example:
import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston';
@Controller('cats')
export class CatsController {
constructor(@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger) { }
}
... it means you are using the winston
package "directly". Looking at the package README, I can't see any evidence of using logger.log
without specify any level, that might cause the error reported.
//
// Logging
//
logger.log({
level: 'info',
message: 'Hello distributed log files!'
});
logger.log('info', 'test message %s', 'my string');
TLTR: always specify a level when using logger.log
as provved by @marcelom56 .
I'm going to close this issue as it seems not related to the nest-winston
package. Feel free to comment further if I've misunderstood the problem.
from nest-winston.
sure that helps
from nest-winston.
I stumbled upon the same problem.
I found this issue at winston repo:
Leaving this here for others who come to this thread. The winstonlogger object does have a .log() method. However, unlike console.log(), it requires two arguments, not just one. If you forget the first argument, the log message category, you will get the Symbol(level) error.
This is how I'm using it:
import { Controller, Get, Inject, Logger } from '@nestjs/common';
import { AppService } from './app.service';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger
) {}
@Get()
getHello(): string {
this.logger.log('hello!!!') // TypeError: Cannot create property 'Symbol(level)' on string 'hello!!!'
this.logger.log('info', 'hello!!!') // ok
return this.appService.getHello();
}
}
It seems inconsistent with nestjs Logger (vscode tooltip displays: (method) Logger.log(message: any, context?: string): void
)
Perhaps we should override winston log method to make it work like nestjs. Here is a suggested workaround. I think that logger.log(...) should in fact call winston.info(...).
It's rather frustrating to get stuck at such a trivial example, and I'm suprised there aren't more people reporting it
kept doing a couple more tests
following the steps described in Use as the main Nest logger I get the same error, and following Use as the main Nest logger (also for bootstrapping) is the only case which seems to work ok.
from nest-winston.
Moreover, from winston doc, every example given with logger.log receives the log level as first parameter, and in the using loggin levels section says:
Setting the level for your logging message can be accomplished in one of two ways. You can pass a string representing the logging level to the log() method or use the level specified methods defined on every winston Logger.
from nest-winston.
I'm sorry but this shouldn't be closed.
If by injecting the Winston logger by doing the following, it seems we end up with the actually Winston logger instance (and not a logger through nest logger interface).
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger
So I think the injection should be:
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: WinstonLogger
And the typings should be fixed.
import { Logger } from 'winston';
import { LoggerService } from '@nestjs/common';
export declare class WinstonLogger implements LoggerService {
private readonly logger;
private context?;
constructor(logger: Logger);
setContext(context: string): void;
log(level: string, message: any, context?: string): any; // Adding level as a first argument
error(message: any, trace?: string, context?: string): any;
warn(message: any, context?: string): any;
debug?(message: any, context?: string): any;
verbose?(message: any, context?: string): any;
}
from nest-winston.
yes that should be done
from nest-winston.
@empz I've updated the README, please can you check it out and see if something is wrong or unclean (especially about the injection token)?
Typings are correct. If you look at the LoggerService
from Nest, you can see that the log function doesn't define any level. You are probably talking about the log
from winston package.
In addition, I'm working on providing samples which should help people with the token/typings. 👍
from nest-winston.
Related Issues (20)
- Logging NestJS request details with every log? HOT 4
- "Unknown logger level" error when used for bootstraping HOT 3
- Nest can't resolve dependencies HOT 8
- Default context per service (configurable injection scope) HOT 3
- Passing winston logger instance to forRoot doesn't work HOT 2
- [Bug]: Creating multiple winston modules using child winston loggers use the last created winston module when using the nestjs Logger constructor HOT 2
- Adding "level" argument to log method HOT 2
- NestLike ConsoleFormat always contains stringifiedMeta and essentially logs message twice HOT 7
- LoggerService interface changed with Nest v8 HOT 2
- Is there a way to create a child logger? HOT 2
- How can I pass json attributes into the logger? HOT 3
- Support for @nestjs/common 10.0.0 in Peer Dependencies HOT 2
- [Question]: Should documentation be updated? HOT 8
- [Feature]: Support string-interpolation HOT 1
- [Question]: How to get trace_id ? HOT 4
- [Feature]: add fatal level HOT 6
- [Question]: How can I access a request scope injectable when replacing the Nest logger (including boostrap) ? HOT 2
- [Question]: Winston creates file but does not save to it
- [Question]: processing optional arguments is not consistent with Nest HOT 3
- [Bug]: Redundant Stack Information in Error Logs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nest-winston.