|
| 1 | +// |
| 2 | +// Copyright (c) 2025 Contributors to the Eclipse Foundation |
| 3 | +// |
| 4 | +// See the NOTICE file(s) distributed with this work for additional |
| 5 | +// information regarding copyright ownership. |
| 6 | +// |
| 7 | +// This program and the accompanying materials are made available under the |
| 8 | +// terms of the Apache License Version 2.0 which is available at |
| 9 | +// <https://www.apache.org/licenses/LICENSE-2.0> |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | + |
| 14 | +//! Module contains functions printing example logs. |
| 15 | +//! Based on `//score/mw/log/rust/score_log_bridge:example`. |
| 16 | +
|
| 17 | +use score_log::{debug, error, fatal, info, trace, warn, Log}; |
| 18 | +use stdout_logger::StdoutLoggerBuilder; |
| 19 | + |
| 20 | +/// Show example logs. |
| 21 | +#[no_mangle] |
| 22 | +extern "C" fn show_logs() { |
| 23 | + // Regular log usage. |
| 24 | + trace!("This is a trace log - hidden"); |
| 25 | + debug!("This is a debug log - hidden"); |
| 26 | + info!("This is an info log"); |
| 27 | + warn!("This is a warn log"); |
| 28 | + error!("This is an error log"); |
| 29 | + fatal!("This is a fatal log"); |
| 30 | + |
| 31 | + // Log with modified context. |
| 32 | + trace!(context: "EX1", "This is a trace log - hidden"); |
| 33 | + debug!(context: "EX1", "This is a debug log - hidden"); |
| 34 | + info!(context: "EX1", "This is an info log"); |
| 35 | + warn!(context: "EX1", "This is a warn log"); |
| 36 | + error!(context: "EX1", "This is an error log"); |
| 37 | + fatal!(context: "EX1", "This is a fatal log"); |
| 38 | + |
| 39 | + // Log with numeric values. |
| 40 | + let x1 = 123.4; |
| 41 | + let x2 = 111; |
| 42 | + let x3 = true; |
| 43 | + let x4 = -0x3Fi8; |
| 44 | + error!( |
| 45 | + "This is an error log with numeric values: {} {} {} {:x}", |
| 46 | + x1, x2, x3, x4, |
| 47 | + ); |
| 48 | + |
| 49 | + // Use logger instance with modified context. |
| 50 | + let logger = StdoutLoggerBuilder::new() |
| 51 | + .context("ALFA") |
| 52 | + .show_module(false) |
| 53 | + .show_file(true) |
| 54 | + .show_line(false) |
| 55 | + .build(); |
| 56 | + |
| 57 | + // Log with provided logger. |
| 58 | + trace!( |
| 59 | + logger: logger, |
| 60 | + "This is a trace log - hidden" |
| 61 | + ); |
| 62 | + debug!(logger: logger, "This is a debug log - hidden"); |
| 63 | + info!(logger: logger, "This is an info log"); |
| 64 | + warn!(logger: logger, "This is a warn log"); |
| 65 | + error!(logger: logger, "This is an error log"); |
| 66 | + fatal!(logger: logger, "This is an fatal log"); |
| 67 | + |
| 68 | + // Log with provided logger and modified context. |
| 69 | + trace!(logger: logger, context: "EX2", "This is a trace log - hidden"); |
| 70 | + debug!(logger: logger, context: "EX2", "This is a debug log - hidden"); |
| 71 | + info!(logger: logger, context: "EX2", "This is an info log"); |
| 72 | + warn!(logger: logger, context: "EX2", "This is a warn log"); |
| 73 | + error!(logger: logger, context: "EX2", "This is an error log"); |
| 74 | + fatal!(logger: logger, context: "EX2", "This is an fatal log"); |
| 75 | +} |
0 commit comments