mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2026-05-12 11:59:53 -05:00
move debug log
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ builds:
|
||||
- -s -w
|
||||
- -X main.Version={{ .Version }}
|
||||
- -X main.Commit={{ .Commit }}
|
||||
- -X main.BuildDate={{ .CommitDate }}
|
||||
- -X main.Date={{ .CommitDate }}
|
||||
goos:
|
||||
- linux
|
||||
# - darwin
|
||||
|
||||
@@ -6,15 +6,10 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"os"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/caarlos0/env/v11"
|
||||
"github.com/google/uuid"
|
||||
"github.com/lmittmann/tint"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/mizuchilabs/mantrae/internal/backup"
|
||||
"github.com/mizuchilabs/mantrae/internal/dns"
|
||||
"github.com/mizuchilabs/mantrae/internal/settings"
|
||||
@@ -30,7 +25,7 @@ type EnvConfig struct {
|
||||
AdminEmail string `env:"ADMIN_EMAIL"`
|
||||
BaseURL string `env:"BASE_URL" envDefault:"http://localhost:3000"`
|
||||
FrontendURL string `env:"FRONTEND_URL" envDefault:"http://localhost:5173"`
|
||||
Debug bool `env:"DEBUG" envDefault:"false"`
|
||||
Debug bool
|
||||
Version string
|
||||
}
|
||||
|
||||
@@ -51,14 +46,11 @@ func New(ctx context.Context, cmd *cli.Command) (*App, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Merge command line flags (can override environment variables)
|
||||
if cmd != nil {
|
||||
app.Debug = cmd.Bool("debug")
|
||||
app.Version = cmd.Root().Version
|
||||
}
|
||||
|
||||
app.initLogger()
|
||||
|
||||
if !slices.Contains([]int{16, 24, 32}, len(app.Secret)) {
|
||||
return nil, fmt.Errorf("secret must be either 16, 24 or 32 bytes, is %d", len(app.Secret))
|
||||
}
|
||||
@@ -75,21 +67,6 @@ func New(ctx context.Context, cmd *cli.Command) (*App, error) {
|
||||
return &app, app.setupDefaultData(ctx)
|
||||
}
|
||||
|
||||
func (a App) initLogger() {
|
||||
level := slog.LevelInfo
|
||||
if a.Debug {
|
||||
level = slog.LevelDebug
|
||||
}
|
||||
|
||||
slog.SetDefault(slog.New(
|
||||
tint.NewHandler(colorable.NewColorable(os.Stderr), &tint.Options{
|
||||
Level: level,
|
||||
TimeFormat: time.RFC3339,
|
||||
NoColor: !isatty.IsTerminal(os.Stderr.Fd()),
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
func (a *App) setupDefaultData(ctx context.Context) error {
|
||||
q := a.Conn.Q
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
@@ -15,9 +16,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Version = "dev"
|
||||
Commit = "none"
|
||||
BuildDate = "unknown"
|
||||
Version = "dev"
|
||||
Commit = "none"
|
||||
Date = "unknown"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -25,11 +26,18 @@ func main() {
|
||||
EnableShellCompletion: true,
|
||||
Suggest: true,
|
||||
Name: "mantrae",
|
||||
Version: Version,
|
||||
Usage: "mantrae [command]",
|
||||
Description: `Mantrae simplifies the management of Traefik reverse proxy configurations through an intuitive web interface. Manage routers, middleware, services, and DNS providers with ease.
|
||||
|
||||
See https://github.com/mizuchilabs/mantrae for more information.`,
|
||||
Version: fmt.Sprintf("%s (commit: %s, built: %s)", Version, Commit, Date),
|
||||
Usage: "traefik configuration manager",
|
||||
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
|
||||
level := slog.LevelInfo
|
||||
if cmd.Bool("debug") {
|
||||
level = slog.LevelDebug
|
||||
}
|
||||
slog.SetDefault(
|
||||
slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})),
|
||||
)
|
||||
return ctx, nil
|
||||
},
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
app, err := config.New(ctx, cmd)
|
||||
if err != nil {
|
||||
@@ -62,9 +70,10 @@ to specify a different username.`,
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "version",
|
||||
Aliases: []string{"v"},
|
||||
Usage: "Display version information and exit",
|
||||
Name: "debug",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "Enable debug logging",
|
||||
Sources: cli.EnvVars("MANTRAE_DEBUG"),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "password",
|
||||
|
||||
Reference in New Issue
Block a user