@@ -179,7 +179,7 @@ impl AndroidLogger {
179179
180180static ANDROID_LOGGER : OnceLock < AndroidLogger > = OnceLock :: new ( ) ;
181181
182- const LOGGING_TAG_MAX_LEN : usize = 23 ;
182+ const LOGGING_TAG_MAX_LEN : usize = 128 ;
183183const LOGGING_MSG_MAX_LEN : usize = 4000 ;
184184
185185impl Default for AndroidLogger {
@@ -223,10 +223,20 @@ impl Log for AndroidLogger {
223223 . map ( |s| s. as_bytes ( ) )
224224 . unwrap_or_else ( || module_path. as_bytes ( ) ) ;
225225
226- // truncate the tag here to fit into LOGGING_TAG_MAX_LEN
227- self . fill_tag_bytes ( & mut tag_bytes, tag) ;
228- // use stack array as C string
229- let tag: & CStr = unsafe { CStr :: from_ptr ( mem:: transmute ( tag_bytes. as_ptr ( ) ) ) } ;
226+ // In case we end up allocating, keep the CString alive.
227+ let mut _owned_tag = None ;
228+ let tag: & CStr = if tag. len ( ) < tag_bytes. len ( ) {
229+ // use stack array as C string
230+ self . fill_tag_bytes ( & mut tag_bytes, tag) ;
231+ // SAFETY: fill_tag_bytes always puts a nullbyte in tag_bytes.
232+ unsafe { CStr :: from_ptr ( mem:: transmute ( tag_bytes. as_ptr ( ) ) ) }
233+ } else {
234+ // Tag longer than available stack buffer; allocate.
235+ // SAFETY: if tag contains nullbytes, the Android logger will just ignore any
236+ // characters that follow it.
237+ _owned_tag = Some ( unsafe { CString :: from_vec_unchecked ( tag. to_vec ( ) ) } ) ;
238+ _owned_tag. as_ref ( ) . unwrap ( )
239+ } ;
230240
231241 // message must not exceed LOGGING_MSG_MAX_LEN
232242 // therefore split log message into multiple log calls
0 commit comments