Coder Social home page Coder Social logo

UDP syslog example about rust-syslog HOT 2 OPEN

geal avatar geal commented on August 23, 2024
UDP syslog example

from rust-syslog.

Comments (2)

xenago avatar xenago commented on August 23, 2024 1

When using 0.0.0.0:0 or :::0 as the local socket address, UDP syslogs seem to be sent successfully.


Initially I stumbled upon this SO post, it seemed like Ipv4Addr::UNSPECIFIED with the automatic port 0 would help:

It's not obvious, but if you bind the socket to (UNSPECIFIED, 0), then when you connect to a remote address the local address is set to the appropriate interface address. (Port 0 means to auto-allocate a port, just like an unbound socket in C.)

Turns out that 0.0.0.0 is equivalent to UNSPECIFIED in std::net::ToSocketAddrs

An IPv4 address representing an unspecified address: 0.0.0.0

So I tried connecting to a localhost and LAN UDP syslog server with that format, it worked both times:

let syslog_udp_config = fern::Dispatch::new().chain(formatter, "0.0.0.0:0", "127.0.0.1:514").expect("Unable to initialize syslog"));

(...)

let syslog_udp_config = fern::Dispatch::new().chain(formatter, "0.0.0.0:0", "192.168.1.234:514").expect("Unable to initialize syslog"));

It also worked with the IPv6 equivalent, :::0 which is probably an even better choice for future compatibility.

from rust-syslog.

khumps avatar khumps commented on August 23, 2024

after more testing, I arrived at:

let mut logger = syslog::udp(formatter, "127.0.0.1:1234", "10.0.0.10:514").expect("failed to initialize syslog");
logger.alert("zpe-fixer logging initializing").expect("failed to send syslog message");

However this panics with:

thread 'main' panicked at 'failed to send syslog message: Error(Format, State { next_error: Some(Os { code: 22, kind: InvalidInput, message: "Invalid argument" }), backtrace: InternalBacktrace })', src/main.rs:48:56

from rust-syslog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.