Giter Site home page Giter Site logo

Accept interface instead of *zap.Logger about td HOT 12 OPEN

gotd avatar gotd commented on May 21, 2024
Accept interface instead of *zap.Logger

from td.

Comments (12)

ernado avatar ernado commented on May 21, 2024 1

I'll return to this near 1.0 release, probably I'll extract abstract logger to separate package under gotd org.

I've seen lots of bad approaches to this problem and just don't want to make another one.

from td.

tdakkota avatar tdakkota commented on May 21, 2024

Seems like duplicate of #15

from td.

ernado avatar ernado commented on May 21, 2024

Yes, this can be achieved in #15

Currently I can't come with a way of abstracting out zap logging without losing performance or usability.

Can you please provide examples of such "abstract logger"?

from td.

Semior001 avatar Semior001 commented on May 21, 2024

Example is here: https://github.com/go-pkgz/auth/tree/master/logger
This is the library for providing oauth, it also stores its states, logs some events, but there you may provide your own implementation of the store and logger

from td.

ernado avatar ernado commented on May 21, 2024
// L defined logger interface used everywhere in the package
type L interface {
	Logf(format string, args ...interface{})
}

So there are no way to use subloggers, structured logging and verbosity levels.

from td.

Semior001 avatar Semior001 commented on May 21, 2024

Nothing stops you from defining such interface, like:

type Logger interface {
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	With(info string) Logger // adds additional information to the logger
	Named(name string) Logger // creates a sublogger
}

at least it adds some flexibility around the logger, while the library is strictly tied to zap.

from td.

ernado avatar ernado commented on May 21, 2024

I need statically typed structured logger with good performance, if someone will come up with zap-like interface for abstract logger I'm ok with it.

from td.

stale avatar stale commented on May 21, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from td.

tdakkota avatar tdakkota commented on May 21, 2024

keep

from td.

suntong avatar suntong commented on May 21, 2024

I've seen lots of bad approaches to this problem and just don't want to make another one.

Here is my 2c, the best performance logger (for both logging and parsing) that I found is

https://github.com/go-kit/log
(There are some benchmarks & comparisons links at the end of it)

which is also a structured logger --

  • Using a stricter, key/value-oriented message format for our logs, containing contextual and semantic information, makes it much easier to get insight into the operational activity of the systems we build.
  • Migrating from unstructured to structured logging is probably a lot easier than you'd expect.
  • And as last resort, you can redirect stdlib logger to Go kit logger too.

For more details on the evolution of the Logger interface, see The Hunt for a Logger Interface, a talk by Chris Hines.

All in all, it is a minimal and extensible structured logger

from td.

ernado avatar ernado commented on May 21, 2024

Currently I'm waiting for https://github.com/open-telemetry/opentelemetry-go implementation of logging API.

from td.

ernado avatar ernado commented on May 21, 2024

Also structured logging proposal just got accepted:
golang/go#56345

from td.

Related Issues (20)

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.