12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ use std:: borrow:: Cow ;
15
16
use std:: io;
16
17
use std:: io:: BufWriter ;
17
18
use std:: io:: Write ;
@@ -50,9 +51,7 @@ pub fn unix(path: impl AsRef<Path>) -> io::Result<SyslogSender> {
50
51
51
52
pub fn unix_well_known ( ) -> io:: Result < SyslogSender > {
52
53
cfg_if:: cfg_if! {
53
- if #[ cfg( target_os = "linux" ) ] {
54
- unix( "/dev/log" )
55
- } else if #[ cfg( target_os = "macos" ) ] {
54
+ if #[ cfg( target_os = "macos" ) ] {
56
55
// NOTE: This may not work on Monterey (12.x) and above,
57
56
// see also https://github.com/python/cpython/issues/91070.
58
57
unix( "/var/run/syslog" )
@@ -112,6 +111,7 @@ impl_syslog_sender_common!(UnixDatagramSender);
112
111
pub struct UnixStreamSender {
113
112
writer : BufWriter < UnixStream > ,
114
113
context : SyslogContext ,
114
+ postfix : Cow < ' static , str > ,
115
115
}
116
116
117
117
impl UnixStreamSender {
@@ -121,9 +121,17 @@ impl UnixStreamSender {
121
121
Ok ( Self {
122
122
writer : BufWriter :: new ( socket) ,
123
123
context : SyslogContext :: default ( ) ,
124
+ postfix : Cow :: Borrowed ( "\r \n " ) ,
124
125
} )
125
126
}
126
127
128
+ /// Set the postfix when formatting Syslog message.
129
+ ///
130
+ /// Default is "\r\n". You can use empty string to set no postfix.
131
+ pub fn set_postfix ( & mut self , postfix : impl Into < Cow < ' static , str > > ) {
132
+ self . postfix = postfix. into ( ) ;
133
+ }
134
+
127
135
/// Set the context when formatting Syslog message.
128
136
pub fn set_context ( & mut self , context : SyslogContext ) {
129
137
self . context = context;
@@ -137,7 +145,7 @@ impl UnixStreamSender {
137
145
/// Send a pre-formatted message.
138
146
pub fn send_formatted ( & mut self , formatted : & [ u8 ] ) -> io:: Result < ( ) > {
139
147
self . writer . write_all ( formatted) ?;
140
- self . writer . write_all ( & [ 0 ; 1 ] ) ?;
148
+ self . writer . write_all ( self . postfix . as_bytes ( ) ) ?;
141
149
Ok ( ( ) )
142
150
}
143
151
0 commit comments