@ -16,6 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx ;
import gplx.core.strings.* ; import gplx.core.consoles.* ; import gplx.core.brys.fmtrs.* ;
public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
private final Object thread_lock = new Object ( ) ;
private int archive_dirs_max = 8 ;
private Io_url log_dir , err_fil ;
private final Ordered_hash queued_list = Ordered_hash_ . New ( ) ;
@ -85,8 +86,11 @@ public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
}
catch ( Exception e ) { Err_ . Noop ( e ) ; } // java.lang.StringBuilder can throw exceptions in some situations when called on a different thread; ignore errors
} private String_bldr sb = String_bldr_ . new_thread ( ) ; // NOTE: use java.lang.StringBuffer to try to avoid random exceptions when called on a different thread
private String Bld_msg ( String s ) { return sb . Add ( Datetime_now . Get_force ( ) . XtoUtc ( ) . XtoStr_fmt_yyyyMMdd_HHmmss_fff ( ) ) . Add ( " " ) . Add ( s ) . Add_char_nl ( ) . To_str_and_clear ( ) ; }
private String Bld_msg ( String s ) {
return sb . Add ( Datetime_now . Get_force ( ) . XtoUtc ( ) . XtoStr_fmt_yyyyMMdd_HHmmss_fff ( ) ) . Add ( " " ) . Add ( s ) . Add_char_nl ( ) . To_str_and_clear ( ) ;
}
private void Log_msg ( Io_url url , String txt ) {
synchronized ( thread_lock ) { // THREAD:synchronized neded b/c queued_list can be accessible by multiple threads; ISSUE#:646; DATE:2020-01-09
if ( queue_enabled ) {
String url_raw = url = = null ? "mem" : url . Raw ( ) ;
Usr_log_fil fil = ( Usr_log_fil ) queued_list . Get_by ( url_raw ) ;
@ -100,6 +104,7 @@ public class Gfo_usr_dlg__log_base implements Gfo_usr_dlg__log {
if ( enabled )
Io_mgr . Instance . AppendFilStr ( url , txt ) ;
}
}
}
public Object Invk ( GfsCtx ctx , int ikey , String k , GfoMsg m ) {
if ( ctx . Match ( k , "enabled_" ) ) enabled = m . ReadYn ( "v" ) ;