Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release new logging tool and C2 server name #49

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: "c2"
ref: "refs/heads/release"
client-id: "f26240e2-3095-4273-8559-2ca9a121991e"
server: "sql-radix-vulnerability-scan-c2-prod.database.windows.net"
server: "sql-radix-vulnerability-scan-c2.database.windows.net"

env:
connection: >-
Expand Down
4 changes: 2 additions & 2 deletions charts/radix-vulnerability-scanner/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
appVersion: 0.0.6
version: 0.0.6
appVersion: 0.0.7
version: 0.0.7
description: Scan images in RadixDeployments for vulnerabilities
name: radix-vulnerability-scanner
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/microsoft/go-mssqldb v1.6.0
github.com/mitchellh/mapstructure v1.5.0
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.9.3
github.com/rs/zerolog v1.31.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -50,6 +50,8 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
15 changes: 12 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0 h1:HCc0+LpPfpC
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/containerd/containerd v1.7.11 h1:lfGKw3eU35sjV0aG2eYZTiwFEY1pCzxdzicHP3SZILw=
github.com/containerd/containerd v1.7.11/go.mod h1:5UluHxHTX2rdvYuZ5OJTC5m/KJNs0Zs9wVoJm9zf5ZE=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -51,6 +52,7 @@ github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogB
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
Expand Down Expand Up @@ -118,6 +120,11 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/microsoft/go-mssqldb v1.6.0 h1:mM3gYdVwEPFrlg/Dvr2DNVEgYFG7L42l+dGc67NNNpc=
github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcEG0vx6Kbv2aJU=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down Expand Up @@ -150,12 +157,13 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
Expand Down Expand Up @@ -237,12 +245,13 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
58 changes: 38 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,66 @@ import (
"os/signal"
"strings"
"syscall"
"time"

"github.com/equinor/radix-vulnerability-scanner/pkg/server"

logger "github.com/sirupsen/logrus"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

func main() {
logger.SetLevel(logger.DebugLevel)
logger.Info("Starting Radix Vulnerability Scanner")

ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

opts, err := server.LoadOptions(os.Args[1:])
if err != nil {
panic(err)
log.Fatal().Msg(err.Error())
}

ctx, err = setupLogger(opts, ctx)
if err != nil {
log.Fatal().Msg(err.Error())
}

logOptions(opts)

srv, err := server.New(opts)
if err != nil {
panic(err)
log.Fatal().Msg(err.Error())
}

err = srv.Run(ctx.Done())
if err != nil {
panic(err)
log.Fatal().Msg(err.Error())
}
}

func setupLogger(opts *server.Options, ctx context.Context) (context.Context, error) {
zerolog.DurationFieldUnit = time.Millisecond
level, err := zerolog.ParseLevel(opts.LogLevel)
if err != nil {
return nil, err
}

zerolog.SetGlobalLevel(level)
if opts.PrettyPrint {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.TimeOnly})
}
ctx = log.Logger.WithContext(ctx)
return ctx, nil
}

func logOptions(opts *server.Options) {
logger.Info("Configuration")
logger.Infof(" full-sync-cron-spec: %v", opts.FullSyncCronSpec)
logger.Infof(" app-name-exclude-list: %v", strings.Join(opts.AppNameExcludeList, ","))
logger.Infof(" workers: %v", opts.Workers)
logger.Infof(" db-server: %v", opts.DB.Server)
logger.Infof(" db-database: %v", opts.DB.Database)
logger.Infof(" db-username: %v", opts.DB.UserName)
logger.Infof(" db-password set: %v", len(opts.DB.Password) > 0)
logger.Infof(" vulnerability-scan-timeout: %s", opts.VulnerabilityScan.ScanTimeout)
logger.Infof(" vulnerability-rescan-age: %s", opts.VulnerabilityScan.RescanAge)
logger.Infof(" docker-config-file: %s", opts.Docker.AuthsFile)
logger.Infof(" kube-config-file: %s", opts.Kube.KubeConfigFile)
log.Info().Msg("Configuration")
log.Info().Msgf(" full-sync-cron-spec: %v", opts.FullSyncCronSpec)
log.Info().Msgf(" app-name-exclude-list: %v", strings.Join(opts.AppNameExcludeList, ","))
log.Info().Msgf(" workers: %v", opts.Workers)
log.Info().Msgf(" db-server: %v", opts.DB.Server)
log.Info().Msgf(" db-database: %v", opts.DB.Database)
log.Info().Msgf(" db-username: %v", opts.DB.UserName)
log.Info().Msgf(" db-password set: %v", len(opts.DB.Password) > 0)
log.Info().Msgf(" vulnerability-scan-timeout: %s", opts.VulnerabilityScan.ScanTimeout)
log.Info().Msgf(" vulnerability-rescan-age: %s", opts.VulnerabilityScan.RescanAge)
log.Info().Msgf(" docker-config-file: %s", opts.Docker.AuthsFile)
log.Info().Msgf(" kube-config-file: %s", opts.Kube.KubeConfigFile)
}
10 changes: 5 additions & 5 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/equinor/radix-vulnerability-scanner/pkg/dockercfg"
"github.com/equinor/radix-vulnerability-scanner/pkg/generic"
"github.com/equinor/radix-vulnerability-scanner/pkg/scan"
logger "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
"k8s.io/utils/strings/slices"
)

Expand Down Expand Up @@ -75,16 +75,16 @@ func (s *imageVulnerabilityScanner) Handle(ctx context.Context, imageName string
if skipScan, err := s.isLastScanWithinRescanThreshold(ctx, imageName); err != nil {
return err
} else if skipScan {
logger.Infof("skipping scan of image %s, recently scanned", imageName)
log.Info().Str("image", imageName).Msgf("skipping scan of image, recently scanned")
return nil
}

logger.Infof("scanning image image %s", imageName)
log.Info().Str("image", imageName).Msgf("scanning image")
scanCtx, cancel := context.WithTimeout(ctx, s.scanTimeout)
defer cancel()
scanResult, err := s.scanner.Scan(scanCtx, imageName, dockerAuth)
if err != nil {
logger.Warnf("error scanning image %v: %v", imageName, err)
log.Warn().Str("image", imageName).Err(err).Msgf("error scanning image")
}
scanSuccess := err == nil
vulnerabilitiesBulk := []db.VulnerabilityBulkDto{}
Expand Down Expand Up @@ -133,7 +133,7 @@ func (s *imageVulnerabilityScanner) Handle(ctx context.Context, imageName string

dbCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
logger.Infof("storing scan results for image %s", imageName)
log.Info().Str("image", imageName).Msgf("storing scan results for image")
return s.repository.RegisterImageScan(dbCtx, imageName, baseImage, time.Now(), scanSuccess, vulnerabilitiesBulk, identifiersBulk, referencesBulk)
}

Expand Down
21 changes: 9 additions & 12 deletions pkg/imageworker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package imageworker
import (
"context"
"errors"
"fmt"
"sync"
"time"

"github.com/equinor/radix-vulnerability-scanner/pkg/handler"
"github.com/equinor/radix-vulnerability-scanner/pkg/observe"
"github.com/equinor/radix-vulnerability-scanner/pkg/utils"
logger "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
"k8s.io/client-go/util/workqueue"
)

Expand Down Expand Up @@ -44,7 +43,7 @@ func New(handler handler.Handler) *Worker {

// Receive implementation of Observer
func (w *Worker) Receive(obj observe.ImageInfo) {
logger.Infof("enqueuing image %v", obj.ImageName)
log.Info().Str("image", obj.ImageName).Msg("enqueuing image")
w.queue.Add(&obj)
}

Expand Down Expand Up @@ -85,31 +84,29 @@ func (w *Worker) processNextItem(ctx context.Context) bool {
return false
}

if err := w.processItem(ctx, item); err != nil {
logger.Error(err)
}
w.processItem(ctx, item)

return true
}

func (w *Worker) processItem(ctx context.Context, item any) error {
func (w *Worker) processItem(ctx context.Context, item any) {
defer w.queue.Done(item)

if image, ok := item.(*observe.ImageInfo); ok {
logger.Infof("processing image %v", image.ImageName)
log.Info().Str("image", image.ImageName).Msg("processing image")
if err := w.handler.Handle(ctx, image.ImageName, image.DockerAuths); err != nil {
requeues := w.queue.NumRequeues(image)
if requeues < maxNumberOfRequeues {
logger.Infof("requeuing scan of image %v (attempt %d of %d) due to error: %v", image.ImageName, requeues+1, maxNumberOfRequeues, err)
log.Info().Str("image", image.ImageName).Err(err).Msgf("requeuing scan of image (attempt %d of %d) due to error", requeues+1, maxNumberOfRequeues)
w.queue.AddRateLimited(item)
return nil
return
} else {
w.queue.Forget(item)
return fmt.Errorf("scan failed for image %v after %d retries: %v", image.ImageName, requeues, err)
log.Error().Str("image", image.ImageName).Err(err).Msgf("scan failed for image after %d retries", requeues)
return
}
}
}

w.queue.Forget(item)
return nil
}
4 changes: 2 additions & 2 deletions pkg/observe/radixdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/defaults"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-vulnerability-scanner/pkg/dockercfg"
logger "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -41,7 +41,7 @@ func (m *RadixDeploymentContainerImageMapper) Receive(rd *v1.RadixDeployment) {

dockerAuths, err := m.readDockerConfigJSON(rd.Namespace)
if err != nil {
logger.Warnf("unable to read dockerconfigjson secret: %v", err)
log.Warn().Err(err).Msg("unable to read dockerconfigjson secret")
}

for _, c := range rd.Spec.Components {
Expand Down
5 changes: 3 additions & 2 deletions pkg/scan/snyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

"github.com/containerd/containerd/reference/docker"
"github.com/equinor/radix-vulnerability-scanner/pkg/dockercfg"
"github.com/sirupsen/logrus"
"github.com/equinor/radix-vulnerability-scanner/pkg/utils/logwriter"
"github.com/rs/zerolog"
)

var _ Scanner = &snykScanner{}
Expand All @@ -23,7 +24,7 @@ type commandExecutorImpl struct{}

func (commandExecutorImpl) Execute(ctx context.Context, command string, args []string, stdOutWriter io.Writer) error {
cmd := exec.CommandContext(ctx, command, args...)
cmd.Stderr = logrus.NewEntry(logrus.StandardLogger()).WriterLevel(logrus.ErrorLevel)
cmd.Stderr = logwriter.New(zerolog.Ctx(ctx), zerolog.ErrorLevel)
cmd.Stdout = stdOutWriter

if err := cmd.Start(); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions pkg/server/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var defaultRescanAge = 24 * time.Hour
func LoadOptions(args []string) (opts *Options, err error) {
flagset := newOptionsFlagSet()
if err = flagset.Parse(args); err != nil {
return
return nil, err
}

v := viper.New()
Expand All @@ -28,21 +28,23 @@ func LoadOptions(args []string) (opts *Options, err error) {

opts = &Options{}
if err = registerFlags(v, "", flagset, opts); err != nil {
return
return nil, err
}

if err = v.UnmarshalExact(opts, func(dc *mapstructure.DecoderConfig) { dc.TagName = "cfg" }); err != nil {
return
return nil, err
}

return
return opts, nil
}

func newOptionsFlagSet() *pflag.FlagSet {
flagset := pflag.NewFlagSet("options", pflag.ExitOnError)
flagset.String("full-sync-cron-spec", defaultFullSyncCronSpec, "Cron schedule spec when full sync should run")
flagset.StringSlice("app-name-exclude-list", nil, "List of app names to exclude from scan")
flagset.Uint("workers", 1, "Number for image scan workers")
flagset.Bool("pretty-print", false, "Print colored text instead of json")
flagset.String("log-level", "debug", "Set log level (trace,debug,info,warn,error)")
flagset.AddFlagSet(dbFlagset())
flagset.AddFlagSet(dockerFlagset())
flagset.AddFlagSet(kubeFlagset())
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type (
FullSyncCronSpec string `flag:"full-sync-cron-spec" cfg:"full_sync_cron_spec"`
AppNameExcludeList []string `flag:"app-name-exclude-list" cfg:"app_name_exclude_list"`
Workers uint `flag:"workers" cfg:"workers"`
PrettyPrint bool `flag:"pretty-print" cfg:"pretty_print" default:"false"`
LogLevel string `flag:"log-level" cfg:"log_level" default:"debug"`
DB DBOptions `cfg:",squash"`
Docker DockerOptions `cfg:",squash"`
Kube KubeOptions `cfg:",squash"`
Expand Down
21 changes: 21 additions & 0 deletions pkg/utils/logwriter/logwriter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package logwriter

import (
"io"

"github.com/rs/zerolog"
)

type LogWriter struct {
log *zerolog.Logger
level zerolog.Level
}

func New(log *zerolog.Logger, level zerolog.Level) io.Writer {
return LogWriter{log, level}
}

func (l LogWriter) Write(p []byte) (n int, err error) {
l.log.WithLevel(l.level).Msg(string(p))
return len(p), nil
}
Loading