Seelog is a native Go logging library that provides flexible asynchronous dispatching, filtering, and formatting.

Seelog

Seelog is a powerful and easy-to-learn logging framework that provides functionality for flexible dispatching, filtering, and formatting log messages. It is natively written in the Go programming language.

Build Status

Features

  • Xml configuring to be able to change logger parameters without recompilation
  • Changing configurations on the fly without app restart
  • Possibility to set different log configurations for different project files and functions
  • Adjustable message formatting
  • Simultaneous log output to multiple streams
  • Choosing logger priority strategy to minimize performance hit
  • Different output writers
    • Console writer
    • File writer
    • Buffered writer (Chunk writer)
    • Rolling log writer (Logging with rotation)
    • SMTP writer
    • Others... (See Wiki)
  • Log message wrappers (JSON, XML, etc.)
  • Global variables and functions for easy usage in standalone apps
  • Functions for flexible usage in libraries

Quick-start

package main

import log "github.com/cihub/seelog"

func main() {
    defer log.Flush()
    log.Info("Hello from Seelog!")
}

Installation

If you don't have the Go development environment installed, visit the Getting Started document and follow the instructions. Once you're ready, execute the following command:

go get -u github.com/cihub/seelog

IMPORTANT: If you are not using the latest release version of Go, check out this wiki page

Documentation

Seelog has github wiki pages, which contain detailed how-tos references: https://github.com/cihub/seelog/wiki

Examples

Seelog examples can be found here: seelog-examples

Issues

Feel free to push issues that could make Seelog better: https://github.com/cihub/seelog/issues

Changelog

  • v2.6 : Config using code and custom formatters
    • Configuration using code in addition to xml (All internal receiver/dispatcher/logger types are now exported).
    • Custom formatters. Check wiki
    • Bugfixes and internal improvements.
  • v2.5 : Interaction with other systems. Part 2: custom receivers
    • Finished custom receivers feature. Check wiki
    • Added 'LoggerFromCustomReceiver'
    • Added 'LoggerFromWriterWithMinLevelAndFormat'
    • Added 'LoggerFromCustomReceiver'
    • Added 'LoggerFromParamConfigAs...'
  • v2.4 : Interaction with other systems. Part 1: wrapping seelog
    • Added configurable caller stack skip logic
    • Added 'SetAdditionalStackDepth' to 'LoggerInterface'
  • v2.3 : Rethinking 'rolling' receiver
    • Reimplemented 'rolling' receiver
    • Added 'Max rolls' feature for 'rolling' receiver with type='date'
    • Fixed 'rolling' receiver issue: renaming on Windows
  • v2.2 : go1.0 compatibility point [go1.0 tag]
    • Fixed internal bugs
    • Added 'ANSI n [;k]' format identifier: %EscN
    • Made current release go1 compatible
  • v2.1 : Some new features
    • Rolling receiver archiving option.
    • Added format identifier: %Line
    • Smtp: added paths to PEM files directories
    • Added format identifier: %FuncShort
    • Warn, Error and Critical methods now return an error
  • v2.0 : Second major release. BREAKING CHANGES.
    • Support of binaries with stripped symbols
    • Added log strategy: adaptive
    • Critical message now forces Flush()
    • Added predefined formats: xml-debug, xml-debug-short, xml, xml-short, json-debug, json-debug-short, json, json-short, debug, debug-short, fast
    • Added receiver: conn (network connection writer)
    • BREAKING CHANGE: added Tracef, Debugf, Infof, etc. to satisfy the print/printf principle
    • Bug fixes
  • v1.0 : Initial release. Features:
    • Xml config
    • Changing configurations on the fly without app restart
    • Contraints and exceptions
    • Formatting
    • Log strategies: sync, async loop, async timer
    • Receivers: buffered, console, file, rolling, smtp
Owner
Seelog project repository
Seelog project repository
Comments
  • custom dispatcher / AppEngine

    custom dispatcher / AppEngine

    I want to use seelog in a package that I want to use on AppEngine and other apps. I would like to set a logger like explained in https://github.com/cihub/seelog/wiki/Writing-libraries-with-Seelog

    I would like to set a logger with a custom dispatcher which writes to the appengine.Context.Criticalf/Errorf/Warningf/Infof/Debugf() methods.

    Is there a way to provide a custom dispatcher to a logger?

  • Not all messages are written to log with multiple processes logging to same file

    Not all messages are written to log with multiple processes logging to same file

    I have a program that logs in high volume to a single log file. If I start more than one of these, only some messages reach the log. For example, with two processes, approximately 1/2 the messages reach the log. With three, 2/3. With four, 3/4.

    Note that these are multiple processes, not a single process using channels. It happens even if I flush after each message.

    I suspect this is some kind of lock contention problem in the library. I am using the default logging behavior, and the newest release via go get github.com/cihub/seelog.

    When I swapped out seelog with simply writing bytes to os.File, it works as expected: all messages are written to the log.

  • How to create custom json log message format?

    How to create custom json log message format?

    Is the below log message:-

    {"level":"info", "message" : "hello world", "tId":"T12345", "reqId" : "R3232", "appId": "Discovery", "sessionId": "12325", "userId":"AB3435", "stackTraces" : ["Call Trace 1", "Call Trace 2"],  "timestamp" : "2015-07-09T18:00:00.875Z"}
    

    where along with message, tId, reqId appId, sessionId and userId will be passed by caller.

    Is it possible to achieve this using custom formatter?

  • connection reset by peer

    connection reset by peer

    Hello,

    (opening a separate issue for connection)

    Without using reconnectonmsg="true" in client config file there is an error in seelog "connection reset by peer"

    16:02:40 2012-08-29 [CRITICAL] testmessage 16:02:40 2012-08-29 [INFO] testinfomessage Seelog error: write tcp 127.0.0.1:8525: connection reset by peer 16:02:40 2012-08-29 [CRITICAL] testmessage 16:02:40 2012-08-29 [INFO] testinfomessage Seelog error: write tcp 127.0.0.1:8525: connection reset by peer 16:02:40 2012-08-29 [CRITICAL] testmessage 16:02:40 2012-08-29 [INFO] testinfomessage Seelog error: write tcp 127.0.0.1:8525: connection reset by peer 16:02:40 2012-08-29 [CRITICAL] testmessage 16:02:40 2012-08-29 [INFO] testinfomessage Seelog error: write tcp 127.0.0.1:8525: connection reset by peer

    Server code: package main

    import ( "fmt" "github.com/cihub/seelog" "log" "net" "time" ) var connections int

    func handleClient(c net.Conn) { connections += 1 defer c.Close() }

    func showprogress(){ var curr int c := time.Tick(1 * time.Second) for now := range c { fmt.Println(now) fmt.Println(connections-curr) curr = connections }

    }

    func main() { logger, err := seelog.LoggerFromConfigAsFile("seelog-server.xml")

    if err != nil {
        log.Fatal(err)
    }
    seelog.UseLogger(logger)
    ln, err := net.Listen("tcp", ":8525")
    if err != nil {
        seelog.Error(err)
    }
    
    go showprogress()
    for {
        conn, err := ln.Accept()
        fmt.Printf("%d\r", connections)
        if err != nil {
            seelog.Error(err)
        }
        go handleClient(conn)
    }
    

    }

    If "defer c.Close()" is not present logging will freeze after few dozen of lines. Can you please take a look on the issue?

    (as a note to the previous issue, now, after using the "log" solution, the server logs between 800-1300 messages per second) Thanks.

  • fi.Mode().IsRegular undefined on OSX 10.8.2

    fi.Mode().IsRegular undefined on OSX 10.8.2

    /usr/local/go/src/pkg/github.com/cihub/seelog/internals_fsutils.go:208: fi.Mode().IsRegular undefined (type os.FileMode has no field or method IsRegular)

  • questions for session base logging

    questions for session base logging

    Hi,

    I'm integrating seelog with my http service. I would like to debug with a 'request id' per request/session.

    My concept is, once http server receive a request, it will generate a UUID as the request id for this session. All debug log will include this UUID for identifying till the end of request.

    I've read a solution at Custom receivers - Scenario 3.2: Custom receivers with context, but I still had a concern there, please advice.

    The concern is, when we instance the 'logger-per-request' log in HttpHandler per request (means it might be parallel), should I take care of the performance and any potential issue()? I list cases for example:

    • create new logger with per-request-context every time might cause too many resource?
    • ReplaceLogger might be called at the middle of other session, does it cause other request use the incorrect request id? (one session might call debug() many times)
    • is that possible we log information via some variable in runtime?

    Thank you, seelog rock! :)

  • Add support for syslog formatting and TLS

    Add support for syslog formatting and TLS

    With this commit seelog can be used to log to syslog, optionally over TLS (e.g. to rsyslog) so logs can be transmitted directly to a central log server.

    Below is an example configuration logging over a TLS connection, using syslog facility local4 (=20).

    <outputs formatid="syslog">
      <filter levels="info,warn,error,critical">
        <conn net="tcp4" addr="server.address:5514" useTLS="true" insecureSkipVerify="true" />
      </filter>
    </outputs>
    <formats>
      <format id="syslog" format="&lt;%PRI(20)&gt;1 %Date(2006-01-02T15:04:05Z07:00) myhostname myappname PROCID MSGID - %Msg%n"/>
    </formats>
    

    Use "-" for the PROCID and MSGID if they are unknown, refer to http://tools.ietf.org/html/rfc5424 for more information about the format.

  • fix: weird path, and renaming error

    fix: weird path, and renaming error

    1. weird path:

      // fix: weird path: \psf\gopath\src\github.com\cihub\seelog/\psf\gopath\src\github.com\cihub\seelog\format_test.go

    2. renaming error while log rotate:

      // on windows service. (tracked with systeminternal suite.) only our service (single process), // SYSTEM and explorer.exe are using the log file. but still, an error will be raised while // renaming it: // // The process cannot access the file because it is being used by another process. // // I consulted with some one who implemented windows service with python also encountered the // some issue. then find out their solution seems pretty stable, although it's not the // ideal way to fix the issue.

  • Rolling file writer by date does not write in the original file

    Rolling file writer by date does not write in the original file

    Hello !

    Given the following configuration:

    <seelog type="sync" >
        <outputs formatid="main">
                <rollingfile type="date" datepattern="2006-02-02" filename="/var/log/logByDate.log" />
                <rollingfile type="size" maxsize="5000" filename="/var/log/logBySize.log" />
        </outputs>
        <formats>
            <format id="main" format="%Date(2006 Jan 02/3:04:05.000000000 PM MST) [%Level] %Msg%n"/>
        </formats>
    </seelog>
    

    Seelog will write current logs in logBySize.log as expected, but not in logByDate.log. Instead, it will write in the rolling file of the day: logByDate.log.2016-04-04. I suppose this is a bug, right ?

  • 'Max rolls' feature for 'rolling' receiver with type='date' do not work for me.

    'Max rolls' feature for 'rolling' receiver with type='date' do not work for me.

    'Max rolls' feature for 'rolling' receiver with type='date' do not work for me. my code is follow.

        testConfig := `
    <seelog>
        <outputs>
            <rollingfile type="date" filename="./log/roll.log" maxrolls="5" datepattern="02.01.2006"/>
        </outputs>
    </seelog>
    `
        logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig))
        log.ReplaceLogger(logger)
        fmt.Println("Rolling file writer")
        for i := 0; i < 10000; i++ {
            log.Tracef("%d", i)
            log.Infof("%d", i)
        }
    

    image

    the value of 'maxrolls' is 5. it should at most generate five files but there are six log file. Is wrong the usage i used to log? How can i fix the problem.

  • Question: how to wrap seelog in own package?

    Question: how to wrap seelog in own package?

    Hi there,

    I want to use seelog in a mixed hosting environment: appengine and standalone.

    Since appengine has its own logging mechanism - attached to the Context interface - I want to have a custom log package that abstracts this away.

    But when I create a struct and call the Info method which delegates to seelog, I see this

    [2013-09-05 23:50:33] [INFO] [101loops/log.(*Logger).Info] ...
    

    instead of

    [2013-09-05 23:50:33] [INFO] [101loops/module.start] ...
    

    How can I make seelog log the correct location when being wrapped?

  • Test failure: TestCustomFormatterRegistration

    Test failure: TestCustomFormatterRegistration

    go version: go version go1.18.5 linux/amd64

    Testing    in: /builddir/build/BUILD/seelog-f561c5e57575bb1e0a2167028b7339b3a8d16fb4/_build/src
             PATH: /builddir/build/BUILD/seelog-f561c5e57575bb1e0a2167028b7339b3a8d16fb4/_build/bin:/builddir/.local/bin:/builddir/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
           GOPATH: /builddir/build/BUILD/seelog-f561c5e57575bb1e0a2167028b7339b3a8d16fb4/_build:/usr/share/gocode
      GO111MODULE: off
          command: go test -buildmode pie -compiler gc -ldflags " -X github.com/cihub/seelog/version.commit=f561c5e57575bb1e0a2167028b7339b3a8d16fb4 -X github.com/cihub/seelog/version=2.6 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/seelog-f561c5e57575bb1e0a2167028b7339b3a8d16fb4/.package_note-golang-github-cihub-seelog-2.6-1.20220804gitf561c5e.fc36.x86_64.ld '"
          testing: github.com/cihub/seelog
    github.com/cihub/seelog
    --- FAIL: TestCustomFormatterRegistration (0.00s)
        format_test.go:235: Custom formatter: invalid output. Expected: 'test TEST github.com/cihub/seelog.TestCustomFormatterRegistration TEST 123'. Got: 'test TEST github.com/cihub/seelog.currentContext TEST 123'
    
  • No Sharing parameter in XML. Assuming sharing false

    No Sharing parameter in XML. Assuming sharing false

    I am trying to configure two identical custom CloudWatch receivers, one to write errors to a log stream, the second instance writes all log entries to a second log stream. The output I get from seelog at start up is "No Sharing parameter in XML. Assuming sharing false" - Wiki does not mention "sharing parameter" - can details be added to Wiki so I know syntax to turn sharing to "true"?

  • iotest_test.go unit test failture

    iotest_test.go unit test failture

    func TestTempFile(t *testing.T) { f, cleanup := TempFile(t) if _, err := f.Write([]byte("test")); err != nil { t.Fatalf("temp file not writable: %v", err) } cleanup() // Confirm closed if err := f.Close(); err != syscall.EINVAL { t.Errorf("temp file was not closed by cleanup func") }


    if call file.Close() again, it probably return error "file already closed" rather than "syscall.EINVAL"

  •  bus error

    bus error

    my program is running in K8S,and it core dump once a week to three weeks.

    //main.go
    func main() {
            initLog()
           ....
           ....
    } 
    
    func initLog() {
            logger, err := seelog.LoggerFromConfigAsFile(startcfg.GetWSerLogPath())
            if err != nil {
                    panic(err)
            }
            if err = seelog.ReplaceLogger(logger); err != nil {
                    panic(err)
            }
    }
    
    unexpected fault address 0x67f8e0
    fatal error: fault
    [signal SIGBUS: bus error code=0x2 addr=0x67f8e0 pc=0x67f8e0]
    
    goroutine 83 [running]:
    runtime.throw(0x9096e7, 0x5)
            /usr/local/go/src/runtime/panic.go:608 +0x72 fp=0xc000505b98 sp=0xc000505b68 pc=0x42c5a2
    runtime.sigpanic()
            /usr/local/go/src/runtime/signal_unix.go:387 +0x2d7 fp=0xc000505be8 sp=0xc000505b98 pc=0x441127
    github.com/kingbuffalo/seelog.(*rollTimeFileTailsSlice).Len(0xc000551b60, 0xc000551b60)
            <autogenerated>:1 fp=0xc000505bf0 sp=0xc000505be8 pc=0x67f8e0
    sort.Sort(0x987f80, 0xc000551b60)
            /usr/local/go/src/sort/sort.go:217 +0x31 fp=0xc000505c30 sp=0xc000505bf0 pc=0x55ce31
    github.com/kingbuffalo/seelog.(*rollingFileWriterTime).sortFileRollNamesAsc(0xc0001f5440, 0xc0003b0400, 0x1e, 0x20, 0x1, 0xc000505d68, 0xa, 0x20, 0x0)
            /opt/applications/go/pkg/mod/github.com/kingbuffalo/[email protected]/writers_rollingfilewriter.go:739 +0xc8 fp=0xc000505cb0 sp=0xc000505c30 pc=0x678878
    github.com/kingbuffalo/seelog.(*rollingFileWriter).getSortedLogHistory(0xc000274000, 0x0, 0x0, 0xa, 0xc000505e40, 0xa)
            /opt/applications/go/pkg/mod/github.com/kingbuffalo/[email protected]/writers_rollingfilewriter.go:297 +0x129 fp=0xc000505e08 sp=0xc000505cb0 pc=0x675949
    github.com/kingbuffalo/seelog.(*rollingFileWriter).roll(0xc000274000, 0x926001, 0xc000274080)
            /opt/applications/go/pkg/mod/github.com/kingbuffalo/[email protected]/writers_rollingfilewriter.go:523 +0x7d fp=0xc000505ed8 sp=0xc000505e08 pc=0x6771fd
    github.com/kingbuffalo/seelog.(*rollingFileWriter).Write(0xc000274000, 0xc000276000, 0x38d, 0x2710, 0x0, 0x0, 0x0)
            /opt/applications/go/pkg/mod/github.com/kingbuffalo/[email protected]/writers_rollingfilewriter.go:561 +0x172 fp=0xc000505f28 sp=0xc000505ed8 pc=0x677752
    bufio.(*Writer).Flush(0xc000206bc0, 0x926088, 0xc000212350)
            /usr/local/go/src/bufio/bufio.go:575 +0x75 fp=0xc000505f88 sp=0xc000505f28 pc=0x4cff55
    github.com/kingbuffalo/seelog.(*bufferedWriter).flushBuffer(0xc0001f5470)
            /opt/applications/go/pkg/mod/github.com/kingbuffalo/[email protected]/writers_bufferedwriter.go:146 +0x6b fp=0xc000505fb0 sp=0xc000505f88 pc=0x67432b
    github.com/kingbuffalo/seelog.(*bufferedWriter).flushPeriodically(0xc0001f5470)
            /opt/applications/go/pkg/mod/github.com/kingbuffalo/[email protected]/writers_bufferedwriter.go:154 +0x60 fp=0xc000505fd8 sp=0xc000505fb0 pc=0x6743c0
    runtime.goexit()
            /usr/local/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc000505fe0 sp=0xc000505fd8 pc=0x4589e1
    created by github.com/kingbuffalo/seelog.NewBufferedWriter
            /opt/applications/go/pkg/mod/github.com/kingbuffalo/[email protected]/writers_bufferedwriter.go:76 +0x16c
    
Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go
Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go

Tiny structured logging abstraction or facade for various logging libraries, allowing the end user to plug in the desired logging library in main.go.

Dec 7, 2022
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be
FactorLog is a logging infrastructure for Go that provides numerous logging functions for whatever your style may be

FactorLog FactorLog is a fast logging infrastructure for Go that provides numerous logging functions for whatever your style may be. It could easily b

Aug 3, 2022
Fully asynchronous, structured, pluggable logging for Go.

logr Logr is a fully asynchronous, contextual logger for Go. It is very much inspired by Logrus but addresses two issues: Logr is fully asynchronous,

Dec 28, 2022
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs

gomol Gomol (Go Multi-Output Logger) is an MIT-licensed structured logging library for Go. Gomol grew from a desire to have a structured logging libra

Sep 26, 2022
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Dec 14, 2022
Package logging implements a logging infrastructure for Go
Package logging implements a logging infrastructure for Go

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Nov 10, 2021
Go implementation of systemd Journal's native API for logging

journald Package journald offers Go implementation of systemd Journal's native API for logging. Key features are: based on a connection-less socket wo

Dec 23, 2022
Logger - Go language is interface-oriented to implement an asynchronous log writing program

logger日志库 1、安装 go get github.com/staryjie/logger@latest 2、使用 示例: package main import ( "github.com/staryjie/logger" "time" ) func initLogger(name,

Jan 4, 2022
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
A flexible process data collection, metrics, monitoring, instrumentation, and tracing client library for Go
A flexible process data collection, metrics, monitoring, instrumentation, and tracing client library for Go

Package monkit is a flexible code instrumenting and data collection library. See documentation at https://godoc.org/gopkg.in/spacemonkeygo/monkit.v3 S

Dec 14, 2022
Simple and blazing fast lockfree logging library for golang
Simple and blazing fast lockfree logging library for golang

glg is simple golang logging library Requirement Go 1.11 Installation go get github.com/kpango/glg Example package main import ( "net/http" "time"

Nov 28, 2022
The Simplest and worst logging library ever written

gologger A Simple Easy to use go logger library. Displays Colored log into console in any unix or windows platform. You can even store your logs in fi

Sep 26, 2022
Hierarchical, leveled, and structured logging library for Go

spacelog Please see http://godoc.org/github.com/spacemonkeygo/spacelog for info License Copyright (C) 2014 Space Monkey, Inc. Licensed under the Apach

Apr 27, 2021
Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.
Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Noodlog Summary Noodlog is a Golang JSON parametrized and highly configurable logging library. It allows you to: print go structs as JSON messages; pr

Oct 27, 2022
Logging library for Golang

GLO Logging library for Golang Inspired by Monolog for PHP, severity levels are identical Install go get github.com/lajosbencz/glo Severity levels Deb

Sep 26, 2022
Minimalistic logging library for Go.
Minimalistic logging library for Go.

logger Minimalistic logging library for Go. Blog Post Features: Advanced output filters (package and/or level) Attributes Timers for measuring perform

Nov 16, 2022
A pure Go contextual logging library with "batteries included"

Cue Overview Cue implements contextual logging with "batteries included". It has thorough test coverage and supports logging to stdout/stderr, file, s

Sep 16, 2019
Golang logging library
Golang logging library

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Dec 27, 2022
Minimal structured logging library for Go
Minimal structured logging library for Go

slog slog is a minimal structured logging library for Go. Install go get cdr.dev/slog Features Minimal API First class context.Context support First c

Dec 29, 2022