stumpless_sys/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2
3// Copyright 2023 Joel E. Anderson
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! FFI bindings for the Stumpless logging library.
18//!
19//! These wrappings are intended to be the bare minimum to use Stumpless from
20//! a Rust application.
21//!
22//!
23//! # Create Features
24//! Stumpless provides a number of build configuration options that can be used
25//! to enable or disable different functionality. This crate exposes these
26//! options as the following features.
27//!
28//!
29//! ### Target Features
30//!
31//! * **journald** -
32//! Enables targets that can send logs to a systemd journald daemon.
33//! * **network** -
34//! Enables targets that can send logs to a server over a network connection.
35//! * **socket** -
36//! Enables targets that can send logs to Unix sockets.
37//! * **wel** -
38//! Enables targets that can send logs to the Windows Event Log.
39
40#![allow(non_upper_case_globals)]
41#![allow(non_camel_case_types)]
42#![allow(non_snake_case)]
43
44include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
45
46#[cfg(feature = "wel")]
47use std::fs::File;
48#[cfg(feature = "wel")]
49use std::io::Write;
50#[cfg(feature = "wel")]
51use std::path::Path;
52
53/// Writes a compiled resource file (.bin) to the provided file.
54#[cfg(feature = "wel")]
55pub fn write_default_events_bin_file<P: AsRef<Path>>(path: &P) -> std::io::Result<()> {
56 let resource_bytes = include_bytes!(env!("STUMPLESS_DEFAULT_EVENTS_BIN_PATH"));
57 let mut file = File::create(&path)?;
58 file.write_all(resource_bytes)
59 .expect("couldn't write to the file!");
60 Ok(())
61}
62
63/// Writes the resource definition (.rc) file for the default Stumpless events
64/// to the provided file.
65#[cfg(feature = "wel")]
66pub fn write_default_events_resource_file<P: AsRef<Path>>(path: &P) -> std::io::Result<()> {
67 let resource_bytes = include_bytes!(env!("STUMPLESS_DEFAULT_EVENTS_RC_PATH"));
68 let mut file = File::create(&path)?;
69 file.write_all(resource_bytes)
70 .expect("couldn't write to the file!");
71 Ok(())
72}