Giter VIP home page Giter VIP logo

Comments (5)

mgutz avatar mgutz commented on July 26, 2024

I'm not sure if this helps. The way I use logxi for package-private logging is to create a logger with a namespace.

//// models/init.go
var logger  = log.New("my-models")
//// controllers/init.go
var logger = log.New("my-controllers")

You can then control how each package logs

LOGXI=my-models=DBG,my-controllers=ERR

from logxi.

ansel1 avatar ansel1 commented on July 26, 2024

That's what we do too, but we want different defaults for LOGXI and LOGXI_FORMAT when running tests. Our makefile can set these, but the makefile is only useful when you want to run all the project's tests. When we are focussing on individual packages or tests, we're using "go test ..." and its tougher to manage a different set of environment variables just for those test runs. For our other configuration options (also configured via environment variables), we use a .env loader at runtime, but that happens too late for logxi...by the time we've run that, logxi has already configured itself.

Maybe I can just use the Suppress() function to turn off logs completely during tests.

from logxi.

mgutz avatar mgutz commented on July 26, 2024

I need to refactor how logxi reads environment vars. The unit tests are more complicated than they need to be because of it. Do you want to take a stab at refactoring it? I have limited time.

from logxi.

ansel1 avatar ansel1 commented on July 26, 2024

Thoughts on how to refactor? I'm a little torn on the best approach. There are good reasons to init logging in init() functions (mainly so logging can happen as early as possible in boot up). If I add a more robust way to reconfigure existing loggers, it seems I'll have to add at least one extra mutex into the logger calls, which will impact performance. Or move loggers to channels to avoid the lock, but again, not sure what the performance impact will be...

There's currently a "concurrent writer" which has a mutex...maybe I could move that mutex up the stack, to a "ConcurrentLogger"? That would avoid adding another mutex.

from logxi.

ansel1 avatar ansel1 commented on July 26, 2024

Another simpler approach would be passing defaults to log.New().

from logxi.

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.