Giter Site home page Giter Site logo

log's People

Contributors

4781121 avatar deankarn avatar madouura avatar sb10 avatar sm3142 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

log's Issues

Every visit add a line ....

log:

kkp-api       | โ‡จ http server started on [::]:1323
kkp-api       | 2019/08/07 17:07:57  DEBUG debug
kkp-api       | 2019/08/07 17:07:57   INFO info
kkp-api       | 2019/08/07 17:07:57 NOTICE notice
kkp-api       | 2019/08/07 17:07:57   WARN warn
kkp-api       | 2019/08/07 17:07:57  ERROR error
kkp-api       | 2019/08/07 17:07:57  ALERT alert
kkp-api       | Detail: rsp: created_at:<seconds:-62135596800 > updated_at:<seconds:-62135596800 > deleted_at:<seconds:-62135596800 >
kkp-api       | {"time":"2019-08-07T17:07:57.543187+08:00","id":"","remote_ip":"172.23.0.1","host":"localhost:11323","method":"GET","uri":"/user/detail","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36","status":200,"error":"","latency":121904600,"latency_human":"121.9046ms","bytes_in":0,"bytes_out":110}
kkp-api       | 2019/08/07 17:07:57   INFO time to run duration=121.403ms
kkp-api       | 2019/08/07 17:08:01  DEBUG debug
kkp-api       | 2019/08/07 17:08:01  DEBUG debug
kkp-api       | 2019/08/07 17:08:01   INFO info
kkp-api       | 2019/08/07 17:08:01   INFO info
kkp-api       | 2019/08/07 17:08:01 NOTICE notice
kkp-api       | 2019/08/07 17:08:01 NOTICE notice
kkp-api       | 2019/08/07 17:08:01   WARN warn
kkp-api       | 2019/08/07 17:08:01   WARN warn
kkp-api       | 2019/08/07 17:08:01  ERROR error
kkp-api       | 2019/08/07 17:08:01  ERROR error
kkp-api       | 2019/08/07 17:08:01  ALERT alert
kkp-api       | 2019/08/07 17:08:01  ALERT alert
kkp-api       | Detail: rsp: created_at:<seconds:-62135596800 > updated_at:<seconds:-62135596800 > deleted_at:<seconds:-62135596800 >
kkp-api       | {"time":"2019-08-07T17:08:01.2394095+08:00","id":"","remote_ip":"172.23.0.1","host":"localhost:11323","method":"GET","uri":"/user/detail","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36","status":200,"error":"","latency":3925600,"latency_human":"3.9256ms","bytes_in":0,"bytes_out":110}
kkp-api       | 2019/08/07 17:08:01   INFO time to run duration=3.8317ms
kkp-api       | 2019/08/07 17:08:01   INFO time to run duration=3.8317ms
kkp-api       | 2019/08/07 17:08:12  DEBUG debug
kkp-api       | 2019/08/07 17:08:12  DEBUG debug
kkp-api       | 2019/08/07 17:08:12  DEBUG debug
kkp-api       | 2019/08/07 17:08:12   INFO info
kkp-api       | 2019/08/07 17:08:12   INFO info
kkp-api       | 2019/08/07 17:08:12   INFO info
kkp-api       | 2019/08/07 17:08:12 NOTICE notice
kkp-api       | 2019/08/07 17:08:12 NOTICE notice
kkp-api       | 2019/08/07 17:08:12 NOTICE notice
kkp-api       | 2019/08/07 17:08:12   WARN warn
kkp-api       | 2019/08/07 17:08:12   WARN warn
kkp-api       | 2019/08/07 17:08:12   WARN warn
kkp-api       | 2019/08/07 17:08:12  ERROR error
kkp-api       | 2019/08/07 17:08:12  ERROR error
kkp-api       | 2019/08/07 17:08:12  ERROR error
kkp-api       | 2019/08/07 17:08:12  ALERT alert
kkp-api       | 2019/08/07 17:08:12  ALERT alert
kkp-api       | 2019/08/07 17:08:12  ALERT alert
kkp-api       | Detail: rsp: created_at:<seconds:-62135596800 > updated_at:<seconds:-62135596800 > deleted_at:<seconds:-62135596800 >
kkp-api       | {"time":"2019-08-07T17:08:12.7423301+08:00","id":"","remote_ip":"172.23.0.1","host":"localhost:11323","method":"GET","uri":"/user/detail","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36","status":200,"error":"","latency":2952500,"latency_human":"2.9525ms","bytes_in":0,"bytes_out":110}
kkp-api       | 2019/08/07 17:08:12   INFO time to run duration=2.7394ms
kkp-api       | 2019/08/07 17:08:12   INFO time to run duration=2.7394ms
kkp-api       | 2019/08/07 17:08:12   INFO time to run duration=2.7394ms

code:

	cLog := console.New(true)
	cLog.SetTimestampFormat("2006/01/02 15:04:05")
	log.AddHandler(cLog, log.AllLevels...)

	// Trace
	defer log.WithTrace().Info("time to run")
	log.Debug("debug")
	log.Info("info")
	log.Notice("notice")
	log.Warn("warn")
	log.Error("error")
	// log.Panic("panic") // this will panic
	log.Alert("alert")
	// log.Fatal("fatal") // this will call os.Exit(1)

Cannot use in a module based project

Essentially, the go.mod definition is malformed and causes projects attempting to consume the module by importing the latest version using import "github.com/go-playground/log/v7". Also, the sub-modules need to be updated to use the proper import path. Otherwise they will be importing the v6.3.0 version of the module.

Help Wanted - adding more log Handlers

Hello All,

I could definitely use some help adding even more log Handlers for other services such as Graylog, Email, InfluxDB, ElasticSearch... list goes on.

Thanks in Advance for anyone whom can help! ๐Ÿ‘

v8 How to turn off the default output

package main

import (
"bytes"
"fmt"

"github.com/go-playground/log/v8"

)

type CustomHandler struct {
}

func (c *CustomHandler) Log(e log.Entry) {
b := new(bytes.Buffer)
b.Reset()
b.WriteString(e.Message)
fmt.Println("-------------------- " + b.String())
}

func main() {
log.RedirectGoStdLog(true)
cLog := new(CustomHandler)
log.AddHandler(cLog, log.AllLevels...)
log.Debug("debug")
log.Info("info")
log.Notice("notice")
log.Warn("warn")
log.Error("error")
log.Alert("alert")
}


2023-06-20T16:42:19.821153700+08:00 DEBUG debug
-------------------- debug
2023-06-20T16:42:19.827476000+08:00 INFO info
-------------------- info
2023-06-20T16:42:19.827989800+08:00 NOTICE notice
-------------------- notice
2023-06-20T16:42:19.829013000+08:00 WARN warn
-------------------- warn
2023-06-20T16:42:19.829522600+08:00 ERROR error
-------------------- error
2023-06-20T16:42:19.829522600+08:00 ALERT alert
-------------------- alert


how to show

-------------------- debug
-------------------- info
-------------------- notice
-------------------- warn
-------------------- error
-------------------- alert

Synchronization

but synchronization of the change is still the user's responsibility

Sorry to make another issue, but I just noticed that, and I'm a bit new to Go in general.
How would I synchronize the changes in the email handler (or log itself?), for instance?
I can't seem to find any way.

group entries

Hi there,

there is possible group log entries? Im trying to print multiple log entries for a unique action, eg:

INFO running command 1
INFO output is bla
INFO running command 2
INFO output is bla

but when I use the same logic in multiple goroutines, become insane:

INFO running command 1
INFO running command 1
INFO running command 1
INFO output is bla
INFO running command 1
INFO running command 1
INFO output is bla
INFO output is bla
ERROR error for command is : foo bar
INFO output is bla
INFO running command 2
INFO running command 2
INFO output is bla
INFO output is bla
INFO running command 2
INFO output is bla

Any ideia about this issue?

Thanks

Unable to remove handlers

addHandlers just keeps the handler there forever with no way to remove it or change it.
removeHandlers would be a great method for this.
Consider servers where you can change the error email live, the only thing you can do right now is change and restart the program.

Sharing fields between entries

What is the recommended way to use one collection of fields to log multiple entries? The obvious way:

func respond(requestID string) {
    l := log.WithFields(
        log.F("requestID", requestID),
    )
    l.Info("Everything goes ok")
    l.Warn("Something's wrong")
}

But it's completely wrong because of the way the package works -- each time I call WithFields(...), I get an Entry from pool, and when I call Info(...) or Warn(...) I put Entry back into pool. There's no guarantee that I get the same Entry next time I log with the same "context".

I tried to approach this problem from a different angle by aliasing a slice and implementing LeveledLogger, so I can mutate and copy fields as I like:

type Fields []log.Field

func (fs Fields) Info(v ...interface{}) {
    log.WithFields(fs...).Info(v...)
}

func (fs Fields) WithFields(other ...log.Field) log.LeveledLogger {
    return append(fs, other...)
}

...

func respond(requestID string) {
    l := Fields{
        log.F("requestID", requestID),
    }
    l.Info("Everything goes ok")
    l[:].WithFields(log.F("temperature", 100)).Warn("Something's wrong")
    l.Info("Back to normal") // no "temperature" field
}

I wonder if I missed something and there's a simpler solution.

UTC time

Hi there!

There is any particular reason to force UTC timestamp?

Regards,
Sebastian

SetFormatFunc is useless

Though SetFormatFunc method is exported in every handler, users actually can do nothing with this. Since none of the handlers' struct have any exported field, users can't customize their own format function.

Either making some fields exported or adding some getters to make this method usable. What do you think about it?

Gather file + line info on all error type logs

Gather file + line info on all error type logs such as log.Error(..), log.Fatal(...) etc..

This information is worth the overhead to know exactly what went wrong where.

TODO

  • Retain the SetCallerInfo function to turn it on for any/all log functions.
  • Add checks for certain log levels
  • update handlers to check for line number == 0 if not then caller information is present.

Not all error prefixes make it to the logging field

package main

import (
	"io"
	"os"

	"github.com/go-playground/log"
	"github.com/go-playground/log/handlers/json"
	"github.com/go-playground/errors"
)

func main() {
	log.AddHandler(json.New(os.Stderr), log.AllLevels...)
	err1 := errors.Wrap(io.EOF, "prefix 1")
	err2 := errors.Wrap(err1, "prefix 2")
	log.WithError(err2).Error("test")
}

prints out

{
  "message": "test",
  "timestamp": "2018-04-04T17:54:51.338592537-07:00",
  "fields": [
    {
      "key": "error",
      "value": "prefix 1: EOF"
    },
    {
      "key": "source",
      "value": "main: /Users/andrey/go/sandbox/src/sandbox/main.go:13"
    }
  ],
  "level": "ERROR"
}

I was expecting the value of the "error" field to be prefix 2: prefix 1: EOF

Windows color

Using this file:

package main
import "github.com/go-playground/log"
func main() {
   log.Warn("aaaaa bbbbb")   
}

I get this result:

2019-05-21 06:52:06.780406600-05:00  [33;1m  WARN [0m aaaaa bbbbb

Go playground issue

it seems there is a problem with the Go playground- when I try to run this from the Golang tutorial https://go.dev/tour/flowcontrol/12 I get an error ("can't connect to server) but when I copy and paste the code to another playground window, it works. Also obviously the tutorial /playground environment is being changed by the development team - when will it be stable?

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.