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

Overview

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
You might also like...
 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

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

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 @

📝 🪵 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

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

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

Simple log parser written in Golang

Simple log parser written in Golang

Self-use log encapsulation for golang

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

Log to cloud object storage for golang. Zap extension.

cos-logger Log to cloud object storage for golang implemented as io.Writer. Use it as a plugin/extension to uber-go/zap logger Configure logger and ad

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

    opened by howardjohn 2
  • 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.

    opened by gitter-badger 0
  • 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.

    opened by eclipseo 2
Releases(v1.2.1)
Owner
chzyer
Gopher
chzyer
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

null 0 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

Koumei Mikuni 0 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

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

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

Hamza Yusuff 6 Jun 1, 2022
Log-analyzer - Log analyzer with golang

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

Lawrence Agbani 0 Jan 27, 2022
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.

Mao Mao 28 Oct 26, 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

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

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

Kirill 4 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

SoftCoil Development 6 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

Mark Blythe 0 Feb 12, 2022