123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110moduleStable=structopenCore.Core_stableopenImport_stablemoduleNaming_scheme=structmoduleV1=structtypet=[`Numbered|`Timestamped|`Dated|`User_definedof(moduleRotation_id.S)]letsexp_of_t:t->Core.Sexp.t=function|`Numbered->Atom"Numbered"|`Timestamped->Atom"Timestamped"|`Dated->Atom"Dated"|`User_defined(_:(moduleRotation_id.S))->Atom"User_defined";;endendmoduleV3=structtypet={messages:intoption[@sexp.option];size:Byte_units.V1.toption[@sexp.option];time:Time_float.Ofday.V1.toption[@sexp.option];keep:[`All|`Newer_thanofTime_float.Span.V3.t|`At_leastofint];naming_scheme:Naming_scheme.V1.t;zone:Time_float_unix.Zone.V1.t}[@@derivingfields~getters~iterators:fold,sexp_of]endendopen!Coreopen!Import(* description of boundaries for file rotation. If all fields are None the file will
never be rotated. Any field set to Some _ will cause rotation to happen when that
boundary is crossed. Multiple boundaries may be set. Log rotation always causes
incrementing rotation conditions (e.g. size) to reset, though this is the
responsibililty of the caller to should_rotate.
*)includeStable.V3letcreate?messages?size?time?zone~keep~naming_scheme()={messages;size;time;zone=Option.valuezone~default:(forceTime_float_unix.Zone.local);keep;naming_scheme};;letfirst_occurrence_aftertime~ofday~zone=letfirst_at_or_aftertime=Time_float.occurrence`First_after_or_attime~ofday~zoneinletcandidate=first_at_or_aftertimein(* we take care not to return the same time we were given *)ifTime_float.equaltimecandidatethenfirst_at_or_after(Time_float.addtimeTime_float.Span.robust_comparison_tolerance)elsecandidate;;letshould_rotatet~last_messages~last_size~last_time~current_time=Fields.fold~init:false~messages:(funaccfield->matchField.getfieldtwith|None->acc|Somerotate_messages->acc||rotate_messages<=last_messages)~size:(funaccfield->matchField.getfieldtwith|None->acc|Somerotate_size->acc||Byte_units.(<=)rotate_sizelast_size)~time:(funaccfield->matchField.getfieldtwith|None->acc|Somerotation_ofday->letrotation_time=first_occurrence_afterlast_time~ofday:rotation_ofday~zone:t.zoneinacc||Time_float.(>=)current_timerotation_time)~zone:(funacc_->acc)~keep:(funacc_->acc)~naming_scheme:(funacc_->acc);;letdefault?(zone=forceTime_float_unix.Zone.local)()={messages=None;size=None;time=SomeTime_float.Ofday.start_of_day;keep=`All;naming_scheme=`Dated;zone};;moduleNaming_scheme=structtypet=[`Numbered|`Timestamped|`Dated|`User_definedof(moduleRotation_id.S)]end