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

fix(e2e): default kics log-level to error to avoid excessive log messages #1955

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 core/log/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions plugins/sdk-go/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions plugins/sdk-go/plugin/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion plugins/sdk-python/plugin/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.parse import urlparse

ENV_LOG_LEVEL = "PLUGIN_SERVER_LOG_LEVEL"
DEFAULT_LOG_LEVEL = "info"
DEFAULT_LOG_LEVEL = logging.ERROR

ENV_LISTEN_ADDRESS = "PLUGIN_SERVER_LISTEN_ADDRESS"
DEFAULT_LISTEN_ADDRESS = "http://0.0.0.0:8080"
Expand Down
1 change: 1 addition & 0 deletions plugins/sdk-python/plugin/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# Init logger
_logger = logging.getLogger('plugin.scanner')
_logger.setLevel(_config.get_log_level())
_logger.addHandler(logging.StreamHandler(sys.stdout))


Expand Down
4 changes: 4 additions & 0 deletions plugins/store/kics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down