Closed ahuijiLearning closed 5 months ago
I have same issue.
As workaround I did something like this:
export class OrmLogger implements Logger {
logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner) {
const startTime = (asyncLocalStorage.getStore() as any)?.startTime;
console.log(`${+startTime} Executed: ${query}`);
if(queryRunner) {
queryRunner.data._logRc = asyncLocalStorage.getStore();;
}
}
logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: QueryRunner) {
const rc = queryRunner?.data._logRc ?? {};
asyncLocalStorage.run(rc, () => {
const startTime = (asyncLocalStorage.getStore() as any)?.startTime;
console.log(`${+startTime} Executed: ${query} time: ${time}ms`);
// I call other functions here and asyncLocalStorage.getStore() works correctly in them.
});
}
}
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
Details
So why does logQuery get store correctly and logQuerySlow doesn't? Is there a solution to get a store in logQuerySlow? This seems to need to use AsyncResource, but I don't know how to use it.
Node.js version
v14.19.0
Example code
I have looked at Typeorm related Mysql Query internal implementation, which is described as follows:
Operating system
mac
Scope
async_hooks. AsyncLocalStorage
Module and version
"@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", "@nestjs/typeorm": "^8.0.3",