xybor-x / xylog Goto Github PK
View Code? Open in Web Editor NEWPython-like logging design in Golang
License: MIT License
Python-like logging design in Golang
License: MIT License
Problem
Solution
Use pool.
Describe the bug
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The output should have the message, but not found.
Problem
Because we do not have an easy way to config a root logger, it is redundant.
Solution
Remove root logger methods.
Problem
Sometimes we use a third party library which uses xylog, and we need to flush the Emitter in the library too.
Solution
Flush should be the global function instead of Logger method. It need to flush all emitters in program.
Problem
Currently, log with an object, map, or array is too slow.
Solution
Consider add fast encoding of object, map, and array.
Problem
Socket is a requirement of a logging library.
Solution
Add SocketEmitter.
Problem
NewRotatingEmitter functions need to many arguments, it make code difficult to readable.
Solution
Initiate RotatingEmitter via a config struct instead of using New functions with parameters.
Example
var config = &TimeEmitterConfig{
Filename: "example.log",
BackupCount: 5,
Interval: 5*time.Minute
}
var emitter = NewFileEmitter(config)
Problem
Solution
Rewrite unittests.
Problem
Currently, creating a logger is take too many lines of code. We need to shorten this work.
Solution
Create a wrapper logger which allows to set the output and format quickly.
Example
var simpleConfig = xylog.NewSimpleConfig("example.service")
simpleConfig.SetTextFormatter("%(message)s %(asctime)s")
simpleConfig.SetOutput(os.Stdout)
var logger = xylog.GetLogger("example.service")
logger.Info("something")
Problem
uber/zaplog has a very fast way of encoding logging messages. They build by themself the logging message instead of using json.Marshal.
Add copyright to all files
Describe the bug
=== RUN TestLoggerCallHandlerHierarchy
/home/runner/work/xylog/xylog/logger_test.go:107: "This is a long enough message 26" IN messsage="This is a long enough message 268"
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Test passes.
Problem
using AddField we can add permanent fields. But sometimes the values of the field change over the time. As of now there is no way to fix this as you cannot delete the logger object (no api) and can remove/ update field (no api).
Sometime some fields are no longer required so there should be a provision to remove the fields.
Solution
Example
logger := xylog.GetLogger(name)
logger.AddField("test", "sample1")
logger.UpdateField("test", "sample2")
logger.RemoveField("test")
Problem
Many people need to know some information about this library.
Solution
Add Q&A
Problem
Handler is used to create logging message, and Emitter is used to dispatch messages to specific output.
One logging message could be printed to some output.
Solution
Handler need to have some Emitters instead of one.
Describe the bug
Problem
One Logger can have some Handlers with different formatters. Currently, EventLogger must specify the format (JSON or default) of fields. It is difficult to handle in the logger with both JSONFormatter and StructuredFormatter.
Solution
Adapt EventLogger fields with Formatter.
Problem
String concatenation is time-consuming and produce many allocations.
Solution
Use array of byte as buffer instead.
Problem
Linux has a logrotate command line tool for handle rotating log files. Moreover, Rotating Emitters are difficult to maintain and extend. It should be removed.
Solution
Problem
Benchmark is using the utility functions in tests package. It is hard to maintain this package.
Problem
When logging a message by using bufio.Writer, it is appended to the buffer. If Emitter calls Writer.Flush, the bytes in buffer will be written into disk files. This creates an IO bound time.
Solution
Example
var emitter = xylog.NewStreamEmitter(os.Stdout)
defer emitter.Close()
Problem
Now a Handler has many Emitters, it is time-consuming if locking while the Handler call Emit of all Emitters.
Solution
Emitter should have its own lock.
Problem
EventLogger contains many fields, if we allocate theses fields every call, it will time-consuming.
Solution
Create pool to reuse EventLogger.
Problem
Solution
Apply this approach to TextFormatter.
Describe the bug
To Reproduce
Steps to reproduce the behavior:
var logger = xylog.GetLogger("xybor.foo")
logger.Debug("bar")
Output is:
time=[time] level=DEBUG message=bar
Expected behavior
Example says it should print:
time=[time] source=example.go.main:2 level=DEBUG module=foo message=bar
Screenshots
No.
Environment
Additional context
Add any other context about the problem here.
Problem
Solution
Apply this approach to JSONFormatter.
Problem
The alone benchmark values do not prove anything.
Solution
Add benchmark of some logging libraries:
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.