@@ -50,17 +50,17 @@ impl Write for SysLogWriter {
50
50
loop {
51
51
if self . cursor + message. len ( ) > LIMIT {
52
52
// floor_char_boundary is currently unstable
53
- let mut mid = LIMIT ;
54
- while !message. is_char_boundary ( mid ) {
55
- mid -= 1 ;
53
+ let mut truncate_boundary = LIMIT - self . cursor ;
54
+ while !message. is_char_boundary ( truncate_boundary ) {
55
+ truncate_boundary -= 1 ;
56
56
}
57
57
58
- mid = message[ ..mid ]
58
+ truncate_boundary = message[ ..truncate_boundary ]
59
59
. rfind ( |c : char | c. is_ascii_whitespace ( ) )
60
- . unwrap_or ( mid ) ;
60
+ . unwrap_or ( truncate_boundary ) ;
61
61
62
- let left = & message[ ..mid ] ;
63
- let right = & message[ mid ..] ;
62
+ let left = & message[ ..truncate_boundary ] ;
63
+ let right = & message[ truncate_boundary ..] ;
64
64
65
65
self . append ( left. as_bytes ( ) ) ;
66
66
self . append ( DOTDOTDOT_END ) ;
@@ -105,8 +105,10 @@ impl Log for Syslog {
105
105
106
106
#[ cfg( test) ]
107
107
mod tests {
108
- use super :: Syslog ;
109
108
use log:: Log ;
109
+ use std:: fmt:: Write ;
110
+
111
+ use super :: { SysLogWriter , Syslog , FACILITY } ;
110
112
111
113
#[ test]
112
114
fn can_write_to_syslog ( ) {
@@ -119,6 +121,15 @@ mod tests {
119
121
logger. log ( & record) ;
120
122
}
121
123
124
+ #[ test]
125
+ fn can_handle_multiple_writes ( ) {
126
+ let mut writer = SysLogWriter :: new ( libc:: LOG_DEBUG , FACILITY ) ;
127
+
128
+ for i in 1 ..20 {
129
+ let _ = write ! ( writer, "{}" , "Test 123 " . repeat( i) ) ;
130
+ }
131
+ }
132
+
122
133
#[ test]
123
134
fn can_truncate_syslog ( ) {
124
135
let logger = Syslog ;
0 commit comments