Created
October 18, 2022 23:09
-
-
Save gj1118/a4139acb6666b9bc5a00306c2fb82693 to your computer and use it in GitHub Desktop.
using Lumberjack and Zerolog
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
package main | |
import ( | |
"log" | |
"os" | |
"path" | |
"strings" | |
"github.com/rs/zerolog" | |
"gopkg.in/natefinch/lumberjack.v2" | |
) | |
const LOGDIRECTORY = "dirwalker_logs" | |
const LOG_FILE_NAME = "dirwalker.log" | |
const MAXBACKUPS = 10 | |
const MAXSIZE = 10 | |
const MAXAGE = 10 | |
func setupLogger() { | |
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix | |
zerolog.SetGlobalLevel(zerolog.InfoLevel) | |
currentWorkingDirectory, _ := os.Getwd() | |
loggerPath := path.Join(currentWorkingDirectory, LOGDIRECTORY) | |
customeLogger := lumberjack.Logger{ | |
Filename: path.Join(loggerPath, LOG_FILE_NAME), | |
MaxBackups: MAXBACKUPS, // files | |
MaxSize: MAXSIZE, // megabytes | |
MaxAge: MAXAGE, // days | |
} | |
logger := zerolog.New(&customeLogger).With().Timestamp().Logger() | |
logger.Info().Msg("Logger setup complete") | |
} | |
func main() { | |
log.Println("Logger 1.0") | |
setupLogger() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment