123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160(*********************************************************************************)(* Chamo *)(* *)(* Copyright (C) 2003-2021 Institut National de Recherche en Informatique *)(* et en Automatique. All rights reserved. *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License version *)(* 3 as published by the Free Software Foundation. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public License *)(* along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)(* $Id: cam_log.ml 758 2011-01-13 07:53:27Z zoggy $ *)openStkletlog_src=Logs.Src.createMessages.softwareletgroup=refOcf.groupletadd_to_grouppatho=group:=Ocf.add!grouppatho;oletgroup()=!groupletcolors?(doc=Printf.sprintf"color for %s messages"s)def=add_to_group["colors";s](Ocf.string~docdef)letcolor_app=color"app""white"letcolor_error=color"error""red"letcolor_warning=color"warning""orange"letcolor_info=color"info""green"letcolor_debug=color"debug""yellow"letfont=add_to_group["font"](Ocf.string~doc:"font for messages""fixed 10")letlevel_wrapper=letto_j?with_dock=`String(Logs.level_to_stringk)inletfrom_j?def=function|`Strings->(matchLogs.level_of_stringswith|Okl->l|Error(`Msg_)->failwith(Printf.sprintf"invalid log level %S"s))|json->letmsg=Printf.sprintf"Invalid key %S"(Yojson.Safe.to_stringjson)infailwithmsginOcf.Wrapper.maketo_jfrom_jletlevel=add_to_group["level"](Ocf.option~doc:"log level"~cb:(funlevel->Logs.Src.set_levellog_srclevel)level_wrapper(SomeLogs.Info))letlength=add_to_group["length"](Ocf.int~doc:"number of characters kept in log"100_000)moduleLevMap=Map.Make(structtypet=Logs.levelletcompare=Stdlib.compareend)classbox()=letscr=Scrollbox.scrollbox()in(*let () = Gtksv_utils.register_source_buffer buffer in*)lettextlog=Stk.Textlog.textlog~pack:scr#set_child()in(*
let () = Gtksv_utils.register_source_view source_view in
let () = Gtksv_utils.apply_sourceview_props source_view
(Gtksv_utils.read_sourceview_props ())
in*)object(self)methodbox=scr#coercemethodtextlog=textlogendletlog_window()=letwindow=Stk.App.create_window~show:false~resizable:true~w:500~h:600(Messages.software^" log")inignore(window#connectWindow.Close(fun_->window#hide;true));letvbox=Box.vbox~pack:window#set_child()inletv=newbox()invbox#packv#box;let(wb_close,_)=Button.text_button~text:Messages.close~pack:(vbox#pack~vexpand:0)()inlet_=wb_close#connectWidget.Activated(fun()->window#hide)inobjectmethodwindow=windowmethodtextlog=v#textlogendletthe_log_window=refNoneletget_log_window()=match!the_log_windowwith|Somew->w|None->letw=log_window()inthe_log_window:=Somew;wletsrc=Logs.Src.create"chamo"letappf=Logs.app~srcfleterrf=Logs.err~srcfletwarnf=Logs.warn~srcfletinfof=Logs.info~srcfletdebugf=Logs.debug~srcfletshow_log_window()=letw=get_log_window()inw#window#showlethide_log_window()=letw=get_log_window()inw#window#hide(*
let lwt_reporter app =
let buf_fmt ~like =
let b = Buffer.create 512 in
Fmt.with_buffer ~like b,
fun () -> let m = Buffer.contents b in Buffer.reset b; m
in
let ppf, b_flush = buf_fmt ~like:Fmt.stdout in
let reporter = Logs_fmt.reporter ~app:ppf ~dst:ppf () in
let report src level ~over k msgf =
let k () =
let write () =
let%lwt w = get_log_window app in
w#print level (b_flush())
in
let unblock () = over (); Lwt.return_unit in
Lwt.finalize write unblock |> Lwt.ignore_result;
k ()
in
reporter.Logs.report src level ~over:(fun () -> ()) k msgf;
in
{ Logs.report = report }
*)