Fixing code location log level filtering

This commit is contained in:
Alexandre Quesnel
2020-12-23 02:57:18 +00:00
parent bba65b3592
commit a4f3471707
2 changed files with 123 additions and 75 deletions
+63 -52
View File
@@ -36,7 +36,8 @@ enum logLevels
LOG_LEVEL_WARNING, /* for describing recoverable error states in a request or method */
LOG_LEVEL_INFO, /* for low verbosity and high level descriptions of normal operations */
LOG_LEVEL_DEBUG, /* for medium verbosity and low level descriptions of normal operations */
LOG_LEVEL_TRACE /* for high verbosity and low level descriptions of normal operations (eg. method or wire tracing) */
LOG_LEVEL_TRACE, /* for high verbosity and low level descriptions of normal operations (eg. method or wire tracing) */
LOG_LEVEL_NEVER,
};
/* startup return values */
@@ -69,53 +70,53 @@ enum logReturns
#define LOG_PER_LOGGER_LEVEL
/**
* @brief Logging macro for messages that are for an XRDP developper to
* @brief Logging macro for messages that are for an XRDP developer to
* understand and debug XRDP code.
*
* Note: all log levels are relavant to help a developper understand XRDP at
*
* Note: all log levels are relavant to help a developer understand XRDP at
* different levels of granularity.
*
*
* Note: the logging function calls are removed when XRDP_DEBUG is NOT defined.
*
* Note: when the build is configured with --enable-xrdpdebug, then
* the log level can be configured per the source file name or method name
*
* Note: when the build is configured with --enable-xrdpdebug, then
* the log level can be configured per the source file name or method name
* (with the suffix "()") in the [LoggingPerLogger]
* section of the configuration file.
*
*
* For example:
* ```
* ```
* [LoggingPerLogger]
* xrdp.c=DEBUG
* main()=WARNING
* ```
*
*
* @param lvl, the log level
* @param msg, the log text as a printf format c-string
* @param ... the arguments for the printf format c-string
*/
#define LOG_DEVEL(log_level, args...) \
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args);
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args);
/**
* @brief Logging macro for messages that are for a systeam administrator to
* configure and run XRDP on their machine.
*
* Note: the logging function calls contain additional code location info when
*
* Note: the logging function calls contain additional code location info when
* XRDP_DEBUG is defined.
*
*
* @param lvl, the log level
* @param msg, the log text as a printf format c-string
* @param ... the arguments for the printf format c-string
*/
#define LOG(log_level, args...) \
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args);
log_message_with_location(__func__, __FILE__, __LINE__, log_level, args);
/**
* @brief Logging macro for logging the contents of a byte array using a hex
* @brief Logging macro for logging the contents of a byte array using a hex
* dump format.
*
*
* Note: the logging function calls are removed when XRDP_DEBUG is NOT defined.
*
*
* @param log_level, the log level
* @param message, a message prefix for the hex dump. Note: no printf like
* formatting is done to this message.
@@ -123,12 +124,13 @@ enum logReturns
* @param length, the length of the byte array to log
*/
#define LOG_DEVEL_HEXDUMP(log_level, message, buffer, length) \
log_hexdump_with_location(__func__, __FILE__, __LINE__, log_level, message, buffer, length);
log_hexdump_with_location(__func__, __FILE__, __LINE__, log_level, message, buffer, length);
#else
#define LOG_DEVEL(log_level, args...)
#define LOG(log_level, args...) log_message(log_level, args);
#define LOG_DEVEL_HEXDUMP(log_level, message, buffer, length)
#endif
enum log_logger_type
@@ -206,7 +208,7 @@ internal_log_text2level(const char *buf);
* also init its content.
* @return LOG_STARTUP_OK or LOG_ERROR_MALLOC
*/
struct log_config*
struct log_config *
internalInitAndAllocStruct(void);
/**
@@ -218,32 +220,41 @@ internal_log_config_dump(struct log_config *config);
/**
* the log function that all files use to log an event.
* @param lvl, the loglevel
* @param override_destination_level, if true then the destination log level is not used
* @param override_log_level, the loglevel instead of the destination log level if override_destination_level is true
* @param msg, the logtext.
* @param ...
* @param ap, the values for the message format arguments
* @return
*/
enum logReturns
internal_log_message(const enum logLevels lvl, bool_t force_log, const char *msg, va_list args);
internal_log_message(const enum logLevels lvl,
const bool_t override_destination_level,
const enum logLevels override_log_level,
const char *msg,
va_list ap);
/**
* @param log_level, the log level
* @param override_destination_level, if true then the destinatino log level is ignored.
* @param override_destination_level, if true then the destination log level is ignored.
* @param override_log_level, the log level to use instead of the destination log level
* if override_destination_level is true
* @return true if at least one log destination will accept a message logged at the given level.
*/
bool_t
internal_log_is_enabled_for_level(const enum logLevels log_level,
const bool_t override_destination_level);
const bool_t override_destination_level,
const enum logLevels override_log_level);
/**
* @param function_name, the function name (typicaly the __func__ macro)
* @param file_name, the file name (typicaly the __FILE__ macro)
* @param log_level, the log level
* @param[out] log_level_return, the log level to use instead of the destination log level
* @return true if the logger location overrides the destination log levels
*/
bool_t
internal_log_location_overrides_level(const char *function_name,
internal_log_location_overrides_level(const char *function_name,
const char *file_name,
const enum logLevels log_level);
enum logLevels *log_level_return);
/*End of internal functions*/
#endif
@@ -262,8 +273,8 @@ log_start(const char *iniFile, const char *applicationName);
* An alternative log_start where the caller gives the params directly.
* @param config
* @return
*
* @post to avoid memory leaks, the config argument must be free'ed using
*
* @post to avoid memory leaks, the config argument must be free'ed using
* `log_config_free()`
*/
enum logReturns
@@ -283,27 +294,27 @@ log_start_from_param(const struct log_config *src_log_config);
*
* @return pointer to struct log_config.
*/
struct log_config*
struct log_config *
log_config_init_for_console(enum logLevels lvl, const char *override_name);
/**
* Read configuration from a file and store the values in the returned
* Read configuration from a file and store the values in the returned
* log_config.
* @param file
* @param applicationName, the application name used in the log events.
* @param section_prefix, prefix for the logging sections to parse
* @return
*/
struct log_config*
log_config_init_from_config(const char *iniFilename,
const char *applicationName,
struct log_config *
log_config_init_from_config(const char *iniFilename,
const char *applicationName,
const char *section_prefix);
/**
* Free the memory for the log_config struct.
*/
enum logReturns
log_config_free(struct log_config* config);
log_config_free(struct log_config *config);
/**
* Function that terminates all logging
@@ -314,9 +325,9 @@ log_end(void);
/**
* the log function that all files use to log an event.
*
*
* Please prefer to use the LOG and LOG_DEVEL macros instead of this function directly.
*
*
* @param lvl, the loglevel
* @param msg, the logtext.
* @param ...
@@ -326,11 +337,11 @@ enum logReturns
log_message(const enum logLevels lvl, const char *msg, ...) printflike(2, 3);
/**
* the log function that all files use to log an event,
* the log function that all files use to log an event,
* with the function name and file line.
*
* Please prefer to use the LOG and LOG_DEVEL macros instead of this function directly.
*
*
* @param function_name, the function name (typicaly the __func__ macro)
* @param file_name, the file name (typicaly the __FILE__ macro)
* @param line_number, the line number in the file (typicaly the __LINE__ macro)
@@ -340,20 +351,20 @@ log_message(const enum logLevels lvl, const char *msg, ...) printflike(2, 3);
* @return
*/
enum logReturns
log_message_with_location(const char *function_name,
const char *file_name,
const int line_number,
const enum logLevels lvl,
const char *msg,
log_message_with_location(const char *function_name,
const char *file_name,
const int line_number,
const enum logLevels lvl,
const char *msg,
...) printflike(5, 6);
enum logReturns
log_hexdump_with_location(const char *function_name,
const char *file_name,
const int line_number,
const enum logLevels log_level,
const char *msg,
const char *p,
log_hexdump_with_location(const char *function_name,
const char *file_name,
const int line_number,
const enum logLevels log_level,
const char *msg,
const char *p,
int len);
/**