Skip to content

Commit 2da90cc

Browse files
committed
fix: PR comments
fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments fix: PR comments
1 parent 70ecc3e commit 2da90cc

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

cmd/base/options/log.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type LogsOptions struct {
2828
LogFileMaxSizeInMB uint64
2929
SupportAsyncLogging bool
3030
LogDir string
31-
LogBufferSizeMB int
31+
LogBufferSize int
3232
LogFileMaxAge int
3333
LogFileMaxBackups int
3434
}
@@ -37,19 +37,19 @@ func NewLogsOptions() *LogsOptions {
3737
return &LogsOptions{
3838
LogPackageLevel: general.LoggingPKGFull,
3939
LogFileMaxSizeInMB: 1800,
40-
LogBufferSizeMB: 10000,
40+
LogBufferSize: 10000,
4141
LogFileMaxAge: 7,
4242
LogFileMaxBackups: 10,
4343
}
4444
}
4545

4646
// AddFlags adds flags to the specified FlagSet.
4747
func (o *LogsOptions) AddFlags(fs *pflag.FlagSet) {
48+
fs.BoolVar(&o.SupportAsyncLogging, "support-async-logging", o.SupportAsyncLogging, "whether to support async logging")
49+
fs.StringVar(&o.LogDir, "async_log_dir", o.LogDir, "directory to store logs")
4850
fs.Var(&o.LogPackageLevel, "logs-package-level", "the default package level for logging")
4951
fs.Uint64Var(&o.LogFileMaxSizeInMB, "log-file-max-size", o.LogFileMaxSizeInMB, "Max size of klog file in MB.")
50-
fs.BoolVar(&o.SupportAsyncLogging, "support-async-logging", o.SupportAsyncLogging, "whether to support async logging")
51-
fs.StringVar(&o.LogDir, "log-dir", o.LogDir, "directory of log file")
52-
fs.IntVar(&o.LogBufferSizeMB, "log-buffer-size", o.LogBufferSizeMB, "size of the ring buffer to store async logs")
52+
fs.IntVar(&o.LogBufferSize, "log-buffer-size", o.LogBufferSize, "size of the ring buffer to store async logs")
5353
fs.IntVar(&o.LogFileMaxAge, "log-file-max-age", o.LogFileMaxAge, "max age of klog log file in days")
5454
fs.IntVar(&o.LogFileMaxBackups, "log-file-max-backups", o.LogFileMaxBackups, "max number of klog log file backups")
5555
}
@@ -59,8 +59,8 @@ func (o *LogsOptions) ApplyTo(c *generic.LogConfiguration) error {
5959
general.SetLogFileMaxSize(o.LogFileMaxSizeInMB)
6060
c.SupportAsyncLogging = o.SupportAsyncLogging
6161
c.LogDir = o.LogDir
62+
c.LogBufferSize = o.LogBufferSize
6263
c.LogFileMaxSize = int(o.LogFileMaxSizeInMB)
63-
c.LogBufferSizeMB = o.LogBufferSizeMB
6464
c.LogFileMaxAge = o.LogFileMaxAge
6565
c.LogFileMaxBackups = o.LogFileMaxBackups
6666
return nil

cmd/katalyst-agent/app/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func Run(
6464
}
6565

6666
if conf.SupportAsyncLogging {
67-
asyncLogger := logging.NewAsyncLogger(genericCtx, conf.LogDir, conf.LogFileMaxSize, conf.LogFileMaxAge, conf.LogFileMaxBackups, conf.LogBufferSizeMB)
67+
asyncLogger := logging.NewAsyncLogger(genericCtx, conf.LogDir, conf.LogFileMaxSize, conf.LogFileMaxAge, conf.LogFileMaxBackups, conf.LogBufferSize)
6868
defer asyncLogger.Shutdown()
6969
}
7070

pkg/config/generic/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type LogConfiguration struct {
2020
SupportAsyncLogging bool
2121
LogDir string
2222
LogFileMaxSize int
23-
LogBufferSizeMB int
23+
LogBufferSize int
2424
LogFileMaxAge int
2525
LogFileMaxBackups int
2626
}

pkg/util/logging/logger.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ limitations under the License.
1717
package logging
1818

1919
import (
20+
"fmt"
21+
"os"
2022
"path"
23+
"path/filepath"
2124
"time"
2225

2326
"github.com/rs/zerolog/diode"
@@ -44,11 +47,11 @@ const (
4447
metricsNameNumDroppedFatalLogs = "number_of_dropped_fatal_logs"
4548
)
4649

47-
const (
48-
defaultInfoLogFileName = "agent.info.log"
49-
defaultWarningLogFileName = "agent.warning.log"
50-
defaultErrorLogFileName = "agent.error.log"
51-
defaultFatalLogFileName = "agent.fatal.log"
50+
var (
51+
defaultInfoLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), InfoSeverity)
52+
defaultWarningLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), WarningSeverity)
53+
defaultErrorLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), ErrorSeverity)
54+
defaultFatalLogFileName = fmt.Sprintf("%s.%s.log", filepath.Base(os.Args[0]), FatalSeverity)
5255
)
5356

5457
type logInfo struct {
@@ -70,7 +73,7 @@ type AsyncLogger struct {
7073
// NewAsyncLogger creates an async logger that produces an async writer for each of the severity levels.
7174
// The async writer spins up a goroutine that periodically flushes the buffered logs to disk.
7275
func NewAsyncLogger(
73-
agentCtx *agent.GenericContext, logDir string, maxSizeMB, maxAge, maxBackups, bufferSizeMB int,
76+
agentCtx *agent.GenericContext, logDir string, maxSizeMB, maxAge, maxBackups, bufferSize int,
7477
) *AsyncLogger {
7578
wrappedEmitter := agentCtx.EmitterPool.GetDefaultMetricsEmitter()
7679

@@ -85,7 +88,7 @@ func NewAsyncLogger(
8588
}
8689

8790
// diodeWriter is a writer that stores logs in a ring buffer and asynchronously flushes them
88-
diodeWriter := diode.NewWriter(lumberjackLogger, bufferSizeMB, 10*time.Millisecond, func(missed int) {
91+
diodeWriter := diode.NewWriter(lumberjackLogger, bufferSize, 10*time.Millisecond, func(missed int) {
8992
_ = wrappedEmitter.StoreInt64(logInfo.metricsName, int64(missed), metrics.MetricTypeNameRaw)
9093
})
9194
// Overrides the default synchronous writer with the diode writer

0 commit comments

Comments
 (0)