Skip to content

Commit

Permalink
Change log timestamp format to RFC3339Nano.
Browse files Browse the repository at this point in the history
Closes #880.
  • Loading branch information
LandonTClipp committed Jan 2, 2025
1 parent f5b3134 commit 3c1cf74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ func (r *RootApp) Run() error {
}
parser := pkg.NewParser(buildTags)

log.Info().Msg("Parsing configured packages...")
interfaces, err := parser.ParsePackages(ctx, configuredPackages)
if err != nil {
log.Error().Err(err).Msg("unable to parse packages")
return err
}
log.Info().Msg("Done parsing configured packages.")
// maps the following:
// outputFilePath|fullyQualifiedInterfaceName|[]*pkg.Interface
// The reason why we need an interior map of fully qualified interface name
Expand All @@ -256,7 +258,7 @@ func (r *RootApp) Run() error {
ifaceLog.Debug().Msg("config doesn't specify to generate this interface, skipping.")
continue
}
ifaceLog.Debug().Msg("config specifies to generate this interface")
ifaceLog.Info().Msg("Adding interface")
ifaceConfigs, err := r.Config.GetInterfaceConfig(ctx, iface.Pkg.PkgPath, iface.Name)
if err != nil {
return err
Expand Down Expand Up @@ -311,15 +313,18 @@ func (r *RootApp) Run() error {
if err != nil {
return err
}
fileLog.Info().Msg("Executing template")
templateBytes, err := generator.Generate(fileCtx, interfacesInFile.interfaces)
if err != nil {
return err
}

outFile := pathlib.NewPath(outFilePath)
if err := outFile.Parent().MkdirAll(); err != nil {
log.Err(err).Msg("failed to mkdir parent directories of mock file")
return stackerr.NewStackErr(err)
}
fileLog.Info().Msg("Writing template to file")
if err := outFile.WriteFile(templateBytes); err != nil {
return stackerr.NewStackErr(err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ func GetLogger(levelStr string) (zerolog.Logger, error) {
return zerolog.Logger{}, stackerr.NewStackErrf(err, "Couldn't parse log level")
}
out := os.Stderr
// This is essentially RFC3339Nano, but we don't truncate trailing zeros so
// that the log fields are somewhat aligned.
timeFormat := "2006-01-02T15:04:05.000000000Z07:00"
writer := zerolog.ConsoleWriter{
Out: out,
TimeFormat: time.RFC822,
TimeFormat: timeFormat,
}
zerolog.TimeFieldFormat = timeFormat
if !term.IsTerminal(int(out.Fd())) || os.Getenv("TERM") == "dumb" { //nolint:gosec
writer.NoColor = true
}
Expand Down

0 comments on commit 3c1cf74

Please sign in to comment.