Comments (5)
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.
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.
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.
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.
Another simpler approach would be passing defaults to log.New().
from logxi.
Related Issues (20)
- Option to disable colors HOT 8
- Can I print line number (and function or file name) on debug and info log? HOT 1
- 'go vet' is nit-picking the API naming that takes formatting directives.
- Support context logger HOT 1
- Empty "in:" in Trace and Warn with happyDevFormatter HOT 5
- Push to s3 HOT 2
- Log as csv
- fix panic when logging a nil pointer to a Stringer HOT 1
- How to disable stack trace in wrn and err level ? HOT 3
- doesn't work well with go1.6+, logger.warn does not display line number HOT 1
- Configuration problem. HOT 1
- Fit formatter
- Text formatter formats Trace incorrectly
- Using HappyDevFormatter can cause race conditions not present in the jsonFormatter HOT 2
- Time more precise by default. HOT 1
- The gif is good, but too fast
- Why does Warn and Error return the error?
- Maintainers? HOT 2
- go modules build fails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from logxi.