Crates.io | winlog2 |
lib.rs | winlog2 |
version | 0.3.1 |
source | src |
created_at | 2023-05-03 15:40:07.816276 |
updated_at | 2023-06-24 17:45:15.504397 |
description | A simple Rust log backend to send messages to the Windows event log. |
homepage | https://github.com/Berrysoft/winlog |
repository | https://github.com/Berrysoft/winlog |
max_upload_size | |
id | 855574 |
size | 28,777 |
This is a fork of winlog
.
A simple Rust log backend to send messages to the Windows event log.
env_logger
filtering, initialized from RUST_LOG environment variable. (optional)The five Rust log levels are mapped to Windows event types as follows:
Rust Log Level | Windows Event Type | Windows Event Id |
---|---|---|
Error | Error | 1 |
Warn | Warning | 2 |
Info | Informational | 3 |
Debug | Informational | 4 |
Trace | Informational | 5 |
Plain winlog:
[dependencies]
log = "*"
winlog = "*"
Or to enable env_logger filtering support:
[dependencies]
log = "*"
winlog = { version = "0.2.5", features = ["env_logger"] }
Register the log source in the Windows registry:
winlog::register("Example Log").unwrap();
This usually requires Administrator
permission so this is usually done during
installation time.
If your MSI installer (or similar) registers your event sources you should not call this.
Without env_logger filtering:
use log::{info, trace};
winlog::init("Example Log").unwrap();
info!("Hello, Event Log");
trace!("This will be logged too");
Use the winlog backend with env_logger filter enabled:
use log::{info, trace};
// # export RUST_LOG="info"
winlog::init("Example Log").unwrap();
info!("Hello, Event Log");
trace!("This will be filtered out");
Deregister the log source:
winlog::deregister("Example Log").unwrap();
This is usually done during program uninstall. If your MSI installer (or similar) deregisters your event sources you should not call this.
windows-sys
instead of winapi
.eventmsgs.rc
and compile it with winres
.end-to-end
test to deregister correctly even if it fails.build.rs
.env_logger
).windrc/windrc
on MinGW..cargo/config
.cargo build --release
Install MinGW (Ubuntu):
sudo apt install mingw-w64
Install Rust:
rustup target install x86_64-pc-windows-gnu
Currently the install from rustup doesn't use the correct linker so you have to add the following to .cargo/config
:
[target.x86_64-pc-windows-gnu]
linker = "/usr/bin/x86_64-w64-mingw32-gcc"
Build:
cargo build --release
Artifacts eventmsgs.rc
and MSG00409.bin
are under source control so users
don't need to have mc.exe
installed for a standard build.
The end-to-end test requires 'Full Control' permissions on the
HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application
registry key.
cargo test
Process:
Create a unique temporary event source name (winlog-test-###########
).
Register our compiled test executable as EventMessageFile
for
the event source in the Windows registry. You can see a new key at
HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\winlog-test-###########
.
Write some log messages to the event source.
Use PowerShell to retrieve the logged messages.
Assert that the retrieved log messages are correct.
Deregister our event source. This removes the winlog-test-###########
registry key.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.