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

[Request] Add trace level #24

Open
johnpyp opened this issue Oct 12, 2024 · 1 comment
Open

[Request] Add trace level #24

johnpyp opened this issue Oct 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@johnpyp
Copy link

johnpyp commented Oct 12, 2024

As is standard in almost all loggers in other language ecosystems, and mostly standard in modejs, it would be great to add the trace level to finish the log4j-compatible logging levels.

There may be arguments for or against it on principle, but I think for consistency's sake is the strongest reason to add it regardless. Many downstream tools expect all of these levels, and adapters/abstractions over logging do as well.

@NfNitLoop
Copy link

NfNitLoop commented Feb 10, 2025

+1. I'd love a trace log level.

I tend to use "debug" for logging key pieces of information that I think (ahead of time) will be helpful for debugging.

I use "trace" to "just dump all the info", in case I need more info later. For example, dumping the entire response from a client/server interaction. If that always ends up in "debug" output, it can make "debug" so noisy that it's difficult for debugging the common case. But I want an easy way to enable it in case I do need it later.

I'm probably going to work around this locally, by adding a {trace: true} flag to some of my statements, and filtering them out unless I enable "trace" mode in my application. But it would be a lot easier if this were just built-in. 😊


Update, here's my workaround:

async function configureLogging(logLevel: LogLevel|"trace" = "debug") {
    const traceEnabled = logLevel == "trace"
    await lt.configure({
        loggers: [
            { 
                // This seems to act as a root category (which is handy!)
                // ... but I don't see it documented anywhere.
                category: [],

                lowestLevel: logLevel == "trace" ? "debug" : logLevel,
                sinks: ["console"],
                filters: ["trace"]
            },
            { category: ["logtape", "meta"], lowestLevel: "warning" },
        ],
        sinks: {
            console: getConsoleSink(),
        },
        filters: {
            trace: (rec) => traceEnabled || rec.properties.trace !== true
        }
    })
}

Of course, this fake "trace" loglevel only works for my app. Libraries would have to agree on a trace property for this to work globally. Unless logtape makes it a feature. 😉

@dahlia dahlia added the enhancement New feature or request label Feb 11, 2025
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

3 participants