Skip to content

Implement flag parsing for Logging. #4474

Open
@ShohamBit

Description

@ShohamBit
### Tasks
- [x] Implement `level` flag
- [x] Implement `file` flag
- [x] Implement `aggregation.enabled` flag
- [x] Implement `aggregation.flush-interval` flag
- [x] Implement `filters.include` flags (`msg`, `package`, `file`, `level`, `regex`)
- [x] Implement `filters.exclude` flags (`msg`, `package`, `file`, `level`, `regex`)
- [x] Update configuration file parsing to support the new log section
- [x] Document new flag design
- [x] Test new flag design

The following design describes the CLI flag:

Logging
--log level=<level>
--log file=<path>
--log aggregation.enabled=<true/false>
--log aggregation.flush-interval=<interval>
--log filters.include.msg=<message> (multiple allowed)
--log filters.include.package=<package> (multiple allowed)
--log filters.include.file=<file> (multiple allowed)
--log filters.include.level=<level> (multiple allowed)
--log filters.include.regex=<pattern> (multiple allowed)
--log filters.include.libbpf
--log filters.exclude.msg=<message> (multiple allowed)
--log filters.exclude.package=<package> (multiple allowed)
--log filters.exclude.file=<file> (multiple allowed)
--log filters.exclude.level=<level> (multiple allowed)
--log filters.exclude.regex=<pattern> (multiple allowed)
--log filters.exclude.libbpf

The following design describes the config:

log:
  level: info               # debug, info, warn, error, fatal, panic (default: info)
  file: ""                  # Path to the log file (optional, defaults to stdout)
  aggregation:                 
    enabled: false          # Enable log aggregation (default: false)
    flush-interval: "5s"    # Aggregation interval (e.g., "5s", "1m", "1h") (default: "5s")
  filters:                  # Filter log messages
    include:                # Include messages based on criteria (optional)
      libbpf: true          # Include logs that originate from libbpf
      msg:                    
        - SampleMessage1    # Include messages containing this string 
      package:                 
        - package1          # Include messages from this package
      file:                   
        - file1.go          # Include messages from this file
      level:                  
        - warn              # Include messages with this log level or higher
      regex:
        - ^pattern1         # Include messages matching this regex pattern
    exclude:                # Exclude messages based on criteria (optional)
    libbpf: true            # Exclude logs that originate from libbpf
      msg:
        - ExcludedMessage1  # Exclude messages containing this string
      package:
        - excludedPackage   # Exclude messages from this package
      file:
        - excludedFile.go   # Exclude messages from this file
      level:
        - debug             # Exclude messages with this log level
      regex:
        - ^excludedPattern  # Exclude messages matching this regex pattern

Implementation Notes

  • Multiple values: Ensure the implementation correctly handles flags that can accept multiple values (e.g., --log filters.include.msg).
  • Regular expressions: Implement proper parsing and handling of regular expressions in filter flags.
  • Log level validation: Validate log level values to ensure they are valid.
  • Aggregation interval parsing: Implement parsing of the flush-interval value to handle different time units (seconds, minutes, hours).
  • Configuration merging: Define how CLI flags and configuration file settings will be merged, with CLI flags potentially overriding config file values.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions