An golang log lib, supports tracking and level, wrap by standard log lib

Logex

Build Status GoDoc Join the chat at https://gitter.im/go-logex/logex

An golang log lib, supports tracing and level, wrap by standard log lib

How To Get

shell

go get gopkg.in/logex.v1

source code

import "gopkg.in/logex.v1" // package name is logex

func main() {
  logex.Info("Hello!")
}

Level

import "gopkg.in/logex.v1"

func main() {
  logex.Println("")
  logex.Debug("debug staff.") // Only show if has an "DEBUG" named env variable(whatever value).
  logex.Info("info")
  logex.Warn("")
  logex.Fatal("") // also trigger exec "os.Exit(1)"
  logex.Error(err) // print error
  logex.Struct(obj) // print objs follow such layout "%T(%+v)"
  logex.Pretty(obj) // print objs as JSON-style, more readable and hide non-publish properties, just JSON
}

Extendability

source code

type MyStruct struct {
  BiteMe bool
}

may change to

type MyStruct struct {
  BiteMe bool
  logex.Logger // just this
}

func main() {
  ms := new(MyStruct)
  ms.Info("woo!")
}

Runtime Tracing

All log will attach theirs stack info. Stack Info will shown by an layout, {packageName}.{FuncName}:{FileName}:{FileLine}

package main

import "gopkg.in/logex.v1"

func test() {
	logex.Pretty("hello")
}

func main() {
	test()
}

response

2014/10/10 15:17:14 [main.test:testlog.go:6][PRETTY] "hello"

Error Tracing

You can trace an error if you want.

package main

import (
	"gopkg.in/logex.v1"
	"os"
)

func openfile() (*os.File, error) {
	f, err := os.Open("xxx")
	if err != nil {
		err = logex.Trace(err)
	}
	return f, err
}

func test() error {
	f, err := openfile()
	if err != nil {
		return logex.Trace(err)
	}
	f.Close()
	return nil
}

func main() {
	err := test()
	if err != nil {
		logex.Error(err)
		return
	}
	logex.Info("test success")
}

response

2014/10/10 15:22:29 [main.main:testlog.go:28][ERROR] [main.openfile:11;main.test:19] open xxx: no such file or directory
Owner
Similar Resources

a lightweight, high-performance, out-of-the-box logging library that relies solely on the Go standard library

English | δΈ­ζ–‡ olog olog is a lightweight, high-performance, out-of-the-box logging library that relies solely on the Go standard library. Support outpu

Apr 12, 2023

An open-source and enterprise-level monitoring system.

 An open-source and enterprise-level monitoring system.

Falcon+ Documentations Usage Open-Falcon API Prerequisite Git = 1.7.5 Go = 1.6 Getting Started Docker Please refer to ./docker/README.md. Build from

Jan 1, 2023

A simple re-creation of the first level for Space Invaders using Go and SDL-2.

A simple re-creation of the first level for Space Invaders using Go and SDL-2.

Space Invaders Go Written in Go using SDL2 Usage This application is a sample first level for a re-creation of Space Invaders. The structure of the pr

Feb 27, 2022

Sand is the next, versatile, high-level compiled or interpreted language that's easy to learn and performant to run.

Sand is the newest, dynamically typed, interpreted programming language. Table of Contents History Project Stats History Sand was created as part of @

Mar 13, 2022

πŸ“ πŸͺ΅ A minimal level based logging library for Go

slogx A minimal level based logging library for Go. Installation Example Usage Logger Log Level Format Output Contribute License Installation go get g

May 23, 2022

Goimportcycle - a tool to visualize Go imports resolved to the file level

Goimportcycle - a tool to visualize Go imports resolved to the file level

Go Import Cycle goimportcycle is a tool to visualize Go imports resolved to the

Dec 8, 2022

Excel binding to struct written in Go.(Only supports Go1.18+)

exl Excel binding to struct written in Go.(Only supports Go1.18+) usage Read Excel package main import ( "fmt" "github.com/go-the-way/exl" ) type

Dec 21, 2022

Simple log parser written in Golang

Simple log parser written in Golang

Oct 31, 2021

Self-use log encapsulation for golang

package app import "github.com/restoflife/log" func Init() { log.Ne

Dec 29, 2021
Comments
  • Tag a new version with a LICENSE

    Tag a new version with a LICENSE

    It would be great if a new version was tagged since LICENSE was added so users with license checkers can use this dependency (transiently or otherwise) without going off-tag

  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    go-logex/logex now has a Chat Room on Gitter

    @chzyer has just created a chat room. You can visit it here: https://gitter.im/go-logex/logex.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

  • Test failure with Golang 1.12-0.rc1

    Test failure with Golang 1.12-0.rc1

    + go test -buildmode pie -compiler gc -ldflags '-extldflags '\''-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '\'''
    --------
     2019/02/20 18:34:38 [logex.test:logex_test.go:19]aa
    2019/02/20 18:34:38 [logex.TestLogex:logex_test.go:42][INFO] b
    2019/02/20 18:34:38 [logex.test:logex_test.go:21][INFO] c
    2019/02/20 18:34:38 [logex.TestLogex:logex_test.go:42][ERROR] ec
    2019/02/20 18:34:38 [logex.(*S).hello:logex_test.go:11][WARN] warn in hello
    2019/02/20 18:34:38 [logex.TestLogex:logex_test.go:42][STRUCT] *logex.S(&{Logger:{depth:0 reqid: Logger:<nil>}}), int(1), string(), bool(false)
    --- FAIL: TestLogex (0.00s)
        logex_test.go:58: except .test:logex_test.go:20][INFO] b not found
    FAIL
    exit status 1
    FAIL	github.com/chzyer/logex	0.005
    

    The line numbers seem to have changed from 20 to 42 in the test output.

Log-server - Implement log server for gwaylib/log/adapter/rmsq

Implement server of github.com/gwaylib/log Base on https://github.com/gwaycc/lserver Build . env.sh cd cmd/web go build Deploy Install supd(Debian sy

Jan 3, 2022
This package enables json output, level logging and so on to standard go logger.

logplug This package enables json output, level logging and so on to standard logger. Usage log.SetOutput(logplug.NewJSONPlug(os.Stderr, logplug.LogF

Dec 27, 2021
Multi-level logger based on go std log

mlog the mlog is multi-level logger based on go std log. It is: Simple Easy to use NOTHING ELSE package main import ( log "github.com/ccpaging/lo

May 18, 2022
Distributed-Log-Service - Distributed Log Service With Golang
Distributed-Log-Service - Distributed Log Service With Golang

Distributed Log Service This project is essentially a result of my attempt to un

Jun 1, 2022
Log-analyzer - Log analyzer with golang

Log Analyzer what do we have here? Objective Installation and Running Applicatio

Jan 27, 2022
Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer for Nginx.
Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer for Nginx.

Nginx-Log-Analyzer is a lightweight (simplistic) log analyzer, used to analyze Nginx access logs for myself.

Nov 29, 2022
Simple and configurable Logging in Go, with level, formatters and writers

go-log Logging package similar to log4j for the Golang. Support dynamic log level Support customized formatter TextFormatter JSONFormatter Support mul

Sep 26, 2022
Go-metalog - Standard API for structured logging

Metalog is a standard API for structured logging and adapters for its implementa

Jan 20, 2022
Monitor pipe progress via output to standard error.

Pipe Monitor Monitor pipe progress via output to standard error. Similar to functionality provided by the Pipe Viewer (pv) command, except this comman

Nov 14, 2022
Gin adapter for standard net/http middleware

midgin An adapter to use standard net/http middleware in Gin. Overview Gin is a very capable web framework, but it does not directly support standard

Feb 12, 2022