From c1b8911a7d74d76506293446743a99305f4ee61a Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Thu, 9 Jan 2020 07:09:47 -0500 Subject: [PATCH] Log: Fix out-of-order log messages during HTML build [#646] --- 100_core/src/gplx/Gfo_usr_dlg__log_base.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/100_core/src/gplx/Gfo_usr_dlg__log_base.java b/100_core/src/gplx/Gfo_usr_dlg__log_base.java index 981c5e11d..06b8f6576 100644 --- a/100_core/src/gplx/Gfo_usr_dlg__log_base.java +++ b/100_core/src/gplx/Gfo_usr_dlg__log_base.java @@ -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");