question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Method names for async functions not showing

See original GitHub issue

Describe the bug When a log is written from an async function it does not have a method name associated with it in the output. This might be an issue with how async/await works - or how I implement so not sure this is a tslog issue or not?

2020-11-18 02:31:14.309.000      INFO   [src\main.ts:5 testSync]                testSync - Yep    
2020-11-18 02:31:14.338.000      INFO   [src\main.ts:8]                 testAsync - Nope

To Reproduce

import { Logger } from 'tslog';
const logger = new Logger();

const testSync = () => {
  logger.info('testSync - Yep');
};
const testAsync = async () => {
  logger.info('testAsync - Nope');
};

(async () => {
  testSync();
  await testAsync();
})();

Expected behavior I would expect the output to show [src\main.ts:8 testAsync] not just [src\main.ts:8].

Screenshots image

Additional context Add any other context about the problem here.

Node.js Version v15.2.1

OS incl. Version Windows 10

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sfsr12commented, Nov 24, 2020

No, that was a mistake to target the old version - was converting old projects.

0reactions
terehovcommented, Nov 24, 2020

I am going to close this issue because you’ve already found a solution. Let me know if you have a valid use case for targeting es5.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get current method name from async function? - Stack Overflow
Getting the method name by using the caller info attributes is useless in a global error logger because you cannot get the first...
Read more >
Don't get burned by missing await Calls for Async Code in ...
I recently got burned in an upgraded ASP.NET Core server application where a missing `await` statement caused wildly inconsistent and ...
Read more >
async function - JavaScript - MDN Web Docs - Mozilla
An async function will return a different reference, whereas Promise.resolve returns the same reference if the given value is a promise. It can ......
Read more >
Why do people add Async to method names in new code?
I do append "Async" to the name of all my async methods for two ... it's not just any task, it's one that...
Read more >
Task asynchronous programming model - Microsoft Learn
Learn when and how to use Task-based async programming, a simplified approach to asynchronous programming in C#.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found