Open keystef opened 11 months ago
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. We once ran into a similar problem with tRPC and assumed tslog was the problem, it turned out to be a circular dependency and a Node problem indeed. If that’s not the case, can you provide me with a repo, that boils down the problem for reproduction? Thx
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