-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dkyanakiev/feature/swapping-logger
Moving to zlog for logging
- Loading branch information
Showing
18 changed files
with
122 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func SetupLogger() (*os.File, *zerolog.Logger) { | ||
|
||
// UNIX Time is faster and smaller than most timestamps | ||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix | ||
|
||
logLevel, debugOn := os.LookupEnv("VAULTY_LOG_LEVEL") | ||
|
||
// Default level for this example is info, unless debug flag is present | ||
if debugOn { | ||
level, err := zerolog.ParseLevel(logLevel) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("Invalid log level") | ||
} | ||
zerolog.SetGlobalLevel(level) | ||
} | ||
var logFile *os.File | ||
|
||
// Check if file for logging is set | ||
LOG_FILE, exists := os.LookupEnv("VAULTY_LOG_FILE") | ||
if exists { | ||
logFile, err := os.OpenFile(LOG_FILE, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0644) | ||
if err != nil { | ||
log.Panic().Err(err).Msg("Error opening log file") | ||
} | ||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: logFile, TimeFormat: zerolog.TimeFieldFormat}) | ||
} else { | ||
// If no log file is set, write to stdout | ||
log.Logger = zerolog.New(os.Stdout).With().Timestamp().Logger() | ||
} | ||
|
||
return logFile, &log.Logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.