Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Show correct log position when running in vite #302

Open
koljada opened this issue Sep 12, 2024 · 2 comments
Open

Feature Request: Show correct log position when running in vite #302

koljada opened this issue Sep 12, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@koljada
Copy link

koljada commented Sep 12, 2024

I'm developing vue 3 application using vite. tslog library is useful for me but unfortunately, I cannot make it showing correct log positions. I tried to set source maps in vite.config.ts and tsconfig.json but it didn't work. My log position always looks like this: /node_modules/.vite/deps/tslog.js:937

Did I miss come configuration step or it is not supported yet?

@koljada koljada added the enhancement New feature or request label Sep 12, 2024
@koljada
Copy link
Author

koljada commented Sep 12, 2024

After some investigation I found that stackDepthLevel value is wrong, at least when running with vite on my machine. In my case it's needed to use 6 instead of 5. Here is one of my stack frames:

    at getCallerStackFrame (http://localhost:5173/node_modules/.vite/deps/tslog.js?v=720e19ab:559:55)
    at Object.getMeta (http://localhost:5173/node_modules/.vite/deps/tslog.js?v=720e19ab:556:44)
    at Logger._addMetaToLogObj (http://localhost:5173/node_modules/.vite/deps/tslog.js?v=720e19ab:871:50)
    at Logger.log (http://localhost:5173/node_modules/.vite/deps/tslog.js?v=720e19ab:710:203)
    at Logger.trace (http://localhost:5173/node_modules/.vite/deps/tslog.js?v=720e19ab:938:18)
    at http://localhost:5173/src/composables/useWidget.ts:82:27
    at http://localhost:5173/node_modules/.vite/deps/chunk-IDN7BJ6T.js?v=720e19ab:4845:40
    at callWithErrorHandling (http://localhost:5173/node_modules/.vite/deps/chunk-IDN7BJ6T.js?v=720e19ab:2289:19)
    at callWithAsyncErrorHandling (http://localhost:5173/node_modules/.vite/deps/chunk-IDN7BJ6T.js?v=720e19ab:2296:17)
    at hook.__weh.hook.__weh (http://localhost:5173/node_modules/.vite/deps/chunk-IDN7BJ6T.js?v=720e19ab:4825:19)

So I fixed the problem by creating my custom logger class and passing 6 value to the base class

@vivlim
Copy link

vivlim commented Nov 11, 2024

That worked for me. My (ugly!) workaround:

class MyLogger<T> extends Logger<T> {
    constructor(settings?: ISettingsParam<T>, logObj?: T) {
        super(settings, logObj);
        // @ts-ignore setting this private member as a workaround for https://github.com/fullstack-build/tslog/issues/302
        this.stackDepthLevel = 6
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants