Skip to content

Commit 2d04ec4

Browse files
committed
Merge branch 'withings-feat/syslog-custom-process-names'
2 parents 0bb276b + a8b1b7a commit 2d04ec4

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this
66
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.25.6] - 2024-11-02
9+
10+
Allow for custom process names when using the syslog writer (PR #182, kudos to
11+
[Julien JPK](https://github.com/julienjpk-withings)).
12+
813
## [0.25.5] - 2024-10-29
914

1015
Fix [issue #181](https://github.com/emabee/flexi_logger/issues/181).

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flexi_logger"
3-
version = "0.29.5"
3+
version = "0.29.6"
44
authors = ["emabee <[email protected]>"]
55
categories = ["development-tools::debugging"]
66
description = """

src/writers/syslog/builder.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct SyslogWriterBuilder {
1313
syslog_connection: SyslogConnection,
1414
syslog_line_header: SyslogLineHeader,
1515
syslog_facility: SyslogFacility,
16+
custom_process_name: Option<String>,
1617
determine_severity: LevelToSyslogSeverity,
1718
max_log_level: log::LevelFilter,
1819
format: FormatFunction,
@@ -28,12 +29,20 @@ impl SyslogWriterBuilder {
2829
syslog_connection: syslog,
2930
syslog_line_header,
3031
syslog_facility,
32+
custom_process_name: None,
3133
determine_severity: default_mapping,
3234
max_log_level: log::LevelFilter::Warn,
3335
format: syslog_default_format,
3436
}
3537
}
3638

39+
/// Specify a custom process name, or unset it to revert back to name inference.
40+
#[must_use]
41+
pub fn custom_process_name(mut self, name: Option<&str>) -> Self {
42+
self.custom_process_name = name.map(Into::into);
43+
self
44+
}
45+
3746
/// Use the given function to map the rust log levels to the syslog severities.
3847
/// By default a trivial mapping is used, which should be good enough in most cases.
3948
#[must_use]
@@ -73,12 +82,16 @@ impl SyslogWriterBuilder {
7382
pub fn build(self) -> IoResult<Box<SyslogWriter>> {
7483
Ok(Box::new(SyslogWriter::new(
7584
std::process::id(),
76-
std::env::args().next().ok_or_else(|| {
77-
IoError::new(
78-
ErrorKind::Other,
79-
"Can't infer app name as no env args are present".to_owned(),
80-
)
81-
})?,
85+
self.custom_process_name
86+
.or(std::env::args().next())
87+
.ok_or_else(|| {
88+
IoError::new(
89+
ErrorKind::Other,
90+
"Can't provide a process name as no env args are present and \
91+
no custom process name is set"
92+
.to_owned(),
93+
)
94+
})?,
8295
self.syslog_line_header,
8396
self.syslog_facility,
8497
self.determine_severity,

0 commit comments

Comments
 (0)