Skip to content

Instantly share code, notes, and snippets.

@gj1118
Created October 18, 2022 23:09
Show Gist options
  • Save gj1118/a4139acb6666b9bc5a00306c2fb82693 to your computer and use it in GitHub Desktop.
Save gj1118/a4139acb6666b9bc5a00306c2fb82693 to your computer and use it in GitHub Desktop.
using Lumberjack and Zerolog
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