hhkbp2 / go-logging Goto Github PK
View Code? Open in Web Editor NEWA Logging Library for Golang.
License: BSD 3-Clause "New" or "Revised" License
A Logging Library for Golang.
License: BSD 3-Clause "New" or "Revised" License
To reproduce, you can run the config file example and try changing the datefmt in the config.yml file
P.S. love the package! Thank you for your hard work :)
Hi ,
I am working on Windows 10 and Go 1.9.
I am running sample provide in the document and nothing get printed in the file as well as not in console.
logger.go,record.go------file
record := NewLogRecord(
self.name,
level,
callerInfo.PathName,
callerInfo.FileName,
callerInfo.LineNo,
callerInfo.FuncName,
format,
true,
args) //Here I can see the value line no 380
self.Handle(record) // args value in empty ""
go get github.com/hhkbp2/go-logging
cd C:\GoPath\src\git.apache.org\thrift.git; git pull --ff-only
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
package git.apache.org/thrift.git/lib/go/thrift: exit status 1
Is it possible to redirect sdtout and stderr to the logging file ?
Is it also possible to redirect the default log output to the logging file ?
I wish panics could be written to the logging file. I'm also unsure about flushing in case of program crash.
When running go get
with Go Modules enabled, 4 errors are reported.
NOTE: E:\GoCodes
is just my GOPATH.
E:\GoCodes\pkg\mod\github.com\hhkbp2\[email protected]\gen-go\logging\thriftloggingservice.go:77:20: not enough arguments in call to oprot.Flush
have ()
want (context.Context)
E:\GoCodes\pkg\mod\github.com\hhkbp2\[email protected]\gen-go\logging\thriftloggingservice.go:101:31: cannot use &thriftLoggingServiceProcessorReport literal (type *thriftLoggingServiceProcessorReport) as type thrift.TProcessorFunction in assignment:
*thriftLoggingServiceProcessorReport does not implement thrift.TProcessorFunction (wrong type for Process method)
have Process(int32, thrift.TProtocol, thrift.TProtocol) (bool, thrift.TException)
want Process(context.Context, int32, thrift.TProtocol, thrift.TProtocol) (bool, thrift.TException)
E:\GoCodes\pkg\mod\github.com\hhkbp2\[email protected]\gen-go\logging\thriftloggingservice.go:111:27: not enough arguments in call to processor.Process
have (int32, thrift.TProtocol, thrift.TProtocol)
want (context.Context, int32, thrift.TProtocol, thrift.TProtocol)
E:\GoCodes\pkg\mod\github.com\hhkbp2\[email protected]\gen-go\logging\thriftloggingservice.go:119:13: not enough arguments in call to oprot.Flush
have ()
want (context.Context)
Hi,
Though I have been using this library for quite some time, got this crash for the very first time.
fatal error: concurrent map iteration and map write
goroutine 8 [running]:
runtime.throw(0x12b7bdb, 0x26)
/usr/local/go/src/runtime/panic.go:1117 +0x72 fp=0xc0009907e8 sp=0xc0009907b8 pc=0x4380f2
runtime.mapiternext(0xc00511a3c0)
/usr/local/go/src/runtime/map.go:858 +0x54c fp=0xc000990868 sp=0xc0009907e8 pc=0x41270c
runtime.mapiterinit(0x1155060, 0xc0017e8750, 0xc00511a3c0)
/usr/local/go/src/runtime/map.go:848 +0x1c5 fp=0xc000990888 sp=0xc000990868 pc=0x4120c5
reflect.mapiterinit(0x1155060, 0xc0017e8750, 0xc0004f9aa0)
/usr/local/go/src/runtime/map.go:1340 +0x54 fp=0xc0009908b8 sp=0xc000990888 pc=0x467c14
reflect.(*MapIter).Next(0xc0001697a0, 0xc0017e8750)
/usr/local/go/src/reflect/value.go:1272 +0x6a fp=0xc0009908e0 sp=0xc0009908b8 pc=0x4a290a
internal/fmtsort.Sort(0x1155060, 0xc0017e8750, 0x15, 0x120)
/usr/local/go/src/internal/fmtsort/sort.go:63 +0x1af fp=0xc000990990 sp=0xc0009908e0 pc=0x4b3d2f
fmt.(*pp).printValue(0xc0003eb6c0, 0x1155060, 0xc0017e8750, 0x15, 0x76, 0x0)
/usr/local/go/src/fmt/print.go:769 +0xca5 fp=0xc000990b50 sp=0xc000990990 pc=0x4f76a5
fmt.(*pp).printArg(0xc0003eb6c0, 0x1155060, 0xc0017e8750, 0x76)
/usr/local/go/src/fmt/print.go:712 +0x2d3 fp=0xc000990be8 sp=0xc000990b50 pc=0x4f62d3
fmt.(*pp).doPrintf(0xc0003eb6c0, 0x12bda4b, 0x2a, 0xc003a0d870, 0x1, 0x1)
/usr/local/go/src/fmt/print.go:1026 +0x168 fp=0xc000990cd8 sp=0xc000990be8 pc=0x4f9908
fmt.Sprintf(0x12bda4b, 0x2a, 0xc003a0d870, 0x1, 0x1, 0xe, 0x0)
/usr/local/go/src/fmt/print.go:219 +0x66 fp=0xc000990d30 sp=0xc000990cd8 pc=0x4f2c46
github.com/hhkbp2/go-logging.(*LogRecord).GetMessage(0xc00373ed80, 0x453ee5, 0xc00323fce0)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/record.go:69 +0x8a fp=0xc000990d80 sp=0xc000990d30 pc=0x9ccb8a
github.com/hhkbp2/go-logging.(*StandardFormatter).Format(0xc00008e910, 0xc00373ed80, 0x0, 0xc000990f10)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/formatter.go:174 +0x2f fp=0xc000990dc0 sp=0xc000990d80 pc=0x9c1f2f
github.com/hhkbp2/go-logging.(*BaseHandler).Format(0xc000118380, 0xc00373ed80, 0x0, 0x0)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler.go:124 +0x86 fp=0xc000990e08 sp=0xc000990dc0 pc=0x9c2646
github.com/hhkbp2/go-logging.(*RotatingFileHandler).ShouldRollover(0xc0002f6e80, 0xc00373ed80, 0xd2, 0x1, 0x2)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler_rotating_file.go:193 +0x47 fp=0xc000990e48 sp=0xc000990e08 pc=0x9c4aa7
github.com/hhkbp2/go-logging.(*BaseRotatingHandler).RolloverEmit(0xc0001223c8, 0x1518ff8, 0xc0002f6e80, 0xc00373ed80, 0x0, 0x0)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler_rotating_file.go:59 +0x42 fp=0xc000990e90 sp=0xc000990e48 pc=0x9c4622
github.com/hhkbp2/go-logging.(*RotatingFileHandler).Emit(0xc0002f6e80, 0xc00373ed80, 0x1, 0x0)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler_rotating_file.go:251 +0x49 fp=0xc000990ed0 sp=0xc000990e90 pc=0x9c5109
github.com/hhkbp2/go-logging.(*BaseHandler).Handle2(0xc000118380, 0x1517570, 0xc0002f6e80, 0xc00373ed80, 0x0)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler.go:137 +0xbc fp=0xc000990f20 sp=0xc000990ed0 pc=0x9c279c
github.com/hhkbp2/go-logging.(*RotatingFileHandler).loop(0xc0002f6e80)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler_rotating_file.go:272 +0xf8 fp=0xc000990fa8 sp=0xc000990f20 pc=0x9c5238
github.com/hhkbp2/go-logging.NewRotatingFileHandler.func1(0xc0002f6e80)
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler_rotating_file.go:156 +0x52 fp=0xc000990fd8 sp=0xc000990fa8 pc=0x9cdcb2
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc000990fe0 sp=0xc000990fd8 pc=0x46db61
created by github.com/hhkbp2/go-logging.NewRotatingFileHandler
/home/newgo/pkg/mod/github.com/hhkbp2/[email protected]/handler_rotating_file.go:154 +0x215
There is no information in the stack trace about my application code that could be causing this issue and all the coroutines are in IO Wait or select states.
The config file I use for logging is attached and I use Go 1.16.
Any help would be greatly appreciated.
Thanks.
logconfig.txt
Hi there and thanks for sharing this library.
Running go vet
on code that is using this go-logging
causes errors. It seems that go vet
is trying to enforce convention on all Print(f) like functions/methods.
Current workaround for me is to run Log
method directly.
We need function Reopen() which close and reopen all file handlers.
It's required for SIGHUP processing (log rotate)
is it possible to configure this logger to write structured json logs?
I configure logging manually:
import (
"github.com/hhkbp2/go-logging"
)
func LoggingDefault() {
rootLogger := logging.GetLogger("")
rootLogger.SetLevel(logging.LevelInfo)
formatter := logging.NewStandardFormatter("%(asctime)s %(levelname)s (%(filename)s:%(lineno)d) %(name)s %(message)s",
"%Y-%m-%d %H:%M:%S.%3n")
stdoutHandler := logging.NewStdoutHandler()
stdoutHandler.SetLevel(logging.LevelInfo)
stdoutHandler.SetFormatter(formatter)
rootLogger.AddHandler(stdoutHandler)
}
Than I load config file:
{
"version": 1,
"root": {
"level": "DEBUG",
"propagate": true,
"handlers": ["stdout", "file"]
},
"handlers": {
"stdout": {
"class": "StdoutHandler",
"level": "DEBUG",
"formatter" : "ft"
},
"file": {
"class": "FileHandler",
"level": "DEBUG",
"filename": "xignite_fetcher_stocks.log",
"mode": "O_CREATE",
"bufferSize": 0,
"formatter": "ft"
}
},
"formatters": {
"ft": {
"format": "%(asctime)s %(levelname)s (%(filename)s:%(lineno)d) %(name)s %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S.%3n"
}
}
}
by ApplyJsonConfigFile.
Actual behavior: every line is duplicated in stdout
Expected behavior: no duplication
Hi,
I am unable to bulid package while trying to install. Got below error
C:\Go\MyCode> go get github.com/hhkbp2/go-logging
src\github.com\hhkbp2\go-logging\handler_syslog.go:12:11: undefined: syslog.Priority
src\github.com\hhkbp2\go-logging\handler_syslog.go:14:12: undefined: syslog.Writer
Please guide me if I am doing wrong else how to fix issue
Regards,
Dinesh
Hello,
Please let me know how may I use Multi Write file to log in console as well as file. One more thing How may I configure package level log, Like same as Apache log4j.
Regards,
Dinesh
Hi,
Based on what I have gone through there is no option to provide a channel size for a timed rotating file handler.
Please let me know if my analysis is wrong and also if there are plans to implement channel for timed rotating file handler also.
Thanks.
go version go1.19.5 linux/amd64
logging ver : 0.3.6
OS env: Linux (Cent OS)
logging is not updated to file, when ever I am running my application in background , like
"nohup myapp&"
I could not find any information in documentation to force logger to work in background also.
Any help in this regard is very much helpful.
Thanks in advance
Is there a way to log local time instead of UTC when defining "%(asctime)s" in the format when using config.yml?
In RotatingFileHandler.Close()
when inputChanSize > 0
1 sending to exitChan
.
RotatingFileHandler.loop()
receives 1 from exitChan
and returns.
In this case some log records can be ignored in inputChan
channel.
This issue sometimes catches by the test:
--- FAIL: TestRotatingFileHandler_AppendWithoutBackup (0.00s)
Error Trace: handler_rotating_file_test.go:89
Error: Not equal:
expected: 0x3a98
actual: 0x3a34
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.