Skip to content

Better-looking logs for Go. Styled tags, aligned gutters, and multi-line caller info. Built for Logrus.

License

Notifications You must be signed in to change notification settings

canefe/pretty-go-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pretty-go-log

Latest Version  Build Status  Go Report Card

A small Go package that gives logrus a cleaner, structured, and visually aligned output style with bracketed tags, optional colors, and multi-output support.

Use it as a drop-in logger with sane defaults, or fully customize formatting, output, and caller behavior using functional options.

pretty-go-log

What is Pretty Go Log?

Pretty Go Log wraps logrus with a formatter designed for readability:

  • Aligned Tag Output. Bracketed tags align to a common column for fast scanning
  • Multiple Tag Styles. Default, centered, or right-aligned tag padding
  • Multi Output. Console + rotating file output with separate formatters
  • Configurable Colors. Colorized levels and tags, dim gray padding
  • Caller Awareness. Toggle caller output for warnings and errors
  • Environment Config. Use LOG_LEVEL, LOG_OUTPUT, LOG_FORMAT defaults

Installation

go get github.com/canefe/pretty-go-log

Quick Start

package main

import (
    "github.com/canefe/pretty-go-log/logrus/pretty"
)

func main() {
    log := pretty.New()

    log.Info("[Server] Started on :8080")
    log.Warn("[Cache] Miss for key user:123")
}

Usage

Functional Options

package main

import (
    "github.com/canefe/pretty-go-log/logrus/pretty"
    "github.com/sirupsen/logrus"
)

func main() {
    log := pretty.New(
        pretty.WithLevel(logrus.DebugLevel),
        pretty.WithOutput(pretty.OutputMulti),
        pretty.WithFormat(pretty.FormatPlain),
        pretty.WithNamespace("App"),
        pretty.WithFile("logs/service.log"),
    )

    log.Debug("[Init] Starting")
}

Custom Formatter

package main

import (
    "github.com/canefe/pretty-go-log/logrus/pretty"
    "github.com/sirupsen/logrus"
)

func main() {
    formatter := pretty.NewCustomFormatter(
        pretty.WithTagStyle(pretty.StyleRight, "."),
        pretty.WithBracketPadding(15),
        pretty.WithColorBrackets(true),
    )

    log := pretty.New(
        pretty.WithLevel(logrus.InfoLevel),
        pretty.WithOutput(pretty.OutputMulti),
        pretty.WithCustomFormat(*formatter),
        pretty.WithFile("logs/service.log"),
    )

    log.Info("[API] Request completed")
}

Environment Configuration

package main

import (
    "os"

    "github.com/canefe/pretty-go-log/logrus/pretty"
)

func main() {
    os.Setenv("LOG_LEVEL", "debug")
    os.Setenv("LOG_OUTPUT", "console")
    os.Setenv("LOG_FORMAT", "plain")

    log := pretty.New()
    log.Debug("[Env] Logger configured via env vars")
}

Options and Types

Output Types

  • pretty.OutputConsole
  • pretty.OutputFile
  • pretty.OutputMulti

Format Types

  • pretty.FormatRaw
  • pretty.FormatPlain
  • pretty.FormatJSON

Common Options

  • pretty.WithLevel(level logrus.Level)
  • pretty.WithOutput(output pretty.OutputType)
  • pretty.WithFormat(format pretty.FormatType)
  • pretty.WithNamespace(name string)
  • pretty.WithFile(path string)
  • pretty.WithoutCaller()
  • pretty.WithCustomFormat(formatter pretty.CustomFormatter)

Examples

  • examples/logrus/basic
  • examples/logrus/custom-config
  • examples/logrus/env-config
  • examples/logrus/file-output
  • examples/logrus/json-format
  • examples/logrus/multi-output
  • examples/showcase

About

Better-looking logs for Go. Styled tags, aligned gutters, and multi-line caller info. Built for Logrus.

Resources

License

Stars

Watchers

Forks

Languages