Coder Social home page Coder Social logo

pieterclaerhout / go-log Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 5.0 78 KB

A logging library with strack traces, object dumping and optional timestamps

License: Apache License 2.0

Go 100.00%
golang golang-library golang-package logging stacktrace dumping

go-log's Introduction

go-log

Build Status Go Report Card Documentation license GitHub version GitHub issues

This is a Golang library with logging related functions which I use in my different projects.

Usage

package main

import (
    "github.com/pieterclaerhout/go-log"
)

func main() {

    log.DebugMode = true
    log.PrintTimestamp = true
    log.PrintColors = true
    log.TimeFormat = "2006-01-02 15:04:05.000"

    myVar := map[string]string{"hello": "world"}

    log.Debug("arg1", "arg2")
    log.Debugf("arg1 %d", 1)
    log.DebugDump(myVar, "prefix")
    log.DebugSeparator("title")

    log.Info("arg1", "arg2")
    log.Infof("arg1 %d", 1)
    log.InfoDump(myVar, "prefix")
    log.InfoSeparator("title")

    log.Warn("arg1", "arg2")
    log.Warnf("arg1 %d", 1)
    log.WarnDump(myVar, "prefix")
    log.WarnSeparator("title")

    log.Error("arg1", "arg2")
    log.Errorf("arg1 %d", 1)
    log.ErrorDump(myVar, "prefix")
    log.ErrorSeparator("title")

    log.Fatal("arg1", "arg2")
    log.Fatalf("arg1 %d", 1)

    err1 := funcWithError()
    log.StackTrace(err1)

    err2 := funcWithError()
    log.CheckError(err2)

}

Environment variables

The defaults are taken from the environment variables:

  • DEBUG: log.DebugMode
  • PRINT_TIMESTAMP: log.PrintTimestamp

go-log's People

Contributors

dependabot[bot] avatar pieterclaerhout avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-log's Issues

Race condition during writing

==================
WARNING: DATA RACE
Write at 0x00c0001364d8 by goroutine 7:
  github.com/fatih/color.(*Color).EnableColor()
      github.com/fatih/[email protected]/color.go:386 +0x173
  github.com/pieterclaerhout/go-log.printColoredMessage()
      github.com/pieterclaerhout/[email protected]/logger_internal.go:76 +0x12f
  github.com/pieterclaerhout/go-log.printMessage()
      github.com/pieterclaerhout/[email protected]/logger_internal.go:61 +0xd0
  github.com/pieterclaerhout/go-log.Info()
      github.com/pieterclaerhout/[email protected]/logger.go:109 +0x79
  github.com/pieterclaerhout/go-geoip/v2/serverapp.dbUpdaterJob.run()
      github.com/pieterclaerhout/go-geoip/v2/serverapp/job_download.go:17 +0x9a

Previous write at 0x00c0001364d8 by main goroutine:
  github.com/fatih/color.(*Color).EnableColor()
      github.com/fatih/[email protected]/color.go:386 +0x173
  github.com/pieterclaerhout/go-log.printColoredMessage()
      github.com/pieterclaerhout/[email protected]/logger_internal.go:76 +0x12f
  github.com/pieterclaerhout/go-log.printMessage()
      github.com/pieterclaerhout/[email protected]/logger_internal.go:61 +0xd0
  github.com/pieterclaerhout/go-log.Info()
      github.com/pieterclaerhout/[email protected]/logger.go:109 +0x79
  github.com/pieterclaerhout/go-webserver/v2.(*Server).RunWithApps()
      github.com/pieterclaerhout/go-webserver/[email protected]/server.go:44 +0x6c2
  main.main()
      github.com/pieterclaerhout/go-geoip/v2/cmd/geoip-server/main.go:26 +0x25f

Goroutine 7 (running) created at:
  github.com/pieterclaerhout/go-geoip/v2/serverapp.New()
      github.com/pieterclaerhout/go-geoip/v2/serverapp/serverapp.go:39 +0x4f5
  main.main()
      github.com/pieterclaerhout/go-geoip/v2/cmd/geoip-server/main.go:27 +0x21a
==================

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.