Sample code for 30+ languages & platforms
Rust

Enter/Leave Context in Logging

Demonstrates EnterContext and LeaveContext using the Chilkat Log API.

Chilkat Rust Downloads

Rust
let log = chilkat::Log::new();

// Initialize the log object with an initial context tag:
log.clear("myLog");

// Add some information..
log.log_info("Hello, I'm here...");

// Open a sub-context
log.enter_context("abc");

// New information is now logged within the "abc" context.
log.log_info("This is inside the abc context");
log.log_error("File not found.");

// Perhaps open a new context...
log.enter_context("fileInfo");
log.log_data("filename", "something.txt");
log.log_data("path", "/somedir/xyz");
log.leave_context();

// Close the "abc" context.
log.leave_context();

// Examine the content of the log:
println!("{}", log.last_error_text());

// This is the output:

// myLog:
//   Hello, I'm here...
//   abc:
//     This is inside the abc context
//     File not found.
//     fileInfo:
//       filename: something.txt
//       path: /somedir/xyz
//     --fileInfo
//   --abc
// --myLog