Skip to content
/ logfmt Public

Lightweight, customizable command-line structured log formatter

Notifications You must be signed in to change notification settings

thdxg/logfmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logfmt

CI Release Go Report Card

logfmt reads structured logs from stdin and formats into readable output

Demo

Installation

Binary (Recommended)

Download the latest binary for your platform (Linux, macOS, Windows) from the Releases page.

Go Install

go install github.com/thdxg/logfmt@latest

Usage

$ go run ./cmd/autoscaler 2>&1 | logfmt
2026-02-10 12:18:55 INFO Autoscaler started
2026-02-10 12:18:56 DEBUG Scaler registered target.id=7bfc2889-8fc2-4b31-b309-80fd8984628b target.name=RAG
2026-02-10 12:18:56 INFO Manager started interval.metric=5s interval.scale=10s
2026-02-10 12:19:01 DEBUG Metric fetched target=RAG value=0
2026-02-10 12:19:01 INFO Tick metric success=1 total=1

Configuration

You can configure logfmt using command line flags, environment variables, or a config file (.logfmt.yaml in home or current directory).

Flags

logfmt -time-format "15:04:05" -level-format=short -no-color
  • -time-format: Timestamp format (Go layout). Default: 2006-01-02 15:04:05
  • -level-format: Level style (full, short, tiny). Default: full
  • -no-color: Enable/disable colored output. Default: true
  • -hide-attrs: Show only time, level, and message. Default: false

Environment Variables (prefix LOGFMT_)

  • LOGFMT_TIME_FORMAT
  • LOGFMT_LEVEL_FORMAT
  • LOGFMT_COLOR
  • LOGFMT_HIDE_ATTRS

Motivation

I've been using libraries like tint to format structured logs in my Go projects. Formatting logs is primarily for better readability during local development, but using a library for this means adding an unnecessary dependency to your project. Having a customizable local command line tool to format any kind of json logs solves this problem.

About

Lightweight, customizable command-line structured log formatter

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages