Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zgo.at/slog_align

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zgo.at/slog_align

  • v0.0.0-20240913105347-cb623882eeef
  • Go
  • Socket score

Version published
Created
Source

Less "wall of text"-y slog handler; mainly for dev/testing.

I've seen so many apps that will just spit walls and walls of text on error failures and trying to get something meaningful out of it is like manually digging through War & Peace to find that one 6-word quote.

I don't know why all these go loggers have such terrible output by default; Just printing things a bit aligned makes such a world of difference. I must've written a handler like this 5 or 6 times for different loggers over the years by now.

Default handler:

2024/03/23 07:21:02 ERROR error
2024/03/23 07:21:02 WARN warn
2024/03/23 07:21:02 INFO info
2024/03/23 07:21:02 ERROR error str=foo int=123 map="map[another:true key:value struct:{s:[1 2 3]}]" slice="[a b]" struct="{s:asd i:123}"
2024/03/23 07:21:02 WARN warn str=foo int=123 map="map[another:true key:value struct:{s:[1 2 3]}]" slice="[a b]" struct="{s:asd i:123}"
2024/03/23 07:21:02 INFO info str=foo int=123 map="map[another:true key:value struct:{s:[1 2 3]}]" slice="[a b]" struct="{s:asd i:123}"

slog_align:

07:25 ERROR error                                                                       main/main.go:13
07:25 WARN  warn                                                                        main/main.go:14
07:25 INFO  info                                                                        main/main.go:15
07:25 DEBUG debug                                                                       main/main.go:16
07:25 ERROR error                                                                       main/main.go:32
            str    = foo
            int    = 123
            map    = map[another:true key:value struct:{[1 2 3]}]
            slice  = [a b]
            struct = {asd 123}
07:25 WARN  warn                                                                        main/main.go:33
            str    = foo
            int    = 123
            map    = map[another:true key:value struct:{[1 2 3]}]
            slice  = [a b]
            struct = {asd 123}
07:25 INFO  info                                                                        main/main.go:34
            str    = foo
            int    = 123
            map    = map[another:true key:value struct:{[1 2 3]}]
            slice  = [a b]
            struct = {asd 123}
07:25 DEBUG debug                                                                       main/main.go:35
            str    = foo
            int    = 123
            map    = map[another:true key:value struct:{[1 2 3]}]
            slice  = [a b]
            struct = {asd 123}

Use it as:

l := slog.New(slog_align.NewAlignedHandler(os.Stdout, nil))
l.Info("yo yo")

Or globally:

slog.SetDefault(slog.New(slog_align.NewAlignedHandler(os.Stdout, nil)))
slog.Info("yo yo")

FAQs

Package last updated on 13 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc