Giter Club home page Giter Club logo

Comments (1)

ktoso avatar ktoso commented on June 24, 2024 1

When one is using swift-log across multiple different packages, should one use the same Logger instance across these packages or is it acceptable to use different instances?

Ultimately it is up to you and the needs of your system/application.

It may help to think about where/how you'd like to change log levels; which implies where loggers may need to be created for a subsystem. Note that creating a "new" logger with a changed log level is simply: var l = baseLogger; l.logLevel = .warn. So some people use it like this and pass a "single" base logger around, modifying it as they go. The source parameter can be used to identify "what module" has logged then as well (though we need more work with that parameter's default value).


Normally it is either recommended to either:

  • go all-in passing the logger to all types and functions which need it
    • this is the currently most widely adopted pattern I'd say
    • func hello(param: Param, other: Other, logger: Logger)
  • OR go all-in on everyone getting their logger instance ad hoc.
    • For the latter solution we currently do not have a great log handler backend which would allow changing configuration on the fly, but that's an alternative to consider.

Server side frameworks nowadays opt for the explicit logger passing. With the baggage context work there may be new patterns emerging, i.e. "context objects", but that's not entirely baked yet. The primary use of those is for distributed tracing.

APIs are likely to take the shape of: func hello(param: Param, other: Other, context: ...Context) (and context has context.logger which also uses the baggage value -- which enables marrying distributed tracing and logging).

from swift-log.

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.