Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use log-level: error for kics e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <bcsati@cisco.com>
csatib02 committed Jul 24, 2024
1 parent f0eda70 commit 36fb727
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/log/context.go
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ func GetLoggerFromContextOrDiscard(ctx context.Context) *log.Entry {
if !ok {
logger = log.NewEntry(&log.Logger{
Out: io.Discard,
Level: 0,
Level: log.PanicLevel,
}).WithContext(ctx)
}
return logger
7 changes: 4 additions & 3 deletions plugins/sdk-go/plugin/config.go
Original file line number Diff line number Diff line change
@@ -16,23 +16,24 @@
package plugin

import (
"log/slog"
"os"
)

const (
EnvLogLevel = "PLUGIN_SERVER_LOG_LEVEL"
DefaultLogLevel = "info"
DefaultLogLevel = slog.LevelError

EnvListenAddress = "PLUGIN_SERVER_LISTEN_ADDRESS"
DefaultListenAddress = "http://0.0.0.0:8080"
)

func getLogLevel() string {
func GetLogLevel() string {
if logLevel := os.Getenv(EnvLogLevel); logLevel != "" {
return logLevel
}

return DefaultLogLevel
return DefaultLogLevel.String()
}

func getListenAddress() string {
4 changes: 2 additions & 2 deletions plugins/sdk-go/plugin/logger.go
Original file line number Diff line number Diff line change
@@ -24,8 +24,8 @@ var logger *slog.Logger

func init() {
var logLevel slog.Level
if err := logLevel.UnmarshalText([]byte(getLogLevel())); err != nil {
logLevel = slog.LevelInfo
if err := logLevel.UnmarshalText([]byte(GetLogLevel())); err != nil {
logLevel = DefaultLogLevel
}

logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
4 changes: 4 additions & 0 deletions plugins/store/kics/main.go
Original file line number Diff line number Diff line change
@@ -70,6 +70,10 @@ func (s *Scanner) SetStatus(newStatus *types.Status) {
func (s *Scanner) Start(config types.Config) {
go func() {
logger := plugin.GetLogger()
err := printer.LogLevel(plugin.GetLogLevel(), false) //nolint:forbidigo
if err != nil {
logger.Error("Failed to set log level", slog.Any("error", err))
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(config.TimeoutSeconds)*time.Second)
s.cancel = cancel

0 comments on commit 36fb727

Please sign in to comment.