chore: add logger
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2025-01-06 21:52:07 +01:00
parent 7f64ff3b85
commit fda6d10897
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
6 changed files with 54 additions and 4 deletions

View File

@ -4,11 +4,13 @@ import (
"fmt"
"os"
"github.com/spf13/cobra"
"git.front.kjuulh.io/kjuulh/orbis/internal/app"
)
func main() {
if err := newRoot().Execute(); err != nil {
app := app.NewApp()
if err := newRoot(app).Execute(); err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}

View File

@ -1,11 +1,22 @@
package main
import "github.com/spf13/cobra"
import (
"git.front.kjuulh.io/kjuulh/orbis/internal/app"
"github.com/spf13/cobra"
)
func newRoot(app *app.App) *cobra.Command {
logger := app.Logger()
func newRoot() *cobra.Command {
cmd := &cobra.Command{
Use: "orbis",
Short: "Orbis is a data workflow scheduler for all your batch and real-time needs",
RunE: func(cmd *cobra.Command, args []string) error {
logger.Info("starting orbis")
return nil
},
}
return cmd

2
go.mod
View File

@ -7,4 +7,6 @@ require github.com/spf13/cobra v1.8.1
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gitlab.com/greyxor/slogor v1.6.0 // indirect
golang.org/x/sys v0.28.0 // indirect
)

4
go.sum
View File

@ -6,5 +6,9 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gitlab.com/greyxor/slogor v1.6.0 h1:K9QsAoa4leFQfO2RF2MkZ8BYkk2HQpYWykmd4G5R5+Y=
gitlab.com/greyxor/slogor v1.6.0/go.mod h1:6UWQsLLkeNL4o911soP9jvCMzXWgokLqzZP+eekAyyU=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

19
internal/app/app.go Normal file
View File

@ -0,0 +1,19 @@
package app
import (
"log/slog"
)
type App struct {
logger *slog.Logger
}
func NewApp() *App {
return &App{
logger: setupLogging(),
}
}
func (a *App) Logger() *slog.Logger {
return a.logger
}

12
internal/app/logging.go Normal file
View File

@ -0,0 +1,12 @@
package app
import (
"log/slog"
"os"
"gitlab.com/greyxor/slogor"
)
func setupLogging() *slog.Logger {
return slog.New(slogor.NewHandler(os.Stderr))
}