gemnasium / logrus-postgresql-hook Goto Github PK
View Code? Open in Web Editor NEWLogrus PostgreSQL hook
License: MIT License
Logrus PostgreSQL hook
License: MIT License
In the readme log.Hooks.Add(hook)
should be log.AddHook(hook)
Related to issue #4: Some months ago logrus
package has added the TraceLevel
logging level. I believe the Levels()
method should be updated with the new level logrus.TraceLevel
:
logrus-postgresql-hook/postgresql_hook.go
Line 152 in 102da18
Hi,
While reading the code I noticed that the sync.RWMutex is only used with RLock, I could not find a corresponding Lock call.
RWMutex is doing states:
A RWMutex is a reader/writer mutual exclusion lock. The lock can be held by an arbitrary number of readers or a single writer.
The newEntry method is also not having a critical section, correct?
Am I missing something?
When method name is being logged, i.e. log.SetReportCaller(true)
, the Caller
field is lost in hook. This is because this field (Caller
) is not copied when new entry is created.
logrus-postgresql-hook/postgresql_hook.go
Line 132 in 0a35f5d
The newEntry
should be:
newEntry := &logrus.Entry{
Logger: entry.Logger,
Data: data,
Time: entry.Time,
Level: entry.Level,
Message: entry.Message,
Caller: entry.Caller,
}
Currently the database will log for every event level except for panic, as seen here:
func (hook *Hook) Levels() []logrus.Level { return []logrus.Level{ logrus.FatalLevel, logrus.ErrorLevel, logrus.WarnLevel, logrus.InfoLevel, logrus.DebugLevel, } }
It would be ideal if this method can be provided externally with something like the following:
func (h *Hook) init() { h.Levels = func (hook *Hook) Levels() []logrus.Level { return []logrus.Level{ logrus.FatalLevel, logrus.ErrorLevel, logrus.WarnLevel, logrus.InfoLevel, logrus.DebugLevel, } } }
Then in my caller I can update Levels with something like:
hook := pglogrus.NewAsyncHook(db.DB, map[string]interface{}{}) hook.Levels = func() []logrus.Level { topLevel := int(settings.Log.DbLogLevel) + 1 return logrus.AllLevels[0:topLevel] } l.AddHook(hook)
Alternatively it would be good if we can assign levels at declaration to a slice, and that could be used during execution. Something like the following:
type Hook struct { ... LogLevels []Level }
Hello, I'm just opening this issue to let you know, the next release of logrus (v1.2.0) will add a new trace level named Trace below Debug.
Here is the PR for reference sirupsen/logrus#844
You may want to take into account this new level.
Hello,
I have 2 questions/concerns, which seem to be related:
*time.Ticker
to 1 second when the new async hook is createdlogrus-postgresql-hook/postgresql_hook.go
Line 77 in 102da18
and then overwriting this time ticker with a 'quicker' one in the Flush()
method
logrus-postgresql-hook/postgresql_hook.go
Line 172 in 102da18
-race
flag, there is data racing problem. While one goroutine tries to write to hook.Ticker
in Flush()
method, another one want to read in fire()
method, line 202.Here is the output that I get when running test with race condition:
Thank you!
So you don't have to call "defer hook.Flush()" everywhere.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.