8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
21 module ALib.ALox.Impl;
26 import ALib.Strings.Tokenizer;
28 import ALib.EnumRecords;
29 import ALib.EnumRecords.Bootstrap;
30 import ALib.Variables;
32 import ALib.Camp.Base;
33 import ALib.Bootstrap;
48#if !ALIB_SINGLE_THREADED
49# define UNDEFINED_THREAD threads::UNDEFINED
51# define UNDEFINED_THREAD 0
59# include "ALib.Lang.CIFunctions.H"
64struct DomainSubstitutionRule
67 public:
enum class Type
83 DomainSubstitutionRule(
const NString& s,
const NString& r ) {
84 Search .DbgDisableBufferReplacementWarning();
85 Replacement.DbgDisableBufferReplacementWarning();
90 if ( s.CharAtStart() ==
'*' ) {
93 if ( s.CharAtEnd() ==
'*' ) {
94 type= Type::Substring;
100 if ( s.CharAtEnd() ==
'*' ) {
101 type= Type::StartsWith;
107 Search._( s, startPos, length );
110 if ( ( ( type == Type::Exact
111 || type == Type::StartsWith )
112 &&
Search.CharAtStart() !=
'/'
114 || ( type == Type::EndsWith
115 &&
Search.CharAtEnd() ==
'/'
139 monomem::Snapshot beforeLox;
141 #if !ALIB_SINGLE_THREADED
143 threads::RecursiveLock
Lock;
147 int AcquirementsCount;
154 StdVectorMA<BoxesMA*> logableContainers;
157 StdVectorMA<BoxesMA*> internalLogables;
160 integer internalLogRecursionCounter = 0;
171 Domain* internalDomains;
174 ScopeStore<NString , true > scopeDomains;
177 ScopeStore<PrefixLogable*, true > scopePrefixes;
180 ScopeStore<SSMap<int>* ,
false> scopeLogOnce;
183 ScopeStore<SSMap<Box>* ,
false> scopeLogData;
186 integer maxLoggerNameLength =0;
192 const NString noKeyHashKey =
"$";
196 ListMA<DomainSubstitutionRule> domainSubstitutions;
199 bool oneTimeWarningCircularDS =
false;
202 bool loggerAddedSinceLastDebugState =
false;
208 LoxImpl( MonoAllocator* ma,
const NString& name )
209 : monoAllocator ( *ma )
210 , poolAllocator ( monoAllocator )
211 , AcquirementsCount ( 0 )
212 , logableContainers ( monoAllocator )
213 , internalLogables ( monoAllocator )
214 , scopeInfo ( name , monoAllocator )
215 , scopeDomains ( scopeInfo, monoAllocator )
216 , scopePrefixes ( scopeInfo, monoAllocator )
217 , scopeLogOnce ( scopeInfo, monoAllocator )
218 , scopeLogData ( scopeInfo, monoAllocator )
219 , domainSubstitutions( monoAllocator )
228 for (
int i= domains->CountLoggers() - 1 ; i >= 0 ; --i ) {
229 Logger* logger= domains->GetLogger( i );
230 int ii= internalDomains->GetLoggerNo( logger );
232 internalDomains->RemoveLogger( ii );
233 logger->AcknowledgeLox( this, lang::ContainerOp::Remove );
237 for (
int i= internalDomains->CountLoggers() - 1 ; i >= 0 ; --i ) {
238 Logger* logger= internalDomains->GetLogger( i );
239 logger->AcknowledgeLox( this, lang::ContainerOp::Remove );
247 int CountAcquirements() const noexcept {
return AcquirementsCount; }
255 template<
typename T,
typename... TArgs>
256 T* newPO(TArgs&&... args) {
return poolAllocator().New<T>(std::forward<TArgs>(args)...); }
262 void deletePO(T* o) { poolAllocator().Delete<T>(o); }
267#define ASSERT_ACQUIRED ALIB_ASSERT_ERROR( impl->CountAcquirements() >0,"ALOX","Lox not acquired" )
272LoxImpl* LI::Construct(
const NString& name) {
273 lang::HeapAllocator ha;
276 auto snapShot= selfContainedMA->TakeSnapshot();
277 LoxImpl* result= (*selfContainedMA)().New<LoxImpl>( selfContainedMA, name );
278 result->beforeLox= snapShot;
282void LI::Destruct( LoxImpl* impl ) {
283 auto& ma= impl->monoAllocator;
288const NString& LI::GetName(LoxImpl* impl) {
return impl->scopeInfo.loxName; }
290integer& LI::GetLogCounter(LoxImpl* impl) {
return impl->CntLogCalls; }
292#if !ALIB_SINGLE_THREADED
295 ALIB_DBG( assert::SingleThreaded(); )
300void LI::Acquire(LoxImpl* impl,
const lang::CallerInfo& ci ) {
301 #if !ALIB_SINGLE_THREADED
303 , impl->Lock.AcquireRecursive(ci); )
305 ALIB_DBG( assert::SingleThreaded());
307 ++impl->AcquirementsCount;
308 impl->scopeInfo.Set( ci );
311void LI::Release(LoxImpl* impl) {
312 impl->scopeInfo.PopNestedScope();
313 --impl->AcquirementsCount;
314 #if !ALIB_SINGLE_THREADED
319void LI::init(LoxImpl* impl) {
320 impl->logableContainers.reserve(5);
323 impl->domains = impl->monoAllocator().New<Domain>(impl->monoAllocator, impl->poolAllocator,
"" );
324 impl->internalDomains= impl->monoAllocator().New<Domain>(impl->monoAllocator, impl->poolAllocator,
"$" );
327 const NString internalDomainList[]= {
"LGR",
"DMN",
"PFX",
"THR",
"LGD",
"VAR" };
328 for (
auto& it : internalDomainList )
329 impl->internalDomains->Find( it, 1,
nullptr );
330 impl->maxDomainPathLength= Lox::InternalDomains.Length() + 3;
333 Variable var= variables::CampVariable(ALOX);
336 var.Declare( Variables::DOMAIN_SUBSTITUTION,
337 #if !ALIB_CHARACTERS_WIDE
344 if ( var.IsDefined() ) {
345 for(
int ruleNo= 0 ; ruleNo < var.Size() ; ++ruleNo ) {
347 if( rule.Trim().IsEmpty() )
352 NString256 domainPath ( rule.Substring<NC>( 0, idx ) ); domainPath .Trim();
353 NString256 replacement( rule.Substring<NC>( idx + 2, rule.Length() - idx - 2 ) ); replacement.Trim();
354 SetDomainSubstitutionRule( impl, domainPath, replacement );
357 ALIB_WARNING(
"ALOX",
"Syntax error in variable \"{}\".", var )
362void LI::Reset(LoxImpl* impl) {
364 if( impl == Log::Get()->impl && Log::DebugLogger !=
nullptr ) {
366 Log::RemoveDebugLogger( Log::Get() );
371 SetSourcePathTrimRule( impl,
nullptr, lang::Inclusion::Include,
373 lang::Case::Ignore, NULL_NSTRING, lang::Reach::Global, Priority::NONE );
377 auto snapshot = impl->beforeLox;
379 (*loxMA)().Delete(impl);
380 loxMA->Reset(snapshot);
382 (*loxMA)().New<LoxImpl>(loxMA, name );
384 ALIB_ASSERT_ERROR( impl == dbgNewAddress,
"ALOX",
"Internal error. This must never happen." )
385 impl->beforeLox= snapshot;
388void LI::SetFileNameCacheCapacity( LoxImpl* impl, integer numberOfLists, integer entriesPerList )
389{ impl->scopeInfo.SetFileNameCacheCapacity( numberOfLists, entriesPerList ); }
392MonoAllocator& LI::DbgGetMonoAllocator( LoxImpl* impl ) {
return impl->monoAllocator; }
395void LI::SetSourcePathTrimRule( LoxImpl* impl,
396 const NCString& path,
397 lang::Inclusion includeString ,
399 lang::Case sensitivity ,
400 const NString& trimReplacement,
404 impl->scopeInfo.SetSourcePathTrimRule( path, includeString, trimOffset, sensitivity,
405 trimReplacement, reach, priority );
408void LI::SetDomain( LoxImpl* impl ,
const NString& scopeDomain,
409 Scope scope, threads::Thread* thread ) {
410 if ( !isThreadRelatedScope( impl, scope ) )
412 setDomain( impl, scopeDomain, scope,
false, thread );
418Logger* LI::GetLogger(LoxImpl* impl,
const NString& loggerName ) {
423 if ( (logger= impl->domains ->GetLogger( loggerName ) ) !=
nullptr )
return logger;
424 if ( (logger= impl->internalDomains->GetLogger( loggerName ) ) !=
nullptr )
return logger;
427 BoxesMA& logables= acquireInternalLogables(impl);
428 logables.Add(
"No logger named {!Q} found.", loggerName );
429 logInternal( impl, Verbosity::Warning,
"LGR", logables );
435void writeVerbVarRecursive( Domain& domain,
int loggerNo, CVVerbosities& verbosities,
436 Verbosity parentVerbosity ) {
437 auto verbosity= domain.GetVerbosity( loggerNo );
438 if( parentVerbosity != verbosity || verbosities.ExportAll )
439 verbosities.Add(
String256(domain.FullPath) <<
'=' << verbosity );
442 for ( Domain& subDomain : domain.SubDomains )
443 writeVerbVarRecursive( subDomain, loggerNo, verbosities, verbosity );
448void LI::writeVerbositiesOnLoggerRemoval( LoxImpl* impl, Logger* logger ) {
449DOX_MARKER([DOX_VARIABLES_REPLACEMENTS2])
450Variable var= variables::CampVariable(ALOX);
460 var.Declare( Variables::VERBOSITY, replacements );
462DOX_MARKER( [DOX_VARIABLES_REPLACEMENTS2])
465 auto& cvVerb= var.Get<CVVerbosities>();
470 int loggerNoMainDom= impl->domains ->GetLoggerNo( logger );
471 int loggerNoIntDom= impl->internalDomains->GetLoggerNo( logger );
473 if ( loggerNoMainDom >= 0 ) writeVerbVarRecursive( *impl->domains , loggerNoMainDom, cvVerb,
Verbosity(-1) );
474 if ( loggerNoIntDom >= 0 ) writeVerbVarRecursive( *impl->internalDomains, loggerNoIntDom , cvVerb,
Verbosity(-1) );
484 BoxesMA& logables= acquireInternalLogables(impl);
485 logables.Add(
"Verbosities for logger {!Q} written to variable {!Q}",
486 logger->GetName(), varName );
487 logInternal( impl, Verbosity::Info,
"VAR", logables );
492 BoxesMA& logables= acquireInternalLogables(impl);
493 logables.Add(
" Value:");
494 for(
auto& it : cvVerb )
495 logables.Add(
"\n ", it );
496 logInternal( impl, Verbosity::Verbose,
"VAR", logables );
499void LI::dumpStateOnLoggerRemoval(LoxImpl* impl) {
500 if( !impl->loggerAddedSinceLastDebugState )
502 impl->loggerAddedSinceLastDebugState=
false;
504 Variable variable= variables::CampVariable(ALOX, Variables::DUMP_STATE_ON_EXIT,
511 if( !variable.IsDefined() )
519 tknzr.
Set(variable,
',',
true);
520 while( tknzr.HasNext() ) {
524 if( tok.IndexOf(
'=' ) > 0 ) {
525 if( tok.ConsumePartOf<lang::Case::Ignore, lang::Whitespaces::Trim>(
A_CHAR(
"verbosity"), 1) ) {
526 if( tok.ConsumeChar<lang::Case::Sensitive, lang::Whitespaces::Trim>(
'=' ) )
527 enumrecords::Parse<Verbosity>( tok, verbosity );
530 if( tok.ConsumePartOf<lang::Case::Ignore, lang::Whitespaces::Trim>(
A_CHAR(
"domain"), 1) ) {
531 if( tok.ConsumeChar<lang::Case::Sensitive, lang::Whitespaces::Trim>(
'=' ) )
541 if( !enumrecords::Parse<StateInfo>( tok, stateInfo ) ) {
547 if( stateInfo == StateInfo::NONE )
548 flags= StateInfo::NONE;
553 BoxesMA& logables= acquireInternalLogables(impl);
554 logables.Add(
"Unknown argument {!Q} in variable {} = {!Q}.",
555 tok, variable, variable.GetString() );
556 logInternal( impl, Verbosity::Error,
"VAR", logables);
559 if ( flags != StateInfo::NONE ) {
560 State( impl, domain, verbosity,
A_CHAR(
"Auto dump state on exit requested: "), flags );
564bool LI::RemoveLogger( LoxImpl* impl, Logger* logger ) {
567 int noMainDom= impl->domains ->GetLoggerNo( logger );
568 int noIntDom= impl->internalDomains->GetLoggerNo( logger );
570 if( noMainDom >= 0 || noIntDom >= 0 ) {
571 dumpStateOnLoggerRemoval(impl);
572 writeVerbositiesOnLoggerRemoval( impl, logger );
575 impl->domains->RemoveLogger( noMainDom );
578 impl->internalDomains->RemoveLogger( noIntDom );
580 logger->AcknowledgeLox( impl, lang::ContainerOp::Remove );
586 BoxesMA& logables= acquireInternalLogables(impl);
587 logables.Add(
"Logger {!Q} not found. Nothing removed.", logger );
588 logInternal( impl, Verbosity::Warning,
"LGR", logables );
592Logger* LI::RemoveLogger(LoxImpl* impl,
const NString& loggerName ) {
595 int noMainDom= impl->domains ->GetLoggerNo( loggerName );
596 int noIntDom= impl->internalDomains->GetLoggerNo( loggerName );
598 if( noMainDom >= 0 || noIntDom >= 0 ) {
599 Logger* logger= impl->domains->GetLogger( noMainDom );
600 if( logger ==
nullptr ) logger= impl->internalDomains->GetLogger( noIntDom );
602 dumpStateOnLoggerRemoval(impl);
603 writeVerbositiesOnLoggerRemoval( impl, logger );
606 impl->domains->RemoveLogger( noMainDom );
609 impl->internalDomains->RemoveLogger( noIntDom );
611 logger->AcknowledgeLox( impl, lang::ContainerOp::Remove );
613 BoxesMA& logables= acquireInternalLogables(impl);
614 logables.Add(
"Logger {!Q} removed.", logger );
615 logInternal( impl, Verbosity::Info,
"LGR", logables );
620 BoxesMA& logables= acquireInternalLogables(impl);
621 logables.Add(
"Logger {!Q} not found. Nothing removed.", loggerName );
622 logInternal( impl, Verbosity::Warning,
"LGR", logables );
627void LI::SetVerbosity(LoxImpl* impl, Logger* logger, Verbosity verbosity,
const NString& domain, Priority priority )
631 if ( logger ==
nullptr ) {
632 BoxesMA& logables= acquireInternalLogables(impl);
633 logables.Add(
"Given Logger is \"null\". Verbosity not set." );
634 logInternal( impl, Verbosity::Error,
"LGR", logables );
640 Domain* dom= evaluateResultDomain( impl, domain );
643 bool isNewLogger=
false;
644 int no= dom->GetLoggerNo( logger );
646 no= dom->AddLogger( logger );
650 logInternal( impl, Verbosity::Error,
"LGR", acquireInternalLogables(impl)
651 .
Add(
"Unable to add logger {!Q}. Logger with same name exists.", logger ) );
654 logInternal( impl, Verbosity::Verbose,
"LGR",
655 acquireInternalLogables(impl).
Add(
656 " Request was: SetVerbosity({!Q}, {!Q}, Verbosity::{}, {}). ",
657 logger, dom->FullPath, verbosity, priority ) );
659 Logger* existingLogger= dom->GetLogger( logger->GetName() );
660 logInternal( impl, Verbosity::Verbose,
"LGR", acquireInternalLogables(impl)
661 .
Add(
" Existing Logger: {!Q}.", existingLogger ) );
668 if ( ( dom->GetRoot() == impl->domains ? impl->internalDomains->GetLoggerNo( logger )
669 : impl->domains->GetLoggerNo( logger )
672 logger->AcknowledgeLox( impl, lang::ContainerOp::Insert );
676 if ( impl->maxLoggerNameLength < logger->GetName().Length() )
677 impl->maxLoggerNameLength= logger->GetName().Length();
684 impl->loggerAddedSinceLastDebugState=
true;
689 BoxesMA& logables= acquireInternalLogables(impl);
690 logables.Add(
"Logger {!Q}.", logger );
691 if( domain.StartsWith(Lox::InternalDomains) )
692 logables.Add(
" added for internal log messages.");
694 logables.Add(
" added.");
695 logInternal( impl, Verbosity::Info,
"LGR", logables );
698 Box replacements[2]= { GetName( impl ), logger->GetName() };
699 Variable varVerbosities= variables::CampVariable(ALOX, Variables::VERBOSITY, replacements );
700 if( varVerbosities.IsDefined() ) {
701 getAllVerbosities( impl, varVerbosities, logger, *impl->domains );
702 getAllVerbosities( impl, varVerbosities, logger, *impl->internalDomains );
706 dom->SetVerbosity( no, verbosity, priority );
708 BoxesMA& logables= acquireInternalLogables(impl);
710 logables.Add(
"Logger {!Q}: {!Fill}{!Q'}{!Fill}= Verbosity::{}.",
712 impl->maxLoggerNameLength - logger->GetName().Length(),
714 impl->maxDomainPathLength - dom->FullPath.Length() + 1,
715 boxing::MakePair(verbosity, priority) );
717 Verbosity actVerbosity= dom->GetVerbosity( no );
718 if( actVerbosity != verbosity )
719 logables.Add(
" Lower priority ({} < {}). Remains {}.",
720 priority, dom->GetPriority(no), actVerbosity );
722 logInternal( impl, Verbosity::Info,
"LGR", logables );
725void LI::SetVerbosity(LoxImpl* impl ,
const NString& loggerName,
726 Verbosity verbosity,
const NString& domain , Priority priority ) {
732 Domain* dom= evaluateResultDomain( impl, domain );
734 int no= dom->GetLoggerNo( loggerName );
736 logger= dom->GetLogger( no );
739 Domain* otherTree= dom->GetRoot() == impl->domains ? impl->internalDomains
741 no= otherTree->GetLoggerNo( loggerName );
744 BoxesMA& logables= acquireInternalLogables(impl);
745 logables.Add(
"Logger not found. Request was: SetVerbosity({!Q}, {!Q}, Verbosity::{}, {}).",
746 loggerName, dom->FullPath, verbosity, priority );
747 logInternal( impl, Verbosity::Warning,
"LGR", logables );
751 logger= otherTree->GetLogger( no );
754 SetVerbosity( impl, logger, verbosity, domain, priority );
757void LI::setDomain( LoxImpl* impl,
758 const NString& scopeDomain, Scope scope,
759 bool removeNTRSD, threads::Thread* thread ) {
766 int pathLevel= checkScopeInformation( impl, scope,
"DMN" );
770 #if !ALIB_SINGLE_THREADED
771 ThreadID threadID= thread !=
nullptr ? thread->GetID() : UNDEFINED_THREAD;
773 threads::ThreadID threadID= UNDEFINED_THREAD;
779 impl->scopeDomains.InitAccess( scope, pathLevel, threadID );
781 previousScopeDomain= impl->scopeDomains.Remove( scopeDomain );
783 if ( scopeDomain.IsNotEmpty() ) {
785 previousScopeDomain= impl->scopeDomains.Store(
NString(impl->poolAllocator, trimmable.Trim() ) );
788 previousScopeDomain= impl->scopeDomains.Remove(
nullptr );
792 BoxesMA& logables= acquireInternalLogables(impl);
793 if ( !removeNTRSD && scopeDomain.IsNotEmpty() ) {
794 logables.Add(
"{!Q'} set as default for {}.", scopeDomain, (scope + pathLevel) );
796 if ( previousScopeDomain.IsNull() )
797 logInternal( impl, Verbosity::Info,
"DMN", logables );
799 if ( previousScopeDomain.Equals<NC>( scopeDomain ) ) {
800 logables.Add(
"(Wasalreadyset.)");
801 logInternal( impl,Verbosity::Verbose,
"DMN",logables);
803 logables.Add(
" Replacing previous default {!Q'}.", previousScopeDomain );
804 logInternal( impl, Verbosity::Warning,
"DMN", logables );
808 if ( previousScopeDomain.IsNotNull() ) {
809 logables.Add(
"{!Q'} removed from {}.", previousScopeDomain, (scope + pathLevel) );
810 logInternal( impl, Verbosity::Info,
"DMN", logables );
813 logables.Add(
"{!Q'} not found. Nothing removed for {}.", scopeDomain );
815 logables.Add(
"Empty Scope Domain given, nothing registered for {}.", scopeDomain);
817 logables.Add( scope + pathLevel);
818 logInternal( impl, Verbosity::Warning,
"DMN", logables );
822 if ( previousScopeDomain.IsNotNull() )
823 previousScopeDomain.Free(impl->poolAllocator);
826void LI::RemoveThreadDomain( LoxImpl* impl,
const NString& scopeDomain,
827 Scope scope, threads::Thread* thread ) {
828 if ( !isThreadRelatedScope( impl, scope ) )
832 if ( scopeDomain.IsEmpty() ) {
833 BoxesMA& logables= acquireInternalLogables(impl);
834 logables.Add(
"Illegal parameter. No scope domain path given. Nothing removed for {}.",
836 logInternal( impl, Verbosity::Warning,
"DMN", logables );
843 setDomain( impl, scopeDomain, scope,
true, thread);
846void LI::SetDomainSubstitutionRule(LoxImpl* impl,
const NString& domainPath,
847 const NString& replacement ) {
849 if ( domainPath.IsEmpty() ) {
850 impl->oneTimeWarningCircularDS=
false;
851 impl->domainSubstitutions.Clear();
852 logInternal( impl, Verbosity::Info,
"DMN",
"Domain substitution rules removed.");
858 DomainSubstitutionRule newRule( domainPath, replacement );
859 if ( newRule.Search.IsEmpty() ) {
860 logInternal( impl, Verbosity::Warning,
"DMN",
"Illegal domain substitution rule. Nothing stored." );
865 ListMA<DomainSubstitutionRule>::iterator it;
866 for( it= impl->domainSubstitutions.begin(); it != impl->domainSubstitutions.end() ; ++it ) {
867 if ( (*it).type == newRule.type
868 && (*it).Search.Equals<NC>( newRule.Search ) )
873 if ( replacement.IsEmpty() ) {
874 BoxesMA& logables= acquireInternalLogables(impl);
875 if ( it == impl->domainSubstitutions.end() ) {
876 logables.Add(
"Domain substitution rule {!Q} not found. Nothing to remove.", domainPath );
877 logInternal( impl, Verbosity::Warning,
"DMN", logables );
881 logables.Add(
"Domain substitution rule {!Q} -> {!Q} removed.", domainPath, (*it).Replacement );
882 logInternal( impl, Verbosity::Info,
"DMN", logables );
883 (void) impl->domainSubstitutions.erase( it );
887 BoxesMA& logables= acquireInternalLogables(impl);
888 logables.Add(
"Domain substitution rule {!Q} -> {!Q} set.", domainPath, newRule.Replacement );
892 if ( it != impl->domainSubstitutions.end() ) {
893 msg <<
" Replacing previous -> \"" << (*it).Replacement <<
"\".";
895 (*it).Replacement.Reset( newRule.Replacement );
898 impl->domainSubstitutions.emplace_back( newRule );
901 logInternal( impl, Verbosity::Info,
"DMN", logables );
904void LI::setPrefix(LoxImpl* impl,
const Box& prefix, Scope scope, threads::Thread* thread ) {
908 int pathLevel= checkScopeInformation( impl, scope,
"PFX" );
912 #if !ALIB_SINGLE_THREADED
913 ThreadID threadID= thread !=
nullptr ? thread->GetID() : UNDEFINED_THREAD;
915 threads::ThreadID threadID= UNDEFINED_THREAD;
919 impl->scopePrefixes.InitAccess( scope, pathLevel, threadID );
920 bool isVoidOrEmpty= prefix.IsType<
void>()
922 || ( prefix.IsArray() && !prefix.UnboxLength() );
924 Box* previousLogable= !isVoidOrEmpty ? impl->scopePrefixes.Store( impl->newPO<PrefixLogable>( impl->poolAllocator, prefix ) )
925 : impl->scopePrefixes.Remove(
nullptr );
928 BoxesMA& logables= acquireInternalLogables(impl);
929 logables.Add(
"Object ");
930 Verbosity intMsgVerbosity= Verbosity::Info;
931 if ( !isVoidOrEmpty ) {
932 logables.Add( prefix,
" added as prefix logable for {}.", (scope + pathLevel) );
934 if ( previousLogable !=
nullptr ) {
935 if ( previousLogable->Call<FEquals>( prefix ) ) {
936 logables.Add(
" (Same as before.)");
937 intMsgVerbosity= Verbosity::Verbose;
940 logables.Add(
" Replacing previous {}.", *previousLogable );
943 if ( previousLogable !=
nullptr )
944 logables.Add(
"{!Q} removed from list of prefix logables for {}.", *previousLogable);
946 logables.Add(
"<nullptr> given but no prefix logable to remove for {}.");
947 intMsgVerbosity= Verbosity::Warning;
949 logables.Add( scope + pathLevel );
952 logInternal( impl, intMsgVerbosity,
"PFX", logables );
955 if ( previousLogable !=
nullptr )
956 impl->deletePO(
static_cast<PrefixLogable*
>( previousLogable ));
960void LI::SetPrefix( LoxImpl* impl ,
const Box& prefix,
961 const NString& domain, lang::Inclusion otherPLs ) {
965 Domain* dom= evaluateResultDomain( impl, domain );
967 bool isVoidOrEmpty= prefix.IsType<
void>()
969 || ( prefix.IsArray() && !prefix.UnboxLength() );
971 BoxesMA& logables= acquireInternalLogables(impl);
972 Verbosity intLogVerbosity= Verbosity::Info;
973 PrefixLogable* removedLogable=
nullptr;
975 if ( !isVoidOrEmpty ) {
977 logables.Add(
"Object {} added as prefix logable for ", prefix );
979 dom->PrefixLogables.emplace_back( impl->newPO<PrefixLogable>( impl->poolAllocator, prefix ), otherPLs );
981 auto cntPLs= dom->PrefixLogables.size();
983 removedLogable= dom->PrefixLogables.back().first;
984 dom->PrefixLogables.pop_back();
985 logables.Add(
"Object {} removed from list of prefix logables for",
986 *
static_cast<Box*
>(removedLogable) );
988 logables.Add(
"No prefix logables to remove for" );
989 intLogVerbosity= Verbosity::Warning;
992 logables.Add(
" domain {!Q'}.", dom->FullPath);
993 logInternal( impl, intLogVerbosity,
"PFX", logables );
996 impl->deletePO(removedLogable);
1000#if defined (__GLIBCXX__) || defined(_LIBCPP_VERSION) || defined(__APPLE__) || defined(__ANDROID_NDK__)
1001void LI::SetStartTime(LoxImpl* impl, time_t startTime,
const NString& loggerName )
1004 SetStartTime( impl, converter.ToTicks( DateTime::FromEpochSeconds( startTime ) ), loggerName );
1007#elif defined( _WIN32 )
1008 void LI::SetStartTime(LoxImpl* impl,
const FILETIME& startTime,
const NString& loggerName )
1011 SetStartTime( impl, converter.ToTicks( DateTime::FromFileTime( startTime ) ), loggerName );
1014 #pragma message "Unknown Platform in file: " __FILE__ )
1017void LI::SetStartTime(LoxImpl* impl, Ticks startTime,
const NString& loggerName ) {
1020 bool foundOne=
false;
1021 for(
int loggerNo= 0; loggerNo < impl->domains->CountLoggers(); ++loggerNo ) {
1023 Logger* logger= impl->domains->GetLogger( loggerNo );
1024 if( loggerName.IsNotEmpty() && !loggerName.Equals<NC, lang::Case::Ignore>( logger->GetName()) )
1029 BoxesMA& logables= acquireInternalLogables(impl);
1030 logables.Add(
"Logger {!Q}: Start time set to ", logger->GetName() );
1031 if ( !startTime.IsSet() ) {
1032 startTime= Ticks::Now();
1033 logables.Add(
"'now'" );
1037 if( asTextLogger !=
nullptr )
1041 logables.Add(
"{:yyyy-MM-dd HH:mm:ss}", asDateTime );
1044 logger->TimeOfCreation.SetAs( startTime );
1045 logger->TimeOfLastLog .SetAs( startTime );
1047 logInternal( impl, Verbosity::Info,
"LGR", logables );
1050 if ( loggerName.IsNotEmpty() && !foundOne ) {
1051 BoxesMA& logables= acquireInternalLogables(impl);
1052 logables.Add(
"Logger {!Q}: not found. Start time not set.", loggerName );
1053 logInternal( impl, Verbosity::Error,
"LGR", logables );
1058void LI::MapThreadName(LoxImpl* impl,
const String& threadName, threads::ThreadID
id ) {
1059 #if !ALIB_SINGLE_THREADED
1066 Thread* t= Thread::GetCurrent();
1068 origThreadName= t->GetName();
1071 origThreadName=
nullptr;
1074 impl->scopeInfo.threadDictionary.EmplaceOrAssign(
id, threadName);
1077 BoxesMA& logables= acquireInternalLogables(impl);
1078 logables.Add(
"Mapped thread ID {} to {!Q}.",
id, threadName);
1079 if ( origThreadName.IsNotEmpty() )
1080 logables.Add(
" Original thread name: {!Q}.", origThreadName );
1081 logInternal( impl, Verbosity::Info,
"THR", logables );
1089void LI::once( LoxImpl* impl,
1090 const NString& domain, Verbosity verbosity,
1092 const String& pGroup,
1095 int pathLevel= checkScopeInformation( impl, scope,
"DMN" );
1101 bool groupWasEmtpy= group.IsEmpty();
1102 if ( groupWasEmtpy ) {
1104 if ( scope == Scope::Global ) {
1105 scope= Scope::Filename;
1106 group._(
'#')._( impl->scopeInfo.GetLineNumber() );
1111 group._( impl->noKeyHashKey );
1115 impl->scopeLogOnce.InitAccess( scope, pathLevel, UNDEFINED_THREAD );
1117 SSMap<int>* map= impl->scopeLogOnce.Get();
1118 if( map ==
nullptr ) {
1119 map= impl->newPO<SSMap<int>>(impl->poolAllocator);
1120 impl->scopeLogOnce.Store( map );
1124 auto it= map->Find( group );
1125 if (it == map->end() )
1126 it= map->InsertUnique( std::make_pair(
NString(impl->poolAllocator, group), 0) );
1129 if ( quantity >= 0 ) {
1130 if ( it->second < quantity ) {
1134 GetLogableContainer(impl) .Add( std::forward<const Box&>( logable ) );
1135 Entry( impl, domain, verbosity );
1138 if( it->second == quantity ) {
1139 BoxesMA& logables= acquireInternalLogables(impl);
1140 logables.Add(
"Once() reached limit of {} logs. No further logs for ", quantity );
1142 if ( groupWasEmtpy )
1143 logables.Add( scope == Scope::Global ?
Box(
"this line" )
1144 :
Box(scope + pathLevel) );
1146 logables.Add(
"group {!Q}", group );
1147 if ( scope != Scope::Global )
1148 logables.Add(
" in ", (scope + pathLevel) );
1152 logInternal( impl, Verbosity::Info,
"", logables );
1157 if ( it->second++ % -quantity == 0 ) {
1158 GetLogableContainer(impl) .Add( std::forward<const Box&>( logable ) );
1159 Entry( impl, domain, verbosity );
1162void LI::store( LoxImpl* impl,
const Box& data,
const NString& pKey, Scope scope ) {
1166 bool keyWasEmtpy= key.IsEmpty();
1168 key= impl->noKeyHashKey;
1172 if ( scope > Scope::Path ) {
1173 pathLevel= int( scope - Scope::Path );
1178 impl->scopeLogData.InitAccess( scope, pathLevel, UNDEFINED_THREAD );
1179 SSMap<Box>* map= impl->scopeLogData.Get();
1180 if( map ==
nullptr ) {
1181 map= impl->newPO<SSMap<Box>>(impl->poolAllocator);
1182 impl->scopeLogData.Store( map );
1185 BoxesMA& logables= acquireInternalLogables(impl);
1188 auto it= map->Find( key );
1189 if ( !data.IsType<
void>() ) {
1190 bool replacedPrevious=
false;
1191 if ( it == map->end() )
1192 map->InsertUnique( std::make_pair(
NString(impl->poolAllocator, key), data ) );
1194 replacedPrevious=
true;
1199 logables.Add(
"Stored data " );
1202 logables.Add(
" with key {!Q} ", key );
1203 logables.Add(
"in {}.", (scope + pathLevel) );
1204 if ( replacedPrevious )
1205 logables.Add(
" (Replaced and deleted previous.)" );
1210 if ( it != map->end() ) {
1211 auto keyString= it->first;
1213 if ( map->Size() == 0 ) {
1214 impl->deletePO(map);
1215 impl->scopeLogData.Remove(
nullptr );
1217 keyString.Free(impl->poolAllocator);
1218 logables.Add(
"Deleted map data " );
1221 logables.Add(
"No map data found to delete " );
1224 logables.Add(
" with key {!Q} ", key );
1225 logables.Add(
"in {}.", (scope + pathLevel) );
1228 LI::logInternal( impl, Verbosity::Info,
"LGD", logables );
1232Box LI::retrieve( LoxImpl* impl,
const NString& pKey, Scope scope ) {
1236 bool keyWasEmtpy= key.IsEmpty();
1238 key= impl->noKeyHashKey;
1241 if ( scope > Scope::Path ) {
1242 pathLevel= int( scope - Scope::Path );
1247 impl->scopeLogData.InitAccess( scope, pathLevel, UNDEFINED_THREAD );
1249 SSMap<Box>* map= impl->scopeLogData.Get();
1250 if( map !=
nullptr ) {
1251 auto it= map->Find( key );
1252 if ( it != map->end() )
1253 returnValue= it->second;
1256 if ( returnValue.IsType<
void>() )
1257 store( impl,
Box(), pKey, scope + pathLevel );
1260 BoxesMA& logables= acquireInternalLogables(impl);
1261 logables.Add(
"Data " );
1264 logables.Add(
" with key {!Q} ", key );
1265 logables.Add(
"in ", (scope + pathLevel), ( !returnValue.IsType<
void>() ?
" received."
1266 :
" not found." ) );
1268 logInternal( impl, Verbosity::Info,
"LGD", logables );
1273void LI::State( LoxImpl* impl,
1274 const NString& domain,
1275 Verbosity verbosity,
1276 const String& headLine,
1282 if ( headLine.IsNotEmpty() )
1283 buf._<NC>( headLine ).NewLine();
1285 GetState( impl, buf, flags );
1287 GetLogableContainer(impl) .Add( buf );
1288 Entry( impl, domain, verbosity );
1291BoxesMA& LI::GetLogableContainer(LoxImpl* impl) {
1292 auto cntAcquirements= impl->CountAcquirements();
1295 while(
int(impl->logableContainers.size()) < cntAcquirements )
1296 impl->logableContainers.emplace_back( impl->monoAllocator().New<BoxesMA>(impl->monoAllocator) );
1297 BoxesMA& logables= *impl->logableContainers[
size_t(cntAcquirements - 1)];
1302void LI::Entry(LoxImpl* impl, const NString& domain, Verbosity verbosity ) {
1307 if( impl == Log::Get()->impl
1308 && impl->domains->CountLoggers() == 0
1309 && Log::DebugLogger ==
nullptr )
1310 Log::AddDebugLogger( Log::Get() );
1315 ++impl->CntLogCalls;
1317 if ( impl->domains->CountLoggers() == 0 )
1321 evaluateResultDomain( impl, domain ),
1323 *impl->logableContainers[
size_t(impl->CountAcquirements() - 1)],
1324 lang::Inclusion::Include );
1327int LI::IsActive(LoxImpl* impl, Verbosity verbosity,
const NString& domain, NAString* resultDomain){
1332 if( impl == Log::Get()->impl
1333 && impl->domains->CountLoggers() == 0
1334 && Log::DebugLogger ==
nullptr )
1335 Log::AddDebugLogger( Log::Get() );
1340 if ( impl->domains->CountLoggers() == 0 )
1343 Domain* dom= evaluateResultDomain( impl, domain );
1344 if ( resultDomain !=
nullptr )
1345 resultDomain->_( dom->FullPath );
1348 for (
int i= 0; i < dom->CountLoggers() ; ++i )
1349 if( dom->IsActive( i, verbosity ) )
1354void LI::IncreaseLogCounter( LoxImpl* impl) { ++impl->CntLogCalls; }
1356void LI::entryDetectDomainImpl(LoxImpl* impl, Verbosity verbosity ) {
1357 BoxesMA& logables= *impl->logableContainers[size_t(impl->CountAcquirements() - 1)];
1358 if ( logables.Size() > 1 && logables[0].IsArrayOf<nchar>() ) {
1363 if( firstArg.StartsWith( Lox::InternalDomains ) )
1364 idx+= Lox::InternalDomains.Length();
1367 bool illegalCharacterFound=
false;
1368 for( ; idx< firstArg.Length() ; ++idx ) {
1369 char c= firstArg[idx];
1370 if (! ( isdigit( c )
1371 || ( c >=
'A' && c <=
'Z' )
1378 illegalCharacterFound=
true;
1382 if ( illegalCharacterFound ) {
1383 Entry( impl,
nullptr, verbosity );
1387 logables.erase( logables.begin() );
1388 Entry( impl, firstArg, verbosity );
1392 Entry( impl,
nullptr, verbosity );
1399Domain* LI::evaluateResultDomain(LoxImpl* impl,
const NString& domainPath ) {
1403 if ( domainPath.StartsWith( Lox::InternalDomains ) ) {
1405 resDomain._( domainPath, Lox::InternalDomains.
Length() );
1406 return findDomain( impl, *impl->internalDomains, resDomain );
1410 NString64 localPath; localPath.DbgDisableBufferReplacementWarning();
1411 impl->scopeDomains.InitWalk( Scope::ThreadInner,
1413 domainPath.IsNotEmpty() ? localPath._(domainPath)
1417 while( (nextDefault= impl->scopeDomains.Walk() ).IsNotNull() ) {
1420 if ( resDomain.IsNotEmpty() )
1421 resDomain.InsertAt(
"/", 0);
1422 resDomain.InsertAt( nextDefault, 0 );
1425 if ( resDomain.CharAtStart() == Domain::Separator() )
1428 return findDomain( impl, *impl->domains, resDomain );
1431void LI::getVerbosityFromConfig(LoxImpl* impl, Variable& v, Logger* logger, Domain& dom ) {
1433 int loggerNo= dom.GetLoggerNo( logger ) ;
1437 auto& cvVerb = v.Get<alib::lox::CVVerbosities>();
1439 for (
auto it : cvVerb) {
1443 Substring domainStrParser= verbosityTknzr.Next();
1444 if ( domainStrParser.ConsumeString<lang::Case::Ignore>(
A_CHAR(
"INTERNAL_DOMAINS")) ) {
1445 while ( domainStrParser.ConsumeChar(
'/') )
1447 domainStrBuf << Lox::InternalDomains << domainStrParser;
1450 domainStrBuf._( domainStrParser );
1454 Substring verbosityStr= verbosityTknzr.Next();
1455 if ( verbosityStr.IsEmpty() )
1459 if ( domainStr.ConsumeChar (
'*' ) ) searchMode+= 2;
1460 if ( domainStr.ConsumeCharFromEnd(
'*' ) ) searchMode+= 1;
1461 if( ( searchMode == 0 && dom.FullPath.Equals <NC ,lang::Case::Ignore>( domainStr ) )
1462 || ( searchMode == 1 && dom.FullPath.StartsWith<CHK,lang::Case::Ignore>( domainStr ) )
1463 || ( searchMode == 2 && dom.FullPath.EndsWith <CHK,lang::Case::Ignore>( domainStr ) )
1464 || ( searchMode == 3 && dom.FullPath.IndexOf <CHK,lang::Case::Ignore>( domainStr ) >=0 )
1468 enumrecords::Parse<Verbosity>(verbosityStr, verbosity );
1469 dom.SetVerbosity( loggerNo, verbosity, v.GetPriority() );
1473 msg._<NC>(
"Logger \"" )._<NC>( logger->GetName() ) ._<NC>(
"\":" )._(
NTab(11 + impl->maxLoggerNameLength))
1474 ._<NC>(
'\'' )._<NC>( dom.FullPath )
1475 ._(
'\'' ).InsertChars(
' ', impl->maxDomainPathLength - dom.FullPath.Length() + 1 )
1476 ._(
"= Verbosity::" )
1477 ._( boxing::MakePair(verbosity, dom.GetPriority( loggerNo )) ).TrimEnd()
1480 logInternal( impl, Verbosity::Info,
"LGR", msg );
1483void LI::getDomainPrefixFromConfig(LoxImpl* impl, Domain& dom ) {
1484 Variable variable= variables::CampVariable(ALOX);
1486 const Declaration* decl= Declaration::Get( Variables::PREFIXES);
1487 decl= ALOX.GetConfig()->StoreDeclaration( decl,
1488 #if !ALIB_CHARACTERS_WIDE
1494 if( !variable.Try(decl) )
1499 prefixTokOuter.
Set(variable,
';',
true);
1500 while(prefixTokOuter.HasNext()) {
1501 Tokenizer prefixTok( prefixTokOuter.Next(),
'=' );
1504 Substring domainStrParser= prefixTok.Next();
1505 if ( domainStrParser.ConsumeString<lang::Case::Ignore>(
A_CHAR(
"INTERNAL_DOMAINS")) ) {
1506 while ( domainStrParser.ConsumeChar(
'/') )
1508 domainStrBuf << Lox::InternalDomains << domainStrParser;
1511 domainStrBuf._( domainStrParser );
1515 Tokenizer prefixTokInner( prefixTok.Next(),
',' );
1516 Substring prefixStr= prefixTokInner.Next();
1517 if ( prefixStr.IsEmpty() )
1519 if ( prefixStr.ConsumeChar(
'\"' ) )
1522 lang::Inclusion otherPLs= lang::Inclusion::Include;
1523 prefixTokInner.Next();
1524 if ( prefixTokInner.Actual.IsNotEmpty() )
1525 enumrecords::ParseEnumOrTypeBool( prefixTokInner.Actual, otherPLs, lang::Inclusion::Exclude, lang::Inclusion::Include );
1528 if ( domainStr.ConsumeChar (
'*' ) ) searchMode+= 2;
1529 if ( domainStr.ConsumeCharFromEnd(
'*' ) ) searchMode+= 1;
1530 if( ( searchMode == 0 && dom.FullPath.Equals <NC ,lang::Case::Ignore>( domainStr ) )
1531 || ( searchMode == 1 && dom.FullPath.StartsWith<CHK,lang::Case::Ignore>( domainStr ) )
1532 || ( searchMode == 2 && dom.FullPath.EndsWith <CHK,lang::Case::Ignore>( domainStr ) )
1533 || ( searchMode == 3 && dom.FullPath.IndexOf <CHK,lang::Case::Ignore>( domainStr ) >=0 )
1536 dom.PrefixLogables.emplace_back( impl->newPO<PrefixLogable>( impl->poolAllocator, prefixStr ), otherPLs );
1539 NString128 msg; msg._<NC>(
"String \"" )._<NC>( prefixStr )._<NC>(
"\" added as prefix logable for domain \'" )
1540 ._<NC>( dom.FullPath )
1541 ._<NC>(
"\'. (Retrieved from configuration variable \'" )._<NC>(variable)._(
"\'.)" );
1543 logInternal( impl, Verbosity::Info,
"PFX", msg );
1546void LI::getAllVerbosities(LoxImpl* impl, Variable& varVerbosities, Logger* logger, Domain& dom) {
1548 getVerbosityFromConfig( impl, varVerbosities, logger, dom );
1551 for ( Domain& subDomain : dom.SubDomains )
1552 getAllVerbosities( impl, varVerbosities, logger, subDomain );
1556Domain* LI::findDomain(LoxImpl* impl, Domain& rootDomain, NString domainPath ) {
1557 int maxSubstitutions= 10;
1561 Domain* dom=
nullptr;
1564 dom= rootDomain.Find( domainPath, 1, &wasCreated );
1567 if ( impl->maxDomainPathLength < dom->FullPath.Length() )
1568 impl->maxDomainPathLength= dom->FullPath.Length();
1571 BoxesMA& logables= acquireInternalLogables(impl);
1572 logables.Add(
"{!Q} registered.", dom->FullPath );
1573 logInternal( impl, Verbosity::Info,
"DMN", logables );
1577 if ( !dom->ConfigurationAlreadyRead )
1578 { dom->ConfigurationAlreadyRead=
true;
1580 Box replacements[2];
1581 for (
int i= 0; i < dom->CountLoggers(); ++i ) {
1582 Logger* logger= dom->GetLogger(i);
1583 replacements[0]= GetName( impl );
1584 replacements[1]= logger->GetName();
1585 Variable varVerbosities= variables::CampVariable(ALOX, Variables::VERBOSITY, replacements );
1586 if ( varVerbosities.IsDefined() )
1587 getVerbosityFromConfig( impl, varVerbosities, logger, *dom );
1590 getDomainPrefixFromConfig( impl, *dom );
1594 if ( dom->CountLoggers() == 0 )
1595 logInternal( impl, Verbosity::Verbose,
"DMN",
" No loggers set, yet." );
1597 for (
int i= 0; i < dom->CountLoggers(); ++i ) {
1598 NString256 msg; msg._(
" \"")._( dom->GetLogger(i)->GetName() )._(
"\": ");
1599 msg.InsertChars(
' ', impl->maxLoggerNameLength + 6 - msg.Length() );
1600 msg._( dom->FullPath )._(
" = " )
1601 ._(boxing::MakePair(dom->GetVerbosity(i), dom->GetPriority(i)));
1602 logInternal( impl, Verbosity::Verbose,
"DMN", msg );
1609 if( !impl->domainSubstitutions.empty() ) {
1612 if ( domFullPath.CharAtStart<NC>() ==
'$' )
1615 while( maxSubstitutions-- > 0 ) {
1617 bool substituted=
false;
1618 for(
auto& rule : impl->domainSubstitutions ) {
1619 switch( rule.type ) {
1620 case DomainSubstitutionRule::Type::StartsWith:
1621 if( substPath.IsEmpty() ) {
1622 if ( domFullPath.StartsWith( rule.Search ) ) {
1623 substPath._( rule.Replacement )._( domFullPath, rule.Search.Length() );
1628 if ( substPath.StartsWith( rule.Search ) ) {
1629 substPath.ReplaceSubstring<NC>( rule.Replacement, 0, rule.Search.Length() );
1635 case DomainSubstitutionRule::Type::EndsWith:
1636 if( substPath.IsEmpty() ) {
1637 if ( domFullPath.EndsWith( rule.Search ) ) {
1638 substPath._( domFullPath, 0, domFullPath.Length() - rule.Search.Length() )._( rule.Replacement );
1643 if ( substPath.EndsWith( rule.Search ) ) {
1644 substPath.DeleteEnd( rule.Search.Length() )._( rule.Replacement );
1651 case DomainSubstitutionRule::Type::Substring:
1653 if( substPath.IsEmpty() ) {
1654 integer idx= domFullPath.IndexOf( rule.Search );
1656 substPath._( domFullPath, 0, idx )._( rule.Replacement)._( domFullPath, idx + rule.Search.Length() );
1661 integer idx= substPath.IndexOf( rule.Search, 0 );
1663 substPath.ReplaceSubstring<NC>( rule.Replacement, idx, rule.Search.Length() );
1670 case DomainSubstitutionRule::Type::Exact:
1672 if( substPath.IsEmpty() ) {
1673 if ( domFullPath.Equals<NC>( rule.Search ) ) {
1674 substPath._( rule.Replacement);
1678 if ( domFullPath.CharAtStart<NC>() ==
'$' ) {
1679 substPath._( rule.Replacement);
1684 if ( substPath.Equals<NC>( rule.Search) ) {
1685 substPath.Reset( rule.Replacement );
1691 default:
ALIB_ERROR(
"ALOX",
"Illegal switch state." ) break;
1702 if ( maxSubstitutions <= 0 && !impl->oneTimeWarningCircularDS ) {
1703 impl->oneTimeWarningCircularDS=
true;
1704 logInternal( impl, Verbosity::Error,
"DMN",
1705 "The Limit of 10 domain substitutions was reached. Circular substitution assumed!"
1706 " (This error is only reported once!)" );
1710 if( substPath.Length() > 0 ) {
1711 domainPath= substPath;
1718int LI::checkScopeInformation(LoxImpl* impl, Scope& scope,
const NString& internalDomain ) {
1720 if ( scope > Scope::Path ) {
1721 pathLevel= int( scope - Scope::Path );
1725 if ( ( scope == Scope::Path && impl->scopeInfo.GetFullPath().IsEmpty() )
1726 || ( scope == Scope::Filename && impl->scopeInfo.GetFileName().IsEmpty() )
1727 || ( scope == Scope::Method && impl->scopeInfo.GetMethod() .IsEmpty() ) )
1729 BoxesMA& logables= acquireInternalLogables(impl);
1730 logables.Add(
"Missing scope information. Cant use {}.", (scope + pathLevel) );
1731 logInternal( impl, Verbosity::Error, internalDomain, logables );
1737bool LI::isThreadRelatedScope(LoxImpl* impl, Scope scope ) {
1739 if ( scope == Scope::ThreadOuter
1740 || scope == Scope::ThreadInner )
1743 BoxesMA& logables= acquireInternalLogables(impl);
1744 logables.Add(
"Illegal parameter, only Scope::ThreadOuter and Scope::ThreadInner allowed."
1745 " Given: {}.", scope );
1746 logInternal( impl, Verbosity::Error,
"DMN", logables );
1750 impl->scopeInfo.GetLineNumber(),
1751 impl->scopeInfo.GetMethod(),
1752 #if !ALIB_SINGLE_THREADED
1753 impl->scopeInfo.GetThreadNativeID(),
1754 #elif ALIB_EXT_LIB_THREADS_AVAILABLE
1757 impl->scopeInfo.GetTypeInfo()
1759 0,
"Illegal scope type \"{}\" given. Only Scope::ThreadOuter and "
1760 "Scope::ThreadInner allowed.", scope );
1766void LI::log( LoxImpl* impl , Domain* dom,
1767 Verbosity verbosity, BoxesMA& logables, lang::Inclusion includePrefixes ) {
1769 bool logablesCollected=
false;
1770 PrefixLogable marker(impl->poolAllocator,
nullptr);
1771 for (
int i= 0; i < dom->CountLoggers() ; ++i )
1772 if( dom->IsActive( i, verbosity ) ) {
1774 if ( !logablesCollected ) {
1775 logablesCollected=
true;
1776 impl->scopePrefixes.InitWalk( Scope::ThreadInner, &marker );
1778 int userLogablesSize= int( logables.Size() );
1779 int threadInnersSize= -1;
1781 while( (next= impl->scopePrefixes.Walk() ) !=
nullptr ) {
1782 if( next != &marker ) {
1784 if ( includePrefixes == lang::Inclusion::Include ) {
1787 if ( next->IsType<BoxesMA*>() ) {
1788 auto* boxes= next->Unbox<
BoxesMA*>();
1789 for (
auto pfxI= boxes->Size() - 1 ; pfxI >= 0 ; --pfxI )
1790 logables.emplace( logables.begin() + ( threadInnersSize < 0 ? userLogablesSize : 0 ),
1791 (*boxes)[
size_t(pfxI)] );
1793 else if ( next->IsType<Boxes*>() ) {
1794 auto* boxes= next->Unbox<
Boxes*>();
1795 for (
auto pfxI= boxes->Size() - 1 ; pfxI >= 0 ; --pfxI )
1796 logables.emplace( logables.begin() + ( threadInnersSize < 0 ? userLogablesSize : 0 ),
1797 (*boxes)[
size_t(pfxI)] );
1799 else if ( next->IsType<BoxesPA*>() ) {
1800 auto* boxes= next->Unbox<
BoxesPA*>();
1801 for (
auto pfxI= boxes->Size() - 1 ; pfxI >= 0 ; --pfxI )
1802 logables.emplace( logables.begin() + ( threadInnersSize < 0 ? userLogablesSize : 0 ),
1803 (*boxes)[
size_t(pfxI)] );
1806 logables.emplace( logables.begin() + ( threadInnersSize < 0 ? userLogablesSize : 0 ), *next );
1811 bool excludeOthers=
false;
1812 threadInnersSize= int( logables.Size() ) - userLogablesSize;
1813 Domain* pflDom= dom;
1814 while ( pflDom !=
nullptr ) {
1815 for(
auto it= pflDom->PrefixLogables.rbegin() ; it != pflDom->PrefixLogables.rend() ; ++it ) {
1817 PrefixLogable& prefix= *it->first;
1818 if ( prefix.IsType<Boxes*>() ) {
1819 auto* boxes= prefix.Unbox<
Boxes*>();
1820 for (
auto pfxI= boxes->Size() - 1 ; pfxI >= 0 ; --pfxI )
1821 logables.emplace( logables.begin(),
1822 (*boxes)[
size_t(pfxI)] );
1824 else if ( prefix.IsType<BoxesMA*>() ) {
1825 auto* boxes= prefix.Unbox<
BoxesMA*>();
1826 for (
auto pfxI= boxes->Size() - 1 ; pfxI >= 0 ; --pfxI )
1827 logables.emplace( logables.begin(),
1828 (*boxes)[
size_t(pfxI)] );
1830 else if ( prefix.IsType<BoxesPA*>() ) {
1831 auto* boxes= prefix.Unbox<
BoxesPA*>();
1832 for (
auto pfxI= boxes->Size() - 1 ; pfxI >= 0 ; --pfxI )
1833 logables.emplace( logables.begin(),
1834 (*boxes)[
size_t(pfxI)] );
1837 logables.emplace( logables.begin(), prefix );
1840 if ( it->second == lang::Inclusion::Exclude ) {
1841 excludeOthers=
true;
1845 pflDom= excludeOthers ? nullptr : pflDom->Parent;
1849 if (excludeOthers) {
1850 for (
int ii= 0; ii < threadInnersSize ; ++ii )
1851 logables.pop_back();
1856 Logger* logger= dom->GetLogger(i);
1859 logger->Log( *dom, verbosity, logables, impl->scopeInfo );
1860 logger->TimeOfLastLog= Ticks::Now();
1863BoxesMA& LI::acquireInternalLogables(LoxImpl* impl) {
1864 if(
integer(impl->internalLogables.size()) == impl->internalLogRecursionCounter ) {
1865 BoxesMA* newLogables= impl->monoAllocator().New<
BoxesMA>(impl->monoAllocator);
1866 impl->internalLogables.emplace_back( newLogables );
1869 return *impl->internalLogables[size_t(impl->internalLogRecursionCounter++)];
1872void LI::logInternal(LoxImpl* impl, Verbosity verbosity,
const NString& subDomain, BoxesMA& msg ) {
1874 log( impl, findDomain( impl, *impl->internalDomains, subDomain ), verbosity, msg, lang::Inclusion::Exclude );
1876 impl->internalLogables[
size_t(--impl->internalLogRecursionCounter)]->clear();
1879void LI::logInternal( LoxImpl* impl , Verbosity verbosity,
1880 const NString& subDomain, const NString& msg ) {
1881 BoxesMA& logables= acquireInternalLogables(impl);
1882 logables.Add( msg );
1883 logInternal( impl, verbosity, subDomain, logables );
1889void getStateDomainRecursive( Domain& domain, integer maxDomainPathLength, NAString& buf );
1890void getStateDomainRecursive( Domain& domain, integer maxDomainPathLength, NAString& buf ) {
1891 integer reference= buf.Length();
1892 buf._(
" "); domain.ToString( buf );
1893 integer idx= buf.IndexOf(
'[', reference );
1894 buf.InsertChars(
' ', maxDomainPathLength + 5 - idx + reference, idx);
1898 for ( Domain& subDomain : domain.SubDomains )
1899 getStateDomainRecursive( subDomain, maxDomainPathLength, buf );
1902void getStateDomainsWithDiffVerb( Domain& dom,
int loggerNo, std::vector<Domain*>& results );
1903void getStateDomainsWithDiffVerb( Domain& dom,
int loggerNo, std::vector<Domain*>& results ) {
1904 if ( dom.Parent ==
nullptr
1905 || dom.Parent->GetVerbosity(loggerNo) != dom.GetVerbosity(loggerNo) )
1906 results.emplace_back( &dom );
1908 for(
auto& it : dom.SubDomains )
1909 getStateDomainsWithDiffVerb( it, loggerNo, results );
1912void getStateCollectPrefixes( Domain& dom, integer indentSpaces, NAString& target );
1913void getStateCollectPrefixes( Domain& dom, integer indentSpaces, NAString& target ) {
1915 for (
auto& pfl : dom.PrefixLogables ) {
1916 buffer.InsertChars(
' ', indentSpaces );
1918 integer actLen= buffer.Length();
1919 buffer._( *
static_cast<Box*
>(pfl.first) );
1920 ESC::ReplaceToReadable( buffer, actLen );
1921 buffer <<
Escape( lang::Switch::On, actLen );
1923 if ( pfl.second == lang::Inclusion::Exclude )
1924 buffer._<NC>(
" (Excl.)" );
1925 buffer._<NC>(
Tab( 25, -1 ) );
1926 buffer._<NC>(
"<domain> [" )._<NC>( dom.FullPath )._<NC>(
']').NewLine();
1930 for(
auto& subDom : dom.SubDomains )
1931 getStateCollectPrefixes( subDom, indentSpaces, target );
1939void LI::GetState( LoxImpl* impl, NAString& buf, StateInfo flags ) {
1942 ScopeDump scopeDump(
IF_ALIB_THREADS( impl->scopeInfo.threadDictionary, )
1943 impl->noKeyHashKey, buf );
1945 if (
HasBits( flags, StateInfo::CompilationFlags ) ) {
1948 buf._<NC>(
"ALib Compiler Symbols:" ).NewLine();
1951 buf <<
" " <<
NField( p.Name, 41, lang::Alignment::Left ) <<
':'
1962 if( alib::HasBits( flags, StateInfo::Basic ) )
1963 buf._<NC>(
"Name: \"" )._( impl->scopeInfo.GetLoxName() )._(
'\"').NewLine();
1965 if(
HasBits( flags, StateInfo::Version ) ) {
1970 if(
HasBits( flags, StateInfo::Basic ) )
1971 buf._<NC>(
"#Log Calls: " )._<NC>( impl->CntLogCalls ).NewLine();
1973 if(
HasBits( flags, StateInfo::Basic )
1974 ||
HasBits( flags, StateInfo::Version ) )
1978 if(
HasBits( flags, StateInfo::SPTR ) ) {
1979 buf._<NC>(
"Source Path Trimming Rules: " ).NewLine();
1983 for(
int trimInfoNo= 0; trimInfoNo < 2 ; ++trimInfoNo ) {
1985 std::vector<ScopeInfo::SourcePathTrimRule>* trimInfoList=
1986 trimInfoNo == 0 ? &ScopeInfo::GlobalSPTRs
1987 : &impl->scopeInfo.LocalSPTRs;
1991 for (
auto& ti : *trimInfoList ) {
1993 buf._<NC>( trimInfoNo == 0 ?
" Global: "
1995 buf._<NC>( ti.IsPrefix ?
"\"" :
"\"*");
1996 buf._<NC>( ti.Path )._<NC>(
"\", " );
1997 buf._<NC>( ti.IncludeString );
1998 if ( ti.TrimOffset != 0 )
1999 buf._<NC>( ti.Path )._<NC>(
"\", Offset: " )._<NC>( ti.TrimOffset );
2000 buf._<NC>(
", Priority: " )._( ti.Priority );
2006 buf._<NC>(
" <no rules set>" ).NewLine();
2011 if(
HasBits( flags, StateInfo::DSR ) ) {
2012 buf._<NC>(
"Domain Substitution Rules: " ).NewLine();
2013 if( !impl->domainSubstitutions.empty() ) {
2016 for (
auto& it : impl->domainSubstitutions )
2017 if ( maxWidth < it.Search.Length() )
2018 maxWidth = it.Search.Length();
2022 for (
auto& it : impl->domainSubstitutions ) {
2024 if ( it.type == DomainSubstitutionRule::Type::EndsWith
2025 || it.type == DomainSubstitutionRule::Type::Substring )
2028 buf._<NC>( it.Search );
2029 if ( it.type == DomainSubstitutionRule::Type::StartsWith
2030 || it.type == DomainSubstitutionRule::Type::Substring )
2033 buf._<NC>(
NTab( maxWidth, -1, 0 ) )
2035 ._<NC>( it.Replacement );
2039 buf._<NC>(
" <no rules set>" ).NewLine();
2044 if(
HasBits( flags, StateInfo::Once ) ) {
2045 buf._<NC>(
"Once() Counters: " ).NewLine();
2046 if ( scopeDump.writeStoreMap( &impl->scopeLogOnce ) == 0 )
2047 buf._<NC>(
" <no Once() counters set>" ).NewLine();
2052 if(
HasBits( flags, StateInfo::LogData ) ) {
2053 buf._<NC>(
"Log Data: " ).NewLine();
2054 if ( scopeDump.writeStoreMap( &impl->scopeLogData ) == 0 )
2055 buf._<NC>(
" <no data objects stored>" ).NewLine();
2060 if(
HasBits( flags, StateInfo::PrefixLogables ) ) {
2061 buf._<NC>(
"Prefix Logables: " ).NewLine();
2062 integer oldLength= buf.Length();
2063 scopeDump.writeStore( &impl->scopePrefixes, 2 );
2064 getStateCollectPrefixes( *impl->domains, 2, buf );
2065 if ( oldLength == buf.Length() )
2066 buf._<NC>(
" <no prefix logables set>" ).NewLine();
2071 if(
HasBits( flags, StateInfo::ThreadMappings ) ) {
2072 #if !ALIB_SINGLE_THREADED
2073 buf._<NC>(
"Named Threads: " ).NewLine();
2074 if ( impl->scopeInfo.threadDictionary.Size() == 0 )
2075 buf._<NC>(
" <no thread name mappings set>" ).NewLine();
2077 for (
auto& pair : impl->scopeInfo.threadDictionary ) {
2078 buf._<NC>(
" " ) <<
NField(
String32() <<
'(' << pair.first <<
"):", 7, lang::Alignment::Left )
2079 <<
'\"' << pair.second <<
'\"';
2087 if(
HasBits( flags, StateInfo::ScopeDomains ) ) {
2088 buf._<NC>(
"Scope Domains: " ).NewLine();
2089 if ( scopeDump.writeStore( &impl->scopeDomains, 2 ) == 0 )
2090 buf._<NC>(
" <no scope domains set>" ).NewLine();
2095 if(
HasBits( flags, StateInfo::Loggers ) ) {
2097 std::vector<Domain*> domainsWithDiffVerb;
2098 for (
int treeNo= 0; treeNo < 2; ++treeNo ) {
2102 domTree= impl->domains;
2103 buf._<NC>(
"Loggers:" ).NewLine();
2105 domTree= impl->internalDomains;
2106 buf._<NC>(
"Loggers on Internal Domains:" ).NewLine();
2109 for (
int loggerNo= 0; loggerNo< domTree->CountLoggers(); ++loggerNo ) {
2114 Logger* logger= domTree->GetLogger(loggerNo);
2115 buf._<NC>(
" " )._<NC>( *logger ).NewLine();
2116 buf._<NC>(
" Lines logged: " )._<NC>( logger->CntLogs ).NewLine();
2118 ct.Set( dateTimeConverter.ToDateTime(logger->TimeOfCreation) );
2119 buf._<NC>(
" Creation time: " )._<NC>( ct.Format(
A_CHAR(
"yyyy-MM-dd HH:mm:ss"), as64.Reset()) ).NewLine();
2121 ct.Set( dateTimeConverter.ToDateTime(logger->TimeOfLastLog) );
2122 buf._<NC>(
" Last log time: " )._<NC>( ct.Format(
A_CHAR(
"yyyy-MM-dd HH:mm:ss"), as64.Reset()) ).NewLine();
2124 domainsWithDiffVerb.clear();
2125 getStateDomainsWithDiffVerb( *domTree, loggerNo, domainsWithDiffVerb);
2126 for ( Domain* dom : domainsWithDiffVerb ) {
2128 ._( dom == *domainsWithDiffVerb.begin() ?
"Verbosities: "
2132 buf << dom->FullPath <<
NTab( impl->maxDomainPathLength +1, tabRef);
2134 buf <<
"= " << boxing::MakePair(dom->GetVerbosity( loggerNo ), dom->GetPriority(loggerNo) )
2138 buf._<NC>(
" <no loggers attached>" ).NewLine();
2143 if(
HasBits( flags, StateInfo::InternalDomains ) ) {
2144 buf._<NC>(
"Internal Domains:" ).NewLine();
2145 getStateDomainRecursive( *impl->internalDomains, impl->maxDomainPathLength, buf );
2150 if(
HasBits( flags, StateInfo::Domains ) ) {
2151 buf._<NC>(
"Domains:" ).NewLine();
2152 getStateDomainRecursive( *impl->domains , impl->maxDomainPathLength, buf );
2163#undef UNDEFINED_THREAD
2164#undef ASSERT_ACQUIRED
SharedConfiguration & GetConfig()
TickConverter DateConverter
ALIB_DLL void SetBuffer(integer newCapacity)
bool ConsumeCharFromEnd(TChar consumable)
void Set(const TString< TChar > &src, TChar delimiter, bool skipEmptyTokens=false)
DbgLockAsserter Dbg
The debug tool instance.
DateTime ToDateTime(Ticks ticks)
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define ALIB_LOCK_SHARED_WITH(lock)
#define IF_ALIB_THREADS(...)
#define ALIB_ASSERT(cond, domain)
#define ALIB_WARNING(domain,...)
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_ERROR(domain,...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_CALLER_PRUNED
#define ALIB_LOCK_WITH(lock)
#define ALIB_REL_DBG(releaseCode,...)
#define ALIB_CHARACTERS_WIDE
void Raise(const lang::CallerInfo &ci, int type, std::string_view domain, TArgs &&... args)
const TChar * Search(const TChar *haystack, integer haystackLength, TChar needle)
integer Length(const TChar *cstring)
std::conditional_t< ArrayTraits< T, nchar >::Access !=Policy::NONE, nchar, std::conditional_t< ArrayTraits< T, wchar >::Access !=Policy::NONE, wchar, std::conditional_t< ArrayTraits< T, xchar >::Access !=Policy::NONE, xchar, void > > > Type
constexpr bool HasBits(TEnum element, TEnum selection) noexcept
@ Add
Arithmetic addition ('+'). Precedence 800.
platform_specific integer
integer ThreadID
The ALib thread identifier type.
strings::TEscape< character > Escape
Type alias in namespace alib.
threads::Lock Lock
Type alias in namespace alib.
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128>.
CompilationFlagMeaningsEntry COMPILATION_FLAG_MEANINGS[40]
NLocalString< 64 > NString64
Type alias name for TLocalString<nchar,64>.
strings::TTab< character > Tab
Type alias in namespace alib.
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace alib.
variables::Variable Variable
Type alias in namespace alib.
LocalString< 128 > String128
Type alias name for TLocalString<character,128>.
time::DateTime DateTime
Type alias in namespace alib.
LocalString< 64 > String64
Type alias name for TLocalString<character,64>.
constexpr CString NEW_LINE
A zero-terminated string containing the new-line character sequence.
strings::TSubstring< nchar > NSubstring
Type alias in namespace alib.
boxing::TBoxes< lang::HeapAllocator > Boxes
Type alias in namespace alib.
monomem::TPoolAllocator< MonoAllocator > PoolAllocator
strings::TString< nchar > NString
Type alias in namespace alib.
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace alib.
boxing::TBoxes< PoolAllocator > BoxesPA
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
threads::Thread Thread
Type alias in namespace alib.
strings::TTab< nchar > NTab
Type alias in namespace alib.
strings::TCString< nchar > NCString
Type alias in namespace alib.
strings::util::CalendarDateTime CalendarDateTime
Type alias in namespace alib.
LocalString< 32 > String32
Type alias name for TLocalString<character,32>.
lox::ALoxCamp ALOX
The singleton instance of ALib Camp class ALoxCamp.
boxing::Box Box
Type alias in namespace alib.
threads::RecursiveLock RecursiveLock
Type alias in namespace alib.
boxing::TBoxes< MonoAllocator > BoxesMA
Type alias in namespace alib.
strings::TField< nchar > NField
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
NLocalString< 512 > NString512
Type alias name for TLocalString<nchar,512>.
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256>.
TCompilationFlags COMPILATION_FLAGS
NLocalString< 32 > NString32
Type alias name for TLocalString<nchar,32>.
time::TickConverter TickConverter
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.
lox::detail::Logger Logger
Type alias in namespace alib.
lox::textlogger::TextLogger TextLogger
Type alias in namespace alib.
unsigned char bits[5]
The Flags.