diff --git a/cbindgen.toml b/cbindgen.toml index 7a423c51..65133e04 100644 --- a/cbindgen.toml +++ b/cbindgen.toml @@ -40,6 +40,7 @@ exclude = ["MAX_CID_LEN", "MIN_CLIENT_INITIAL_LEN"] "TlsConfigSelectMethods" = "quic_tls_config_select_methods_t" "TlsConfigSelectorContext" = "quic_tls_config_select_context_t" "CongestionControlAlgorithm" = "quic_congestion_control_algorithm" +"LevelFilter" = "quic_log_level" "Http3Connection" = "http3_conn_t" "Http3Config" = "http3_config_t" "Http3Context" = "http3_context_t" diff --git a/include/tquic.h b/include/tquic.h index fb06b7b3..ca184b70 100644 --- a/include/tquic.h +++ b/include/tquic.h @@ -911,16 +911,44 @@ int http3_take_priority_update(struct http3_conn_t *conn, void *argp), void *argp); +/** + * An enum representing the available verbosity level filters of the logger. + */ +typedef enum quic_log_level { + /** + * A level lower than all log levels. + */ + QUIC_LOG_LEVEL_OFF, + /** + * Corresponds to the `Error` log level. + */ + QUIC_LOG_LEVEL_ERROR, + /** + * Corresponds to the `Warn` log level. + */ + QUIC_LOG_LEVEL_WARN, + /** + * Corresponds to the `Info` log level. + */ + QUIC_LOG_LEVEL_INFO, + /** + * Corresponds to the `Debug` log level. + */ + QUIC_LOG_LEVEL_DEBUG, + /** + * Corresponds to the `Trace` log level. + */ + QUIC_LOG_LEVEL_TRACE, +} quic_log_level; + /** * Set logger. * `cb` is a callback function that will be called for each log message. * `line` is a null-terminated log message and `argp` is user-defined data that will be passed to * the callback. - * `level` is the log level filter, valid values are "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE". + * `level` represents the log level. */ -int quic_set_logger(void (*cb)(const uint8_t *line, void *argp), - void *argp, - const char *level); +void quic_set_logger(void (*cb)(const uint8_t *line, void *argp), void *argp, quic_log_level level); typedef enum http3_error { HTTP3_NO_ERROR = 0, diff --git a/src/ffi.rs b/src/ffi.rs index 1e1c5a59..0c17d263 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -1651,30 +1651,17 @@ fn headers_from_ptr<'a>(ptr: *const Header, len: size_t) -> Vec c_int { + level: log::LevelFilter, +) { let argp = atomic::AtomicPtr::new(argp); let logger = Box::new(Logger { cb, argp }); - - if log::set_boxed_logger(logger).is_err() { - return -1; - } - - if level.is_null() { - return -1; - } - - let level = unsafe { ffi::CStr::from_ptr(level).to_str().unwrap_or_default() }; - if let Ok(level_filter) = log::LevelFilter::from_str(level) { - log::set_max_level(level_filter); - } - - 0 + let _ = log::set_boxed_logger(logger); + log::set_max_level(level); } #[repr(C)]