go-eden / slf4go Goto Github PK
View Code? Open in Web Editor NEWSimple Logger Facade for golang
License: MIT License
Simple Logger Facade for golang
License: MIT License
Do you have a plan to do Driver implementation for bridging slf4go and zap?
When looking at the constant names in slf_model.go, I noticed that the fatal level name has only a single "L". It is spelled as "Fata" and "Level" combined. This is confusing when compared with the names of the other levels.
const (
TraceLevel Level = iota
DebugLevel
InfoLevel
WarnLevel
ErrorLevel
PanicLevel
FataLevel
)
I suggest that another constant be added called FatalLevel
with the same numeric value as FataLevel
.
The standard Golang context.Context
allows storing and retrieve objects using WithValue
and Value
func.
It would be a good idea to create a common API to configure slf4go using context.Context
API, apart from existing usage of global variable. The current approach of using global variables (globalLogger
, and globalDriver
) are not always acceptable in some projects, as it's susceptible to race conditions to occur.
An example of a new API:
// configure logger: driver, level, etc. withing context
d := slogzap.Driver{/* ... */}
ctx = slog.WithLogger(ctx, slog.Config{Driver: d})
// usage
func someUserFunc(ctx context.Context) {
log := slog.FromContext(ctx)
log.Info("Example msg")
}
When simply importing module
import slog "github.com/go-eden/slf4go"
and using the following
slog.SetLevel(slog.InfoLevel)
slog.Debug("Don't see this")
slog.Info("DO see this")
Here are the errors
C:\Go_Projs\pkg\mod\github.com\go-eden\[email protected]\etime_now.go:19:11: cannot use tv.Sec (type int32) as type int64 in return argument
C:\Go_Projs\pkg\mod\github.com\go-eden\[email protected]\etime_now.go:33:20: invalid operation: tv.Sec * 1000 + int64(tv.Usec) / 1000 (mismatched types int32 and int64)
C:\Go_Projs\pkg\mod\github.com\go-eden\[email protected]\etime_now.go:47:20: invalid operation: tv.Sec * 1e+06 + int64(tv.Usec) (mismatched types int32 and int64)
C:\Go_Projs\pkg\mod\github.com\huandu\[email protected]\syscall_unix.go:17:17: undefined: syscall.PROT_NONE
C:\Go_Projs\pkg\mod\github.com\huandu\[email protected]\syscall_unix.go:18:17: undefined: syscall.PROT_READ
C:\Go_Projs\pkg\mod\github.com\huandu\[email protected]\syscall_unix.go:19:17: undefined: syscall.PROT_WRITE
C:\Go_Projs\pkg\mod\github.com\huandu\[email protected]\syscall_unix.go:20:17: undefined: syscall.PROT_EXEC
C:\Go_Projs\pkg\mod\github.com\huandu\[email protected]\syscall_unix.go:30:32: not enough arguments in call to syscall.Syscall
C:\Go_Projs\pkg\mod\github.com\huandu\[email protected]\syscall_unix.go:30:33: undefined: syscall.SYS_MPROTECT
HI,
I want to add few values to Fields of the exiting globalLogger, not to the new one created by GetLogger() or func NewLogger(name string) . because I see that no possiblity to again set back newly created *Logger to globalLogger variable.
This is also becasue , slf_core.go always uses globalLogger & not the one I created instance of Logger
func Debug(v ...interface{}) {
...
...
globalLogger.print(DebugLevel, pc[0], nil, v...)
}
Either provide a method to set the newly created Logger to globalLogger or provide new getGlobalLogger() to get handle to globalLogger so that Fields can be added.
somethig like below in slf_core.go :
func GetGlobalLogger() *Logger {
return globalLogger
}
OR
func AddFields(fields Fields) {
globalLogger.BindFields(fields Fields)
}
Hi,
the default example does not work on the 1.0.9
version. There are no logs.
The version 1.0.8
works like expected.
2021-05-24 11:40:06.722457 [1] [DEBUG] [root] log.go:12 debug time: 2021-05-24 11:40:06.722442165 +0200 CEST m=+0.000102399
2021-05-24 11:40:06.722631 [1] [WARN ] [root] log.go:15 warn log
2021-05-24 11:40:06.722644 [1] [ERROR] [root] log.go:17 error log
2021-05-24 11:40:06.722679 [1] [PANIC] [root] log.go:20 panic time: 2021-05-24 11:40:06.722651348 +0200 CEST m=+0.000311567
goroutine 1 [running]:
runtime/debug.Stack(0x4b55e0, 0xc00009e370, 0x1)
/usr/local/go/src/runtime/debug/stack.go:24 +0x9f
github.com/go-eden/slf4go.Panicf(0x4d1c4d, 0xe, 0xc00009e360, 0x1, 0x1)
/home/andrej/go/pkg/mod/github.com/go-eden/[email protected]/slf_core.go:210 +0x8e
main.main()
/home/andrej/go/src/github.com/lorislab/tmp/log.go:20 +0x1f9
br,
Andrej
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.