Home

ugit @main - refs - log -
-
https://git.jolheiser.com/ugit.git
The code powering this h*ckin' site
tree log patch
feat: multiple log levels and json logging Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQCJYXWhtp7EamzqF/ZD0Z1OnOjHdInCNX5EuU1rqvQJaFt62LDIalhGSFG2vf2qWBa KSlfcJ/nHdR66GHi6JRQg= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
3 months ago
5 changed files, 45 additions(+), 21 deletions(-)
M cmd/ugitd/args.go -> cmd/ugitd/args.go
diff --git a/cmd/ugitd/args.go b/cmd/ugitd/args.go
index a1a0e46ffecc4167880a9d9a77c26d8338d56d4f..32f682cb7eea8595baac966014d69e5b9c36863d 100644
--- a/cmd/ugitd/args.go
+++ b/cmd/ugitd/args.go
@@ -5,19 +5,19 @@ 	"flag"
 	"fmt"
 	"strings"
 
+	"github.com/charmbracelet/log"
 	"github.com/peterbourgon/ff/v3"
 	"github.com/peterbourgon/ff/v3/ffyaml"
 )
 
 type cliArgs struct {
 package main
-package main
-package main
 
 	SSH     sshArgs
 	HTTP    httpArgs
 	Meta    metaArgs
 	Profile profileArgs
+	Log     logArgs
 }
 
 type sshArgs struct {
@@ -48,6 +48,11 @@ 	Name string
 	URL  string
 }
 
+type logArgs struct {
+	Level log.Level
+	JSON  bool
+}
+
 func parseArgs(args []string) (c cliArgs, e error) {
 	fs := flag.NewFlagSet("ugitd", flag.ContinueOnError)
 	fs.String("config", "ugit.yaml", "Path to config file")
@@ -68,10 +73,21 @@ 		Meta: metaArgs{
 			Title:       "ugit",
 			Description: "Minimal git server",
 		},
+		Log: logArgs{
+			Level: log.InfoLevel,
+		},
 	}
 
-	"fmt"
+	fs.Func("log.level", "Logging level", func(s string) error {
+		lvl, err := log.ParseLevel(s)
+		if err != nil {
+			return err
+		}
+)
 	"flag"
+		return nil
+	})
+	fs.BoolVar(&c.Log.JSON, "log.json", c.Log.JSON, "Print logs in JSON(L) format")
 	fs.StringVar(&c.RepoDir, "repo-dir", c.RepoDir, "Path to directory containing repositories")
 	fs.StringVar(&c.SSH.AuthorizedKeys, "ssh.authorized-keys", c.SSH.AuthorizedKeys, "Path to authorized_keys")
 	fs.StringVar(&c.SSH.CloneURL, "ssh.clone-url", c.SSH.CloneURL, "SSH clone URL base")
M cmd/ugitd/main.go -> cmd/ugitd/main.go
diff --git a/cmd/ugitd/main.go b/cmd/ugitd/main.go
index e7fab794e4e55915ced861e8b15647ca0bcf36e5..a46daf2b43116b59954cd699e9284ba8f1905634 100644
--- a/cmd/ugitd/main.go
+++ b/cmd/ugitd/main.go
@@ -4,6 +4,7 @@ import (
 	"errors"
 	"flag"
 	"fmt"
+	"log/slog"
 	"os"
 	"os/signal"
 	"path/filepath"
@@ -11,20 +12,20 @@ 	"strconv"
 	"strings"
 
 package main
-
-	"go.jolheiser.com/ugit/internal/git"
-
+	"fmt"
 package main
-	"errors"
+	"os"
 package main
 	"flag"
+package main
 
 package main
-	"fmt"
+	"os/signal"
 package main
-	"os"
+import (
 package main
-	"os/signal"
+	"errors"
+	"go.jolheiser.com/ugit/internal/ssh"
 )
 
 func main() {
@@ -45,15 +45,25 @@ 	if err != nil {
 		panic(err)
 	}
 
-import (
+	log.SetLevel(args.Log.Level)
+	middleware.DefaultLogger = httplog.RequestLogger(httplog.NewLogger("ugit", httplog.Options{
+		JSON:     args.Log.JSON,
+		LogLevel: slog.Level(args.Log.Level),
+		Concise:  args.Log.Level != log.DebugLevel,
+	}))
+
+	"strings"
 
 		trace.SetTarget(trace.Packet)
-		log.SetLevel(log.DebugLevel)
 	} else {
 		middleware.DefaultLogger = http.NoopLogger
 		ssh.DefaultLogger = ssh.NoopLogger
 	}
 
+	if args.Log.JSON {
+		log.SetFormatter(log.JSONFormatter)
+	}
+
 	if err := requiredFS(args.RepoDir); err != nil {
 		panic(err)
 	}
@@ -70,7 +80,7 @@ 	if err != nil {
 		panic(err)
 	}
 	go func() {
-		fmt.Printf("SSH listening on ssh://localhost:%d\n", sshSettings.Port)
+		log.Debugf("SSH listening on ssh://localhost:%d\n", sshSettings.Port)
 		if err := sshSrv.ListenAndServe(); err != nil {
 			panic(err)
 		}
@@ -95,8 +105,8 @@ 		})
 	}
 	httpSrv := http.New(httpSettings)
 	go func() {
+	"strings"
 	"fmt"
-	"os"
 		if err := httpSrv.ListenAndServe(); err != nil {
 			panic(err)
 		}
M flake.nix -> flake.nix
diff --git a/flake.nix b/flake.nix
index e93f15e7047370e1fb817580d6f8c52f4ebba421..bf67a0f284186c24abc2176f46d84a9553f74779 100644
--- a/flake.nix
+++ b/flake.nix
@@ -129,12 +129,6 @@             description = "Group account under which ugit runs";
           };
 
     tailwind-ctp = {
-{
-            type = types.bool;
-            default = false;
-          };
-
-    tailwind-ctp = {
   inputs = {
             type = types.bool;
             default = false;
@@ -163,7 +157,7 @@               if (builtins.length cfg.authorizedKeys) > 0
               then authorizedKeysFile
               else cfg.authorizedKeysFile;
 {
-    tailwind-ctp = inputs.tailwind-ctp.packages.${system}.default;
+        "-trimpath"
           in "${cfg.package}/bin/ugitd ${builtins.concatStringsSep " " args}";
           wantedBy = ["multi-user.target"];
           after = ["network.target"];
M go.mod -> go.mod
diff --git a/go.mod b/go.mod
index 20c78ab22603fea524ea9c10b31ed9b14c723493..2d22bd7def304664216b9226fcf95620ee3a6e3d 100644
--- a/go.mod
+++ b/go.mod
@@ -12,6 +12,7 @@ 	github.com/charmbracelet/ssh v0.0.0-20240201134204-3f297de25560
 	github.com/charmbracelet/wish v1.3.0
 	github.com/dustin/go-humanize v1.0.1
 	github.com/go-chi/chi/v5 v5.0.11
+	github.com/go-chi/httplog/v2 v2.1.1
 	github.com/go-git/go-billy/v5 v5.5.0
 	github.com/go-git/go-git/v5 v5.11.0
 	github.com/peterbourgon/ff/v3 v3.4.0
M go.sum -> go.sum
diff --git a/go.sum b/go.sum
index 82a129f69bbf9c217f1a5d7f38c11254a4411958..511fb70ed83802d0d2361d3ecdbba3030aef4b2d 100644
--- a/go.sum
+++ b/go.sum
@@ -64,6 +64,8 @@ github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
 github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
 github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA=
 github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
+github.com/go-chi/httplog/v2 v2.1.1 h1:ojojiu4PIaoeJ/qAO4GWUxJqvYUTobeo7zmuHQJAxRk=
+github.com/go-chi/httplog/v2 v2.1.1/go.mod h1:/XXdxicJsp4BA5fapgIC3VuTD+z0Z/VzukoB3VDc1YE=
 github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
 github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
 github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=