Popularity
4.7
Growing
Activity
7.0
-
128
6
11

Programming language: Go
License: MIT License
Tags: Logging    
Latest version: v1.5.1

glg alternatives and similar packages

Based on the "Logging" category.
Alternatively, view glg alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of glg or a related project?

Add another 'Logging' Package

README

License: MIT release CircleCI codecov Codacy Badge Go Report Card GolangCI Go Walker GoDoc DepShield Badge FOSSA Status

glg is simple golang logging library

Requirement

Go 1.11

Installation

go get github.com/kpango/glg

Example

package main

import (
    "net/http"
    "time"

    "github.com/kpango/glg"
)

// NetWorkLogger sample network logger
type NetWorkLogger struct{}

func (n NetWorkLogger) Write(b []byte) (int, error) {
    // http.Post("localhost:8080/log", "", bytes.NewReader(b))
    http.Get("http://127.0.0.1:8080/log")
    glg.Success("Requested")
    glg.Infof("RawString is %s", glg.RawString(b))
    return 1, nil
}

func main() {

    // var errWriter io.Writer
    // var customWriter io.Writer
    infolog := glg.FileWriter("/tmp/info.log", 0666)

    customTag := "FINE"
    customErrTag := "CRIT"

    errlog := glg.FileWriter("/tmp/error.log", 0666)
    defer infolog.Close()
    defer errlog.Close()
    glg.Get().
        SetMode(glg.BOTH). // default is STD
        // DisableColor().
        // SetMode(glg.NONE).
        // SetMode(glg.WRITER).
        // SetMode(glg.BOTH).
        // InitWriter().
        // AddWriter(customWriter).
        // SetWriter(customWriter).
        // AddLevelWriter(glg.LOG, customWriter).
        // AddLevelWriter(glg.INFO, customWriter).
        // AddLevelWriter(glg.WARN, customWriter).
        // AddLevelWriter(glg.ERR, customWriter).
        // SetLevelWriter(glg.LOG, customWriter).
        // SetLevelWriter(glg.INFO, customWriter).
        // SetLevelWriter(glg.WARN, customWriter).
        // SetLevelWriter(glg.ERR, customWriter).
        AddLevelWriter(glg.INFO, infolog).                         // add info log file destination
        AddLevelWriter(glg.ERR, errlog).                           // add error log file destination
        AddStdLevel(customTag, glg.STD, false).                    //user custom log level
        AddErrLevel(customErrTag, glg.STD, true).                  // user custom error log level
        SetLevelColor(glg.TagStringToLevel(customTag), glg.Cyan).  // set color output to user custom level
        SetLevelColor(glg.TagStringToLevel(customErrTag), glg.Red) // set color output to user custom level

    glg.Info("info")
    glg.Infof("%s : %s", "info", "formatted")
    glg.Log("log")
    glg.Logf("%s : %s", "info", "formatted")
    glg.Debug("debug")
    glg.Debugf("%s : %s", "info", "formatted")
    glg.Warn("warn")
    glg.Warnf("%s : %s", "info", "formatted")
    glg.Error("error")
    glg.Errorf("%s : %s", "info", "formatted")
    glg.Success("ok")
    glg.Successf("%s : %s", "info", "formatted")
    glg.Fail("fail")
    glg.Failf("%s : %s", "info", "formatted")
    glg.Print("Print")
    glg.Println("Println")
    glg.Printf("%s : %s", "printf", "formatted")
    glg.CustomLog(customTag, "custom logging")
    glg.CustomLog(customErrTag, "custom error logging")

    glg.Get().AddLevelWriter(glg.DEBG, NetWorkLogger{}) // add info log file destination

    http.Handle("/glg", glg.HTTPLoggerFunc("glg sample", func(w http.ResponseWriter, r *http.Request) {
        glg.New().
        AddLevelWriter(glg.Info, NetWorkLogger{}).
        AddLevelWriter(glg.Info, w).
        Info("glg HTTP server logger sample")
    }))

    http.ListenAndServe("port", nil)

    // fatal logging
    glg.Fatalln("fatal")
}

Benchmarks

Contribution

  1. Fork it ( https://github.com/kpango/glg/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

kpango

LICENSE

glg released under MIT license, refer LICENSE file.
FOSSA Status


*Note that all licence references and agreements mentioned in the glg README section above are relevant to that project's source code only.