@@ -185,3 +185,133 @@ impl rs_log::Log for GlibLogger {
185
185
186
186
fn flush ( & self ) { }
187
187
}
188
+
189
+ /// A macro which behaves exactly as `log::error!` except that it sets the
190
+ /// current log target to the contents of a `G_LOG_DOMAIN` constant (and fails
191
+ /// to build if not defined).
192
+ ///
193
+ /// In order to use this macro, `glib` must be built with the `log_macros`
194
+ /// feature enabled and the [`GlibLogger`](struct.GlibLogger.html) must have been
195
+ /// initialized using [`GlibLoggerDomain::CrateTarget`](enum.GlibLoggerDomain.html).
196
+ ///
197
+ /// ```no_run
198
+ /// #[macro_use] extern crate glib;
199
+ ///
200
+ /// static G_LOG_DOMAIN: &str = "my-domain";
201
+ ///
202
+ /// error!("This will be logged under 'my-domain'");
203
+ /// ```
204
+ #[ macro_export]
205
+ #[ cfg( any( feature = "dox" , feature = "log_macros" ) ) ]
206
+ macro_rules! error {
207
+ ( target: $target: expr, $( $arg: tt) +) => (
208
+ log:: log!( target: $target, log:: Level :: Error , $( $arg) +) ;
209
+ ) ;
210
+ ( $( $arg: tt) +) => (
211
+ log:: log!( target: G_LOG_DOMAIN , log:: Level :: Error , $( $arg) +) ;
212
+ )
213
+ }
214
+
215
+ /// A macro which behaves exactly as `log::warn!` except that it sets the
216
+ /// current log target to the contents of a `G_LOG_DOMAIN` constant (and fails
217
+ /// to build if not defined).
218
+ ///
219
+ /// In order to use this macro, `glib` must be built with the `log_macros`
220
+ /// feature enabled and the [`GlibLogger`](struct.GlibLogger.html) must have been
221
+ /// initialized using [`GlibLoggerDomain::CrateTarget`](enum.GlibLoggerDomain.html).
222
+ ///
223
+ /// ```no_run
224
+ /// #[macro_use] extern crate glib;
225
+ ///
226
+ /// static G_LOG_DOMAIN: &str = "my-domain";
227
+ ///
228
+ /// warn!("This will be logged under 'my-domain'");
229
+ /// ```
230
+ #[ macro_export]
231
+ #[ cfg( any( feature = "dox" , feature = "log_macros" ) ) ]
232
+ macro_rules! warn {
233
+ ( target: $target: expr, $( $arg: tt) +) => (
234
+ log:: log!( target: $target, log:: Level :: Warn , $( $arg) +) ;
235
+ ) ;
236
+ ( $( $arg: tt) +) => (
237
+ log:: log!( target: G_LOG_DOMAIN , log:: Level :: Warn , $( $arg) +) ;
238
+ )
239
+ }
240
+
241
+ /// A macro which behaves exactly as `log::info!` except that it sets the
242
+ /// current log target to the contents of a `G_LOG_DOMAIN` constant (and fails
243
+ /// to build if not defined).
244
+ ///
245
+ /// In order to use this macro, `glib` must be built with the `log_macros`
246
+ /// feature enabled and the [`GlibLogger`](struct.GlibLogger.html) must have been
247
+ /// initialized using [`GlibLoggerDomain::CrateTarget`](enum.GlibLoggerDomain.html).
248
+ ///
249
+ /// ```no_run
250
+ /// #[macro_use] extern crate glib;
251
+ ///
252
+ /// static G_LOG_DOMAIN: &str = "my-domain";
253
+ ///
254
+ /// info!("This will be logged under 'my-domain'");
255
+ /// ```
256
+ #[ macro_export]
257
+ #[ cfg( any( feature = "dox" , feature = "log_macros" ) ) ]
258
+ macro_rules! info {
259
+ ( target: $target: expr, $( $arg: tt) +) => (
260
+ log:: log!( target: $target, log:: Level :: Info , $( $arg) +) ;
261
+ ) ;
262
+ ( $( $arg: tt) +) => (
263
+ log:: log!( target: G_LOG_DOMAIN , log:: Level :: Info , $( $arg) +) ;
264
+ )
265
+ }
266
+
267
+ /// A macro which behaves exactly as `log::debug!` except that it sets the
268
+ /// current log target to the contents of a `G_LOG_DOMAIN` constant (and fails
269
+ /// to build if not defined).
270
+ ///
271
+ /// In order to use this macro, `glib` must be built with the `log_macros`
272
+ /// feature enabled and the [`GlibLogger`](struct.GlibLogger.html) must have been
273
+ /// initialized using [`GlibLoggerDomain::CrateTarget`](enum.GlibLoggerDomain.html).
274
+ ///
275
+ /// ```no_run
276
+ /// #[macro_use] extern crate glib;
277
+ ///
278
+ /// static G_LOG_DOMAIN: &str = "my-domain";
279
+ ///
280
+ /// debug!("This will be logged under 'my-domain'");
281
+ /// ```
282
+ #[ macro_export]
283
+ #[ cfg( any( feature = "dox" , feature = "log_macros" ) ) ]
284
+ macro_rules! debug {
285
+ ( target: $target: expr, $( $arg: tt) +) => (
286
+ log:: log!( target: $target, log:: Level :: Debug , $( $arg) +) ;
287
+ ) ;
288
+ ( $( $arg: tt) +) => (
289
+ log:: log!( target: G_LOG_DOMAIN , log:: Level :: Debug , $( $arg) +) ;
290
+ )
291
+ }
292
+
293
+ /// A macro which behaves exactly as `log::trace!` except that it sets the
294
+ /// current log target to the contents of a `G_LOG_DOMAIN` constant (and fails
295
+ /// to build if not defined).
296
+ ///
297
+ /// In order to use this macro, `glib` must be built with the `log_macros`
298
+ /// feature enabled and the [`GlibLogger`](struct.GlibLogger.html) must have been
299
+ /// initialized using [`GlibLoggerDomain::CrateTarget`](enum.GlibLoggerDomain.html).
300
+ ///
301
+ /// ```no_run
302
+ /// #[macro_use] extern crate glib;
303
+ ///
304
+ /// static G_LOG_DOMAIN: &str = "my-domain";
305
+ ///
306
+ /// trace!("This will be logged under 'my-domain'");
307
+ /// ```
308
+ #[ macro_export]
309
+ #[ cfg( any( feature = "dox" , feature = "log_macros" ) ) ]
310
+ macro_rules! trace {
311
+ ( target: $target: expr, $( $arg: tt) +) => (
312
+ log:: log!( target: $target, log:: Level :: Trace , $( $arg) +) ;
313
+ ) ;
314
+ ( $( $arg: tt) +) => (
315
+ log:: log!( target: G_LOG_DOMAIN , log:: Level :: Trace , $( $arg) +) ;
316
+ )
317
+ }
0 commit comments