Skip to content

Commit

Permalink
Revert "cli: support logger level (#558)"
Browse files Browse the repository at this point in the history
This reverts commit 6a0bab3.
  • Loading branch information
cfc4n committed May 31, 2024
1 parent ed45679 commit 1564d61
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/go-c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ jobs:
cd ./lib/libpcap/ && sudo make install
cd $GITHUB_WORKSPACE
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v4
with:
args: --disable-all -E errcheck -E staticcheck
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
problem-matchers: true
- name: Build NOCORE
run: |
make clean
Expand Down
14 changes: 7 additions & 7 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func init() {
cobra.EnablePrefixMatching = true
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.PersistentFlags().BoolVarP(&globalConf.Debug, "debug", "d", false, "enable debug logging")
rootCmd.PersistentFlags().BoolVarP(&globalConf.Debug, "debug", "d", false, "enable debug logging.(coming soon)")
rootCmd.PersistentFlags().Uint8VarP(&globalConf.BtfMode, "btf", "b", 0, "enable BTF mode.(0:auto; 1:core; 2:non-core)")
rootCmd.PersistentFlags().BoolVar(&globalConf.IsHex, "hex", false, "print byte strings as hex encoded strings")
rootCmd.PersistentFlags().IntVar(&globalConf.PerCpuMapSize, "mapsize", 1024, "eBPF map size per CPU,for events buffer. default:1024 * PAGESIZE. (KB)")
Expand All @@ -126,14 +126,15 @@ func init() {
}

// setModConfig set module config
func setModConfig(globalConf config.BaseConfig, modConf config.IConfig) {
func setModConfig(globalConf config.BaseConfig, modConf config.IConfig) error {
modConf.SetPid(globalConf.Pid)
modConf.SetUid(globalConf.Uid)
modConf.SetDebug(globalConf.Debug)
modConf.SetHex(globalConf.IsHex)
modConf.SetBTF(globalConf.BtfMode)
modConf.SetPerCpuMapSize(globalConf.PerCpuMapSize)
modConf.SetAddrType(loggerTypeStdout)
return nil
}

// initLogger init logger
Expand All @@ -142,10 +143,6 @@ func initLogger(addr string, modConfig config.IConfig) zerolog.Logger {
var err error
consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
logger = zerolog.New(consoleWriter).With().Timestamp().Logger()
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if modConfig.GetDebug() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
if addr != "" {
var writer io.Writer
var address string
Expand Down Expand Up @@ -176,7 +173,6 @@ func initLogger(addr string, modConfig config.IConfig) zerolog.Logger {
// runModule run module
func runModule(modName string, modConfig config.IConfig) {
var err error
setModConfig(globalConf, modConfig)
var logger = initLogger(globalConf.LoggerAddr, modConfig)
// init eCapture
logger.Info().Str("AppName", fmt.Sprintf("%s(%s)", CliName, CliNameZh)).Send()
Expand Down Expand Up @@ -207,6 +203,10 @@ func runModule(modName string, modConfig config.IConfig) {
// run module
{
// config check
err = setModConfig(globalConf, modConfig)
if err != nil {
logger.Fatal().Err(err).Send()
}
err = modConfig.Check()
if err != nil {
logger.Fatal().Err(err).Msg("config check failed")
Expand Down
4 changes: 2 additions & 2 deletions pkg/event_processor/iworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (ew *eventWorker) Display() error {
b = []byte(hex.Dump(b))
}

//iWorker只负责写入,不应该打印。
e := ew.writeToChan(fmt.Sprintf("UUID:%s, Name:%s, Type:%d, Length:%d\n%s\n", ew.UUID, ew.parser.Name(), ew.parser.ParserType(), len(b), b))
// TODO 应该外部传入一个chan,iWorker只负责写入,不应该打印。
e := ew.writeToChan(fmt.Sprintf("UUID:%s, Name:%s, Type:%d, Length:%d\n:%s\n", ew.UUID, ew.parser.Name(), ew.parser.ParserType(), len(b), b))
//ew.parser.Reset()
// 设定状态、重置包类型
ew.status = ProcessStateInit
Expand Down
5 changes: 1 addition & 4 deletions pkg/util/kernel/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ func HostVersion() (Version, error) {
// ParseVersion parses a string in the format of x.x.x to a Version
func ParseVersion(s string) Version {
var a, b, c byte
_, err := fmt.Sscanf(s, "%d.%d.%d", &a, &b, &c)
if err != nil {
return Version(0)
}
fmt.Sscanf(s, "%d.%d.%d", &a, &b, &c)
return VersionCode(a, b, c)
}

Expand Down
17 changes: 4 additions & 13 deletions user/module/imodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,11 @@ const (
BtfModeSwitch = "If eCapture fails to run, try specifying the BTF mode. use `-b 2` to specify non-CORE mode."
)

// eventProcesser Logger
type epLogger struct {
logger *zerolog.Logger
}

func (e epLogger) Write(p []byte) (n int, err error) {
e.logger.Info().Msg(string(p))
return len(p), nil
}

type Module struct {
opts *ebpf.CollectionOptions
reader []IClose
ctx context.Context
//logger *zerolog.Logger
logger *zerolog.Logger
child IModule
// probe的名字
Expand All @@ -104,8 +95,8 @@ func (m *Module) Init(ctx context.Context, logger *zerolog.Logger, conf config.I
m.logger = logger
m.errChan = make(chan error)
m.isKernelLess5_2 = false //set false default
var epl = epLogger{logger: logger}
m.processor = event_processor.NewEventProcessor(epl, conf.GetHex())

m.processor = event_processor.NewEventProcessor(logger, conf.GetHex())
kv, err := kernel.HostVersion()
if err != nil {
m.logger.Warn().Err(err).Msg("Unable to detect kernel version due to an error:%v.used non-Less5_2 bytecode.")
Expand Down Expand Up @@ -388,7 +379,7 @@ func (m *Module) Dispatcher(e event.IEventStruct) {
if s == "" {
return
}
m.logger.Info().Msg(s)
m.logger.Println(s)
case event.EventTypeEventProcessor:
m.processor.Write(e)
case event.EventTypeModuleData:
Expand Down

0 comments on commit 1564d61

Please sign in to comment.