Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file mirage_logs_cli.ml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(*
* Copyright (c) 2014 David Sheets <sheets@alum.mit.edu>
* Copyright (c) 2023 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openCmdlinertypethreshold=[`All|`Srcofstring]*Logs.leveloptionleterrstr=Error(`Msg("Can't parse log threshold: "^str))moduleConv=structletthreshold=letparserstr=letsource=function"*"->`All|s->`Srcsinletlevelsrcs=matchLogs.level_of_stringswith|Oks->Ok(src,s)|Error_ase->einmatchString.split_on_char':'strwith|[src;"-"]->Ok(sourcesrc,None)|[src;lvl]->level(sourcesrc)lvl|_->errstrinletserializeppf=function|`All,l->Format.pp_print_stringppf(Logs.level_to_stringl)|`Srcs,l->Format.fprintfppf"%s:%s"s(Logs.level_to_stringl)inArg.conv(parser,serialize)endletset_levels~defaultl=letsrcs=Logs.Src.list()inletdefault=trysnd@@List.find(function`All,_->true|_->false)lwithNot_found->defaultinLogs.set_leveldefault;List.iter(function|`All,_->()|`Srcsrc,level->(trylets=List.find(funs->Logs.Src.names=src)srcsinLogs.Src.set_levelslevelwithNot_found->Format.printf"WARNING: %s is not a valid log source.\n%!"src))lletenv=Cmd.Env.info"LOGGING_LEVELS"letlevels?(env=env)?docs()=letlogs=Arg.listConv.thresholdinletdoc="Be more or less verbose. $(docv) must be of the form \
$(b,'*:info,foo:debug') means that that the log threshold is set to \
$(b,'info') for every log sources but the $(b,'foo') which is set to \
$(b,'debug'). Use $(b,'quiet') or $(b,'-') to disable a souce. And \
$(b,'*') to consider all sources. For instance $(b, '*-,foo:debug') \
disable all sources but $(b,foo) which is set to $(b, debug).'"inletdoc=Arg.info~env~docv:"LEVEL"~doc?docs["l";"logging-levels"]inArg.(value&optlogs[]doc)letdocs="DISPLAY OPTIONS"letsetup=Term.(const(fundefaultlevels->set_levels~defaultlevels)$Logs_cli.level~docs()$levels~docs())