MCPcopy Index your code
hub / github.com/Geal/rust-syslog

github.com/Geal/rust-syslog @7.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 7.0.0 ↗ · + Follow
67 symbols 166 edges 8 files 10 documented · 15%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Sending to Syslog in Rust

Build Status Codecov crates.io Version

A small library to send syslog messages to unix sockets, TCP or UDP.

Installation

syslog is available on crates.io and can be included in your Cargo enabled project like this:

[dependencies]
syslog = "^6.0"

documentation

Reference documentation is available here.

Example

extern crate syslog;

use syslog::{Facility, Formatter3164};

fn main() {
  let formatter = Formatter3164 {
    facility: Facility::LOG_USER,
    hostname: None,
    process: "myprogram".into(),
    pid: 42,
  };

  match syslog::unix(formatter) {
    Err(e)         => println!("impossible to connect to syslog: {:?}", e),
    Ok(mut writer) => {
      writer.err("hello world").expect("could not write error message");
    }
  }
}

The struct syslog::Logger implements Log from the log crate, so it can be used as backend for other logging systems:

extern crate syslog;
#[macro_use]
extern crate log;

use syslog::{Facility, Formatter3164, BasicLogger};
use log::{SetLoggerError, LevelFilter};

fn main() {
    let formatter = Formatter3164 {
        facility: Facility::LOG_USER,
        hostname: None,
        process: "myprogram".into(),
        pid: 0,
    };

    let logger = syslog::unix(formatter).expect("could not connect to syslog");
    log::set_boxed_logger(Box::new(BasicLogger::new(logger)))
            .map(|()| log::set_max_level(LevelFilter::Info));

    info!("hello world");
}

There are 3 functions to create loggers:

  • the unix function sends to the local syslog through a Unix socket: syslog::unix(formatter)
  • the tcp function takes an address for a remote TCP syslog server: tcp(formatter, "127.0.0.1:4242")
  • the udp function takes an address for a local port, and the address remote UDP syslog server: udp(formatter, "127.0.0.1:1234", "127.0.0.1:4242")

Extension points exported contracts — how you extend this code

LogFormat (Interface)
(no doc) [2 implementers]
src/format.rs

Core symbols most depended-on inside this repo

format
called by 8
src/format.rs
err
called by 7
src/lib.rs
get_process_info
called by 6
src/lib.rs
debug
called by 5
src/lib.rs
unix
called by 5
src/lib.rs
escape_structure_data_param_value
called by 4
src/format.rs
warning
called by 4
src/lib.rs
info
called by 4
src/lib.rs

Shape

Method 30
Function 28
Class 4
Enum 4
Interface 1

Languages

Rust100%

Modules by API surface

src/lib.rs29 symbols
src/format.rs23 symbols
src/errors.rs6 symbols
src/tests.rs3 symbols
src/facility.rs3 symbols
examples/write.rs1 symbols
examples/rfc5424.rs1 symbols
examples/log.rs1 symbols

For agents

$ claude mcp add rust-syslog \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page