Skip to content

Better logging #24856

@Kjur0

Description

@Kjur0

What is the problem this feature would solve?

I'm writing my first library for Bun, and I've got no experience in writing JS/TS libs, so maybe it's not standard approach, but I tend to leave TRACE logs...

Unfortunately, despite there being logLevel in bunfig.toml. And all browsers supporting at least 4 levels of logging it's not easily possible to hide/disable console.trace() or console.debug() logs, which leads to my console being extremally bloated by all the requests and responses (I'm making API library)

What is the feature you are proposing to solve the problem?

The feature is quite simple. And has been implemented by multiple libraries, and other programming languages.

It's logLevels support for all console functions

Given that there are different console functions so it would make sense that they are not just all aliases to each other.

My proposal are those levels which you could set in bunfig.toml:

  • Error - for console.error()
  • Warn - for console.warn()
  • Info/Log - for console.info() & console.log()
  • Trace/Verbose/Debug - for console.trace() & console.debug() (or separating them into 2 levels)

Or something like this.

It's pretty trivial to implement such functionality in Runtime so I reckon it's not the highest priority, but it would be cool if Bun had a proper logging system.

Implementing such functionality natively should also include logging to file (i.e. on stderr and stdout only show INFO level and save all Debug level to some file, of course it should be customizable, but that shouldn't be too hard to implement)
It doesn't have to be something complicated.

Alternatively, you could leave current console functionality as is and add some special Bun.log functionality

What alternatives have you considered?

The simplest alternatives are:

  1. if (bun.env.TRACE != 0) console.trace = () => {}
  2. Deleting all console.trace(), but it really makes it easier to debug, when you can simply look through all requests/responses when something needs fixing
  3. Using external logging libraries, but that would force users of my library to use the chosen library. Also, I'm trying to make my own library without using anything not included in Bun APIs (everything I need is WebSocket, fetch(), Bun.serve())

Metadata

Metadata

Assignees

No one assigned

    Labels

    consoleRelated to console apisenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions