|
174 | 174 | //! # fn main() {} |
175 | 175 | //! ``` |
176 | 176 | //! |
177 | | -//! ## Custom with log4rs |
| 177 | +//! ## Custom implementations of logging components |
178 | 178 | //! |
179 | 179 | //! You can impl some trait for your struct and use it with log4rs. For example: |
180 | 180 | //! - Impl [log4rs::append::Append](append/trait.Append.html) for your custom appender. |
181 | 181 | //! - Impl [log4rs::encode::Encode](encode/trait.Encode.html) for your custom encoder. |
182 | 182 | //! - Impl [log4rs::filter::Filter](filter/trait.Filter.html) for your custom filter. |
183 | 183 | //! |
184 | | -//! Here is a very sample example to create a custom appender, |
| 184 | +//! Here is a very simple example to create a custom appender, |
185 | 185 | //! for more examples about custom, see [examples/custom.rs](https://github.com/estk/log4rs/tree/main/examples/custom.rs): |
186 | 186 | //! ```no_run |
187 | 187 | //! # fn f() { |
|
194 | 194 | //! // impl your process record logic here |
195 | 195 | //! impl Append for MyAppender { |
196 | 196 | //! fn append(&self, record: &log::Record) -> anyhow::Result<()> { |
197 | | -//! println!("{record:?}"); |
| 197 | +//! println!("appender({}): {record:?}", self.0); |
198 | 198 | //! Ok(()) |
199 | 199 | //! } |
200 | 200 | //! fn flush(&self) {} |
|
219 | 219 | //! # fn main() {} |
220 | 220 | //! ``` |
221 | 221 | //! |
222 | | -//! To config with file, you should implement [log4rs::config::Deserialize](config/trait.Deserialize.html) for your config and **register it in default Deserializers**. |
| 222 | +//! To configure log4rs with a file, you should implement [log4rs::config::Deserialize](config/trait.Deserialize.html) for your config and be sure to register it with [log4rs::config::Deserializers](config/struct.Deserializers.html) as shown in the example below. |
223 | 223 | //! |
224 | | -//! Here is a very simple example to use custom appender with custom config, |
225 | | -//! for more examples about custom config file, see [examples/custom_config.rs](https://github.com/estk/log4rs/tree/main/examples/custom_config.rs): |
| 224 | +//! Here is a very simple example to use a custom appender with custom config. |
| 225 | +//! For more examples about custom config file, see [examples/custom_config.rs](https://github.com/estk/log4rs/tree/main/examples/custom_config.rs): |
226 | 226 | //! ```yaml |
227 | 227 | //! # custom_config.yml |
228 | 228 | //! appenders: |
229 | 229 | //! my_appender: |
230 | 230 | //! kind: custom_appender |
| 231 | +//! appender_data: 42 |
231 | 232 | //! |
232 | 233 | //! root: |
233 | 234 | //! level: INFO |
|
239 | 240 | //! # #[cfg(feature = "config_parsing")] |
240 | 241 | //! # fn f() { |
241 | 242 | //! use log4rs::append::Append; |
242 | | -//! use log4rs::config::{Appender, Deserialize, Deserializers, Root}; |
| 243 | +//! use log4rs::config::{Deserialize, Deserializers}; |
243 | 244 | //! |
244 | 245 | //! #[derive(Debug)] |
245 | 246 | //! struct MyAppender(usize); |
246 | 247 | //! |
247 | 248 | //! // impl your process record logic here |
248 | 249 | //! impl Append for MyAppender { |
249 | 250 | //! fn append(&self, record: &log::Record) -> anyhow::Result<()> { |
250 | | -//! println!("{record:?}"); |
| 251 | +//! println!("appender({}): {record:?}", self.0); |
251 | 252 | //! Ok(()) |
252 | 253 | //! } |
253 | 254 | //! fn flush(&self) {} |
|
272 | 273 | //! config: MyAppenderConfig, |
273 | 274 | //! _: &Deserializers, |
274 | 275 | //! ) -> anyhow::Result<Box<Self::Trait>> { |
275 | | -//! let appender_data = config.appender_data.unwrap_or(10000); |
| 276 | +//! let appender_data = config.appender_data.unwrap_or(0); |
276 | 277 | //! let appender = MyAppender(appender_data); |
277 | 278 | //! Ok(Box::new(appender)) |
278 | 279 | //! } |
|
0 commit comments