GithubHelp home page GithubHelp logo

xybor-x / xylog Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 3.0 172 KB

Python-like logging design in Golang

License: MIT License

Go 100.00%
go golang golang-library jsonlogging log logger logging logging-library performance python-like structurelogging

xylog's People

Contributors

huykingsofm avatar

Stargazers

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

Watchers

 avatar

xylog's Issues

Logger Flush doesn't Flush parent emitters

Describe the bug

  • Affected version: v0.1.0
  • Logger Flush only Flush its Emitters. It should Flush parent Emitters too.

To Reproduce
Steps to reproduce the behavior:

  1. Create Logger named "parent" with a Handler and a Emitter.
  2. Create Logger named "parent.child" without Handler.
  3. Log one message with the "parent.child" Logger.
  4. Terminate the program and check the output.

Expected behavior
The output should have the message, but not found.

Remove root logger methods

Problem
Because we do not have an easy way to config a root logger, it is redundant.

Solution
Remove root logger methods.

Flush should apply on all Emitters

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.

Add Socket Emitter

Problem
Socket is a requirement of a logging library.

Solution
Add SocketEmitter.

Reduce arguments in NewRotatingEmitter functions

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)

Rewrite unittest

Problem

  • Almost unittests are too useless.
  • They use ExpectNotPanic to only get code coverage without any logic check.

Solution
Rewrite unittests.

Add simple configuration

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")

Test LoggerCallHandlerhierarchy failed

Describe the bug

  • Affected version: v0.3.0
=== 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:

  1. Two random messages are the same prefix.

Expected behavior
Test passes.

Allow removing / updating field values

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

  1. allow recreating the logger object
  2. allow updating and removing field bye key

Example


logger := xylog.GetLogger(name)
logger.AddField("test", "sample1")

logger.UpdateField("test", "sample2")
logger.RemoveField("test")

Add Q&A section

Problem
Many people need to know some information about this library.

Solution
Add Q&A

Handler should have many Emitters instead of one

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.

EventLogger should be adapted with Formatter

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.

Remove Rotating Emitters

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

  • Remove Rotating Emitters.
  • Consider to create a logrotate in Golang for handling rotating log files on multiplatform.

Do not flush writer as soon as write a logging message to buffer

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

  • Do not Flush as soon as writing.
  • Create Close methods for writing unflushed bytes to destination.

Example

var emitter = xylog.NewStreamEmitter(os.Stdout)
defer emitter.Close()

Create text encoding like zap and zerolog

Problem

  • Cloned by #19
  • Zap and zerolog uses a approach of blazing fast encoding. It encodes the json without using reflect or fmt.Sprint.

Solution
Apply this approach to TextFormatter.

Incorrect example about xybor standard format

Describe the bug

  • Affected version: v0.1.0
  • Xybor standard format is not correct as example.

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

  • OS: all.

Additional context
Add any other context about the problem here.

Create json encoding like zap and zerolog

Problem

  • Cloned by #19
  • Zap and zerolog uses a approach of blazing fast encoding. It encodes the json without using reflect or fmt.Sprint.

Solution
Apply this approach to JSONFormatter.

Add benchmark comparison

Problem
The alone benchmark values do not prove anything.

Solution
Add benchmark of some logging libraries:

  • Python logging.
  • logrus.
  • zaplog.

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.