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

automatically slices --eventaddr file to the specified size( similar to lograte) #720

Open
chilli13 opened this issue Jan 13, 2025 · 3 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@chilli13
Copy link

In a continuous traffic environment, ./ecapture-perf tls --eventaddr=xxx.txt may generate a large ecapture file xxx.txt, is it possible to consider using golang rolling file library, such as lumberjack/rotatelogs, to integrate with zerolog and support automatic slicing of eventaddr specified files (the file handler that receives the captured event)? Thks

@dosubot dosubot bot added the enhancement New feature or request label Jan 13, 2025
@cfc4n
Copy link
Member

cfc4n commented Jan 13, 2025

In a continuous traffic environment, ./ecapture-perf tls --eventaddr=xxx.txt may generate a large ecapture file xxx.txt, is it possible to consider using golang rolling file library, such as lumberjack/rotatelogs, to integrate with zerolog and support automatic slicing of eventaddr specified files (the file handler that receives the captured event)? Thks

@dosu

Copy link

dosubot bot commented Jan 13, 2025

To implement automatic file slicing for the --eventaddr option in ecapture, you can integrate a rolling file library like lumberjack with zerolog. Here's a general approach to achieve this:

  1. Add Lumberjack Dependency: First, add the lumberjack package to your go.mod file to manage log file rotation.

  2. Integrate Lumberjack with Zerolog: Modify the logger initialization to use lumberjack as the output writer. Here's a basic example:

    import (
        "github.com/rs/zerolog"
        "gopkg.in/natefinch/lumberjack.v2"
        "os"
    )
    
    func initLogger(addr string, modConfig config.IConfig) zerolog.Logger {
        var logger zerolog.Logger
        var writer zerolog.ConsoleWriter
    
        if addr != "" {
            writer = zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
        } else {
            writer = &lumberjack.Logger{
                Filename:   addr,
                MaxSize:    100, // megabytes
                MaxBackups: 3,
                MaxAge:     28,   // days
                Compress:   true, // disabled by default
            }
        }
    
        logger = zerolog.New(writer).With().Timestamp().Logger()
        zerolog.SetGlobalLevel(zerolog.InfoLevel)
        if modConfig.GetDebug() {
            zerolog.SetGlobalLevel(zerolog.DebugLevel)
        }
    
        return logger
    }
  3. Configure Lumberjack: Adjust the lumberjack.Logger settings such as MaxSize, MaxBackups, and MaxAge to suit your needs for file rotation and retention.

This setup will allow ecapture to automatically manage the size of the --eventaddr file, rotating it when it reaches the specified size limit.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@cfc4n
Copy link
Member

cfc4n commented Jan 13, 2025

--eventaddr can be a TCP Server, and you can customize the way logs are processed.

@cfc4n cfc4n added wontfix This will not be worked on and removed enhancement New feature or request labels Jan 13, 2025
@dosubot dosubot bot added the enhancement New feature or request label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants