I had set logging: true when createConnection() from TypeORM, which works fine for most of times.
But there is a situation where one of my data field from a specific query/mutation may contains a long string (50000 - 300000 char depends on the input, it could be more). When typeORM try to log the content in VScode terminal, it can crush VScode, I wonder if there is anything that TypeORM can hide such a long string instead of completely disable all the query loggings.
My ideal approach would be something like longstring=== (modification based on the string and text ellipsis) ===> long.... Or just apply a custom logger for specific query if necessary.
So it can still log to indicate the bit of code is running with minimal info.
From the doc, it seems like I can only add additional information instead of modifying. https://github.com/typeorm/typeorm/blob/master/docs/logging.md
=============== Update ==============
Based on the accepted solution, it seems like I did not understand the doc properly. We can custom the logger based on our needs. Since I want to cut off the parameter. So I can do the following.
import { AdvancedConsoleLogger, Logger, LoggerOptions, QueryRunner } from "typeorm";
export class CustomLogger extends AdvancedConsoleLogger implements Logger {
constructor(options?: LoggerOptions) {
super(options);
}
//override logquery
logQuery(query: string, paramters?: any[], queryRunner?: QueryRunner) {
const limit = 100;
const paramTextEllipsis = paramters?.map((param) => {
//only cut off string and length longer than 100
if(typeof param === "string" && param.length > limit){
return param.substring(0, limit) + "...";
}
return param;
});
super.logQuery(query, paramTextEllipsis, queryRunner);
}
};
The result from terminal. Note that the json string originally has more than 100k which can easily crush editor.
