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

Is there a way to disable the constant log string in the code? #1713

Open
heheda123123 opened this issue Feb 11, 2025 · 5 comments
Open

Is there a way to disable the constant log string in the code? #1713

heheda123123 opened this issue Feb 11, 2025 · 5 comments

Comments

@heheda123123
Copy link

compile any code using pcapplusplus
there are many constant string in the program
I always use pcpp::Logger::getInstance().suppressLogs(); to disable log print, there is no need to embeded these constant string in the program.
Image

@Dimi1010
Copy link
Collaborator

Dimi1010 commented Feb 11, 2025

The release version currently doesn't have a way to remove them as the log suppression is purely at runtime.

The dev branch has new compile time log level defines that should prune all log messages below the set level during the compilation.

// Compile time log levels.
// Allows for conditional removal of unwanted log calls at compile time.
#define PCPP_LOG_LEVEL_OFF 0
#define PCPP_LOG_LEVEL_ERROR 1
#define PCPP_LOG_LEVEL_INFO 2
#define PCPP_LOG_LEVEL_DEBUG 3
// All log messages built via a PCPP_LOG_* macro below the PCPP_ACTIVE_LOG_LEVEL will be removed at compile time.
// Uses the PCPP_ACTIVE_LOG_LEVEL if it is defined, otherwise defaults to PCAP_LOG_LEVEL_DEBUG
#ifndef PCPP_ACTIVE_LOG_LEVEL
# define PCPP_ACTIVE_LOG_LEVEL PCPP_LOG_LEVEL_DEBUG
#endif // !PCPP_ACTIVE_LOG_LEVEL

You can try that if you want.

@heheda123123
Copy link
Author

heheda123123 commented Feb 12, 2025

Can add an cmake parameter to control the log level?
such as

if(DEFINED LOG_LEVEL)
    add_definitions(-DPCPP_ACTIVE_LOG_LEVEL=${LOG_LEVEL})
endif()

I can use

cmake -DLOG_LEVEL=0

@heheda123123
Copy link
Author

Otherwise, it is not easy to control the compilation log level when introducing pcapplusplus as a third-party library directly.

@tigercosmos
Copy link
Collaborator

@heheda123123 I think it's a good idea. @seladb any comments?

@Dimi1010
Copy link
Collaborator

Dimi1010 commented Feb 12, 2025

I think having it as a cmake option would be better then a general variable, but overall its a good enhancement.

Edit: Forgot options were only booleans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants