charmbracelet / charmbracelet/log

Using another library instead of encoding/json for the JSONFormatter

Open
#125 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
3.4k
Forks
103
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
I was using the JSONFormatter to print structure, when i saw that `encoding/json` doesn't support `map[interface{}]interface{}`

Since the logger doesn't return any information when such an error occurs, it took me several hours of debugging to finally locate that the problem came from the json formatter (I didn't expect it not to support a data type like that).

After a bit of online digging, I discovered that this is a fairly common problem and that libraries like json-iterator (among others) try to solve it.

**Describe the solution you'd like**
Use something other than the core library to format it to support all data types

**Describe alternatives you've considered**
- Make my own logger using json-iterator
- Create my own formatter, but the library doesn't currently seem to support custom formatter.

**Additional context**
```
json: unsupported type: map[interface {}]interface {}
```

Contributor guide

Open the contributing guide

Research direction

Locate the JSONFormatter and its current use of Go's encoding/json, then reproduce the reported map[interface{}]interface{}{} failure. Compare the proposed JSON library options and determine how formatter errors should be surfaced; done means the formatter handles the reported data type and users receive useful error information.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.