towergame / yatsl

Yet Another TypeScript Logger
https://www.npmjs.com/package/yatsl
MIT License
3 stars 2 forks source link

Logger logs incorrect line #18

Open towergame opened 2 years ago

towergame commented 2 years ago

The package logs an incorrect line reference when called. Expected behaviour: Calling logger.log("I live!") on line 4 of index.ts would output: 2022-08-05T15:15:27.266Z [debug | index.ts:4:8] I live!

Actual behaviour: Calling logger.log("I live!") on line 4 of index.ts outputs: 2022-08-05T15:15:27.266Z [debug | index.ts:150:53] I live!

towergame commented 2 years ago

The issue seems to be with the fact that logger.log calls logger.debug (since they both perform the same duty), which moves the actual caller a line down in the stack trace.

Fixing this should be a simple matter of just moving the logic for figuring out which line called the logger to the initial logging functions themselves (and not logger.write).

towergame commented 2 years ago

Pushed a bandaid fix in #19, but I should figure out a better way of getting the line for next minor revision.

sakars commented 1 year ago

I don't think the public log function should call debug as that is a public function and from the current TODO statement, it looks like you are attempting to make an exception to a function call.

If you want both functions to have the same behaviour, then point them to the same private function. That woud make getCallSignature break. A solution would be to generate the error at the top public function level and then pass it down to getCallSignature. Then the stack would always be just one level too deep.