@@ -19,89 +19,65 @@ pub extern "C" fn ddog_logger_set_log_level(
1919 logger_set_log_level ( log_level) . err ( ) . map ( Box :: new)
2020}
2121
22- /// Configures the global logger.
23- ///
24- /// # Arguments
25- /// * `config` - Configuration for the logger including level and output destination
22+ /// Disables logging by configuring a no-op logger.
2623///
2724/// # Errors
2825/// Returns an error if the logger cannot be configured.
2926#[ no_mangle]
30- pub extern "C" fn ddog_logger_configure ( config : LoggerConfig ) -> Option < Box < Error > > {
31- logger_configure ( logger:: LoggerConfig :: from ( config) )
32- . err ( )
33- . map ( Box :: new)
27+ pub extern "C" fn ddog_logger_disable ( ) -> Option < Box < Error > > {
28+ let config = logger:: LoggerConfig {
29+ level : logger:: LogEventLevel :: Error , // Set to the highest level to minimize logging
30+ writer : logger:: WriterConfig :: Noop ,
31+ } ;
32+ logger_configure ( config) . err ( ) . map ( Box :: new)
3433}
3534
36- /// Configuration for the logger .
35+ /// Configuration for stdout output .
3736#[ repr( C ) ]
38- pub struct LoggerConfig < ' a > {
37+ pub struct StdoutConfig {
3938 /// Minimum level for events to be logged
4039 pub level : logger:: LogEventLevel ,
41- /// Output configuration
42- pub writer : WriterConfig < ' a > ,
4340}
4441
45- /// Configuration for log output destination.
46- #[ repr( C ) ]
47- pub struct WriterConfig < ' a > {
48- /// Type of output destination
49- pub kind : WriterKind ,
50- /// File configuration, required when `kind` is [`WriterKind::File`]
51- pub file : Option < & ' a FileConfig < ' a > > ,
42+ /// Configures the logger to write to stdout with the specified configuration.
43+ ///
44+ /// # Arguments
45+ /// * `config` - Configuration for stdout logging including log level
46+ ///
47+ /// # Errors
48+ /// Returns an error if the logger cannot be configured.
49+ #[ no_mangle]
50+ pub extern "C" fn ddog_logger_configure_stdout ( config : StdoutConfig ) -> Option < Box < Error > > {
51+ let logger_config = logger:: LoggerConfig {
52+ level : config. level ,
53+ writer : logger:: WriterConfig :: Stdout ,
54+ } ;
55+ logger_configure ( logger_config) . err ( ) . map ( Box :: new)
5256}
5357
5458/// Configuration for file output.
5559#[ repr( C ) ]
5660pub struct FileConfig < ' a > {
5761 /// Path to the log file
5862 pub path : CharSlice < ' a > ,
63+ /// Minimum level for events to be logged
64+ pub level : logger:: LogEventLevel ,
5965}
6066
61- /// Type of log output destination.
62- #[ repr( C ) ]
63- pub enum WriterKind {
64- /// Discard all output
65- Noop ,
66- /// Write to standard output
67- Stdout ,
68- /// Write to file
69- File ,
70- }
71-
72- impl From < LoggerConfig < ' _ > > for logger:: LoggerConfig {
73- fn from ( config : LoggerConfig ) -> Self {
74- logger:: LoggerConfig {
75- level : config. level ,
76- writer : logger:: WriterConfig :: from ( config. writer ) ,
77- }
78- }
79- }
80-
81- impl From < WriterConfig < ' _ > > for logger:: WriterConfig {
82- fn from ( config : WriterConfig ) -> Self {
83- match config. kind {
84- WriterKind :: Noop => logger:: WriterConfig :: Noop ,
85- WriterKind :: Stdout => logger:: WriterConfig :: Stdout ,
86- WriterKind :: File => {
87- match config. file {
88- Some ( file_config) => {
89- logger:: WriterConfig :: File ( logger:: FileConfig :: from ( FileConfig {
90- path : file_config. path ,
91- } ) )
92- }
93- None => logger:: WriterConfig :: Noop , /* If no file config is provided,
94- * fallback to Noop */
95- }
96- }
97- }
98- }
99- }
100-
101- impl From < FileConfig < ' _ > > for logger:: FileConfig {
102- fn from ( file_config : FileConfig ) -> Self {
103- logger:: FileConfig {
104- path : file_config. path . to_string ( ) ,
105- }
106- }
67+ /// Configures the logger to write to a file with the specified configuration.
68+ ///
69+ /// # Arguments
70+ /// * `config` - Configuration for file logging including path and log level
71+ ///
72+ /// # Errors
73+ /// Returns an error if the logger cannot be configured.
74+ #[ no_mangle]
75+ pub extern "C" fn ddog_logger_configure_file ( config : FileConfig ) -> Option < Box < Error > > {
76+ let logger_config = logger:: LoggerConfig {
77+ level : config. level ,
78+ writer : logger:: WriterConfig :: File ( logger:: FileConfig {
79+ path : config. path . to_string ( ) ,
80+ } ) ,
81+ } ;
82+ logger_configure ( logger_config) . err ( ) . map ( Box :: new)
10783}
0 commit comments