Skip to content

Commit

Permalink
Allow disabling logs by env var
Browse files Browse the repository at this point in the history
Allows users to disable logs without having to use webrtc.API
to configure custom logger factory. Also updates naming
'PIONS' -> 'PION'.

Fixes #7
  • Loading branch information
Okamoto authored and justinokamoto committed Jul 3, 2019
1 parent ce07aaf commit 0387f8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
* [Woodrow Douglass](https://github.com/wdouglass) - *Test coverage*
* [Michiel De Backker](https://github.com/backkem) - *Docs*
* [Hugo Arregui](https://github.com/hugoArregui) - *Custom Logs*
* [Justin Okamoto](https://github.com/justinokamoto) - *Disabled Logs Update*

### License
MIT License - see [LICENSE](LICENSE) for full text
18 changes: 12 additions & 6 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,21 @@ func NewDefaultLoggerFactory() *DefaultLoggerFactory {
factory.Writer = os.Stdout

logLevels := map[string]LogLevel{
"ERROR": LogLevelError,
"WARN": LogLevelWarn,
"INFO": LogLevelInfo,
"DEBUG": LogLevelDebug,
"TRACE": LogLevelTrace,
"DISABLE": LogLevelDisabled,
"ERROR": LogLevelError,
"WARN": LogLevelWarn,
"INFO": LogLevelInfo,
"DEBUG": LogLevelDebug,
"TRACE": LogLevelTrace,
}

for name, level := range logLevels {
env := os.Getenv(fmt.Sprintf("PIONS_LOG_%s", name))
env := os.Getenv(fmt.Sprintf("PION_LOG_%s", name))

if env == "" {
env = os.Getenv(fmt.Sprintf("PIONS_LOG_%s", name))
}

if env == "" {
continue
}
Expand Down

0 comments on commit 0387f8a

Please sign in to comment.