-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Bug: Logging custom objects causes BSONError - console.log works fine #271
Comments
I got the same error while building a typescript application. Node:18:14:2, TSC: 5.3.2. MacOS |
Same issue here using a custom logger this would be nice to fix! |
Is it possible, that you have some circular dependencies somewhere? So basically, in the file where you create the root logger to the file where you try to create or consume a sub logger? Have you tried importing tslog instanciating the logger in the same file, where you replaced that logger with console.log? Because effectively it’s exactly what you did by placing console.log inside, since you instanciate it right there without importing a sub logger. |
I can't share the full code but I'm not really doing any import magic. This is my logging config: import { Logger, ILogObj, ISettingsParam } from 'tslog';
const prettyLogConfig: ISettingsParam<ILogObj> = {...};
const structuredLogConfig: ISettingsParam<ILogObj> = {...};
const formattedLogging: boolean = ['0', 'off', 'false', 'no'].includes(
String(process.env?.STRUCTURED_LOGS).toLowerCase()
);
const logger: Logger<ILogObj> = new Logger(
formattedLogging ? prettyLogConfig : structuredLogConfig
);
export { logger }; Then I use it like this: import { logger } from './logging.js';
...
const objects: MyCustomObject[] = await getMyCustomObjects(getMyCustomObjectsRequest);
console.log(`List objects (console)`, objects);
logger.info(`List objects (logger)`, objects); |
Logging objects returned by a gRPC call results in an error (see additional context below) when the same objects can be printed without any problems using console.log.
The Objects are obtained like this:
The console.log output is as follows:
There is no output for the logger at all but I get a stack trace in Postman, which I use to send the gRPC request.
I know the stack trace says it's a node issue but if it was I think using
console.log
should result in the same error.Expected behavior
The objects should be printed the same way
console.log
prints them.Additional context
Node.js Version
v18.14.0
OS incl. Version
Ubuntu 22.04 but application is running inside docker container using node:18.14.0-alpine image
The text was updated successfully, but these errors were encountered: