tslog icon indicating copy to clipboard operation
tslog copied to clipboard

Bug: Incorrect Line Number

Open Sho-Nuff-007 opened this issue 3 years ago • 1 comments

Describe the bug The line number appears to be incorrect. I have a demo of my code below where I created a NEW Typescript project using npx tsc --init. This may just be with using ts-jest with typescript as if I compile my code and run it, then the line number works as expected. not sure if functionality though was only intended for when code was compiled which if so, then I guess this should be ignored. Also, if I were to use a little bit more code then what I have below, the number of lines off grows quite quickly to where I'll get a line 235 instead of line 26.

To Reproduce Steps to reproduce the behavior:

  1. Create a new project using npx tsc --init
  2. Replicate my index.ts and index.test.ts files.
  3. Install Jest.
  4. Run npx jest and check console.

Expected behavior Logs with the correct line number.

Screenshots image

Additional context index.ts

import { Logger} from 'tslog';

export const log: Logger = new Logger({
  name: 'monopoly_deal_logger',
  minLevel: 'info',
});

log.info('line number 8');

index.test.ts

import { log } from '../src/index';

test('logger', () => {
  
  log.info('this is on line 5');
});

Node.js Version v18.7.0

OS incl. Version Windows 11 - wsl2 w/Ubuntu

Sho-Nuff-007 avatar Sep 16 '22 20:09 Sho-Nuff-007

It would be interesting to know, how you start the TypeScript version. Can you pls provide that command too. Thx.

terehov avatar Sep 17 '22 10:09 terehov

There is a new, completely rewritten version (4.0) with native source maps support. Give it a go and let me know if that solves your problem:

  • npm i tslog@next

  • and run it with node --enable-source-maps or for TypeScript node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm

terehov avatar Sep 29 '22 10:09 terehov

V4 is released now, so I'm going to close this issue. Feel free to open a new one if V4 didn't solve it for you.

Here are the docs: tslog.js.org

terehov avatar Nov 15 '22 18:11 terehov