grim/hgkeeper

Use logging for "serve" only

12 months ago, aklitzing
7521929c818e
Parents 007bff89399e
Children a2db929144c4
Use logging for "serve" only

Logging is enabled and disabled for "authorized_keys" and "once" shouldn't
enable logging, too.
So let's enable logging for "serve" only.

Bugs closed: HGKEEPER-23

Reviewed at https://reviews.imfreedom.org/r/2433/
--- a/authorized_keys/command.go Tue Apr 11 21:21:38 2023 -0500
+++ b/authorized_keys/command.go Tue Apr 11 21:24:09 2023 -0500
@@ -4,8 +4,6 @@
"fmt"
"strings"
- "go.uber.org/zap"
- "go.uber.org/zap/zapcore"
"keep.imfreedom.org/grim/hgkeeper/access"
"keep.imfreedom.org/grim/hgkeeper/globals"
)
@@ -16,14 +14,6 @@
}
func (c *Command) Run(g *globals.Globals) error {
- // we're generating output for another command so we need to turn off our
- // normal logging.
- logger, _ := zap.Config{
- Encoding: "console",
- Level: zap.NewAtomicLevelAt(zapcore.FatalLevel),
- }.Build()
- zap.ReplaceGlobals(logger)
-
if err := access.Setup(g.ReposPath, g.AdminRepo); err != nil {
return err
}
--- a/main.go Tue Apr 11 21:21:38 2023 -0500
+++ b/main.go Tue Apr 11 21:24:09 2023 -0500
@@ -26,7 +26,7 @@
Version version.Command `kong:"cmd,help='display the version and exit'"`
}
-func init() {
+func initLogging() {
levelEncoder := zapcore.CapitalColorLevelEncoder
switch os.Getenv("TERM") {
case "win":
@@ -59,6 +59,10 @@
cmd := commands{}
ctx := kong.Parse(&cmd)
+ if ctx.Command() == "serve" {
+ initLogging()
+ }
+
if err := hg.SetExe(cmd.Globals.HgExecutable); err != nil {
ctx.FatalIfErrorf(err)
}