pion / logging Goto Github PK
View Code? Open in Web Editor NEWThe logging library used by Pion
Home Page: https://pion.ly
License: MIT License
The logging library used by Pion
Home Page: https://pion.ly
License: MIT License
pion/logging has been really useful for me, and using a lot for debugging.
@Sean-Der expressed his concern about its performance, and I'd agree, that is a concern...
For example, if you have this statement:
logger.Debug("received data %s", pkt.String())
It looks alright, and it is just a debug log that only prints out when it is enabled with PION_LOG_DEBUG...
BUT! What if pkt.String()
was an expensive routine? This is evaluated no matter what, consuming CPU time in production as well... Unfortunately, go has no compile-time options like C has (#ifdef etc.)
One obvious solution would be to use a callback like this:
logger.Debug(func (p *LoggerPad) {
p.Format("received data %s", pkt.String())
})
The Debug function can be designed in a way that the callback function passed in it won't be called if it is not set to DEBUG level. You will need to type a lot more but it saves a lot of CPU time!
Provide a way to disable logging completely.
Default logging is currently set to ERROR. In order to disable logging completely, we need to use API to configure a custom logger factory.
Set the default logging level to "disabled"
If we were to keep the default logging level as Error and allow users to use env vars by default, then we should provide a way to disable the logging completely with the env var.
diff --git a/logger.go b/logger.go
index d3c0156..3e07cdd 100644
--- a/logger.go
+++ b/logger.go
@@ -181,11 +181,12 @@ func NewDefaultLoggerFactory() *DefaultLoggerFactory {
factory.Writer = os.Stdout
logLevels := map[string]LogLevel{
- "ERROR": LogLevelError,
- "WARN": LogLevelWarn,
- "INFO": LogLevelInfo,
- "DEBUG": LogLevelDebug,
- "TRACE": LogLevelTrace,
+ "DISABLED": LogLevelDisabled,
+ "ERROR": LogLevelError,
+ "WARN": LogLevelWarn,
+ "INFO": LogLevelInfo,
+ "DEBUG": LogLevelDebug,
+ "TRACE": LogLevelTrace,
}
for name, level := range logLevels {
Ideally, we should set the default level to "Disabled" IMO. (keep the current default)
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.
This issue provides visibility into Renovate updates and their statuses. Learn more
This repository currently has no open or pending branches.
I think it may be as easy as a File writer instead of stdout, but in that case we need to document it in
an example
Avoid using globals & init and enable the corresponding linters.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.