123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566(** Low-level mutex-coordinated logs for the Riot engine.
These are super slow, and are intended for usage within the engine alone.
If you're looking for logs for your application, look into
{!module:Riot.Logger} instead.
*)typelevel=Debug|Error|Info|Trace|Warnletlevel_to_int=function|Trace->5|Debug->4|Info->2|Warn->1|Error->0letlevel_to_color_stringt=matchtwith|Error->"\x1b[31m"|Warn->"\x1b[33m"|Debug->"\x1b[36m"|Info->""|Trace->""letlog_level=ref(SomeError)letset_log_levelx=log_level:=xletshould_logx=match!log_levelwith|None->false|Somelog_level->level_to_intx<=level_to_intlog_levelletpp_levelppft=matchtwith|Error->Format.fprintfppf"ERROR "|Warn->Format.fprintfppf"WARN "|Debug->Format.fprintfppf"DEBUG "|Info->Format.fprintfppf"INFO "|Trace->Format.fprintfppf"TRACE "type('a,'b)message_format=(('a,Format.formatter,unit,'b)format4->'a)->'bletlog_lock=Mutex.create()letstdout=Format.make_formatter(output_substringstdout)(fun()->flushstdout)letmsg:typea.level->(a,unit)message_format->unit=funlevelmsgf->msgf@@funfmt->Mutex.locklog_lock;letdomain=(Domain.self():>int)inFormat.kfprintf(fun_->Mutex.unlocklog_lock)stdout("%s%a %a[thread=%d] @["^^fmt^^"@]@.\x1b[0m%!")(level_to_color_stringlevel)(Ptime.pp_rfc3339~frac_s:5~space:true~tz_offset_s:0())(Ptime_clock.now())pp_levelleveldomainlettracemsgf=ifshould_logTracethenmsgTracemsgfletdebugmsgf=ifshould_logDebugthenmsgDebugmsgfletinfomsgf=ifshould_logInfothenmsgInfomsgfletwarnmsgf=ifshould_logWarnthenmsgWarnmsgfleterrormsgf=ifshould_logErrorthenmsgErrormsgf