/** **************************************************************************************** * This method is looping over the \e Loggers, checking their verbosity against the given * one, and, if they match, invoke the log method of the \e Logger. * With the first logger identified to be active, the <em>Prefix Objects</em> get * collected from the scope store. * @param dom The domain to log on * @param verbosity The verbosity. * @param logable The object to log. * @param prefixes Denotes if prefixes should be included or not. ******************************************************************************************/ protected void log( Domain dom, Verbosity verbosity, Object logable, Inclusion prefixes ) { // OK, this is a little crude, but the simplest solution: As class ScopeStore sees // null objects as nothing and won't return them in a walk, we replace null by // an object (we choose the store itself) and fix this in the loop back to null if ( logable == null ) logable= scopePrefixes; dom.CntLogCalls++; logObjects.Clear(); for ( int i= 0; i < dom.CountLoggers() ; i++ ) if( dom.IsActive( i, verbosity ) ) { // lazily collect objects once if ( logObjects.Count == 0 ) { scopePrefixes.InitWalk( Scope.ThreadInner, logable ); Object next; while( (next= scopePrefixes.Walk() ) != null ) { if ( prefixes == Inclusion.Include || next == logable) logObjects.Insert( 0, next != scopePrefixes ? next : null ); // was this the actual? then insert domain-associated logables now bool excludeOthers= false; if( next == logable ) { int qtyThreadInner= logObjects.Count -1; Domain pflDom= dom; while ( pflDom != null ) { for( int ii= pflDom.PrefixLogables.Count -1 ; ii >= 0 ; ii-- ) { Domain.PL pl= pflDom.PrefixLogables[ii]; logObjects.Insert( 0, pl.Logable ); if ( pl.IncludeOtherPLs == Inclusion.Exclude ) { excludeOthers= true; break; } } pflDom= excludeOthers ? null : pflDom.Parent; } // found a stoppable one? remove those from thread inner and break if (excludeOthers) { for ( int ii= 0; ii < qtyThreadInner ; ii++ ) logObjects.RemoveAt( logObjects.Count - 1 ); break; } } } } Logger logger= dom.GetLogger(i); logger.Acquire(); logger.CntLogs++; logger.Log( dom, verbosity, logObjects, scopeInfo ); logger.TimeOfLastLog.Set(); logger.Release(); } }
/** **************************************************************************************** * Invokes \b Find on the given domain and logs internal message when the domain was * not known before. * * @param domainSystem The domain system. Either the standard or the internal one. * @param domainPath The domain path. * @return The resulting \ref cs::aworx::lox::core::Domain "Domain". ******************************************************************************************/ Domain findDomain( Domain domainSystem, AString domainPath ) { AString substPath= domainSystem == domains ? tmpSubstitutionPath : tmpSubstitutionPathInternalDomains; int maxSubstitutions= 10; for(;;) { // loop for creating domains, one by one Domain dom= null; for(;;) { bool wasCreated= false; dom= domainSystem.Find( domainPath, DomainSensitivity, 1, ref wasCreated ); if ( wasCreated ) { // get maximum domain path length (for nicer State output only...) if ( maxDomainPathLength < dom.FullPath.Length() ) maxDomainPathLength= dom.FullPath.Length(); // log info on new domain intMsg._()._('\'')._NC( dom.FullPath )._NC("' registered."); logInternal( Verbosity.Info, "DMN", intMsg ); } // read domain from Config if ( !dom.ConfigurationRead ) { dom.ConfigurationRead= true; Variable variable= new Variable(); for ( int i= 0; i < dom.CountLoggers(); ++i ) { Logger logger= dom.GetLogger(i); if ( 0 != variable.Define( ALox.VERBOSITY, GetName(), logger.GetName() ).Load() ) getVerbosityFromConfig( logger, dom, variable ); } getDomainPrefixFromConfig( dom ); } // log inherited setting for each logger if ( wasCreated ) { if ( domainSystem.CountLoggers() == 0 ) logInternal( Verbosity.Verbose, "DMN", intMsg._()._NC("No loggers set, yet.") ); else for ( int i= 0; i < domainSystem.CountLoggers(); i++ ) { intMsg._()._(" \"")._( dom.GetLogger(i).GetName() )._NC("\":"); intMsg.InsertChars( ' ', maxLoggerNameLength + 6 - intMsg.Length() ); intMsg._NC( dom.FullPath ) ._NC( " = " ); ALox.ToString( dom.GetVerbosity( i ), dom.GetPriority( i), intMsg ); logInternal( Verbosity.Verbose, "DMN", intMsg ); } } else break; } // apply domain substitutions if( domainSubstitutions.Count > 0 ) { substPath.Clear(); while( maxSubstitutions-- > 0 ) { // loop over rules bool substituted= false; foreach( DomainSubstitutionRule rule in domainSubstitutions ) { switch( rule.type ) { case DomainSubstitutionRule.Type.StartsWith: if( substPath.IsEmpty() ) { if ( dom.FullPath.StartsWith( rule.Search, DomainSensitivity ) ) { substPath._( rule.Replacement )._( dom.FullPath, rule.Search.Length() ); substituted= true; continue; //next rule } } else { if ( substPath.StartsWith( rule.Search, DomainSensitivity ) ) { substPath.ReplaceSubstring( rule.Replacement, 0, rule.Search.Length() ); substituted= true; continue; //next rule } } break; case DomainSubstitutionRule.Type.EndsWith: if( substPath.IsEmpty() ) { if ( dom.FullPath.EndsWith( rule.Search, DomainSensitivity ) ) { substPath._( dom.FullPath, 0, dom.FullPath.Length() - rule.Search.Length() )._( rule.Replacement ); substituted= true; continue; } } else { if ( substPath.EndsWith( rule.Search, DomainSensitivity ) ) { substPath.DeleteEnd( rule.Search.Length() )._( rule.Replacement ); substituted= true; continue; } } break; case DomainSubstitutionRule.Type.Substring: if( substPath.IsEmpty() ) { int idx= dom.FullPath.IndexOf( rule.Search, 0, DomainSensitivity ); if ( idx >= 0 ) { substPath._( dom.FullPath, 0, idx )._( rule.Replacement)._( dom.FullPath, idx + rule.Search.Length() ); substituted= true; continue; //next rule } } else { int idx= substPath.IndexOf( rule.Search, 0, DomainSensitivity ); if ( idx >= 0 ) { substPath.ReplaceSubstring( rule.Replacement, idx, rule.Search.Length() ); substituted= true; continue; //next rule } } break; case DomainSubstitutionRule.Type.Exact: { if( substPath.IsEmpty() ) { if ( dom.FullPath.Equals( rule.Search ) ) { substPath._( rule.Replacement); substituted= true; continue; //next rule } } else { if ( substPath.Equals( rule.Search) ) { substPath._()._( rule.Replacement ); substituted= true; continue; //next rule } } } break; } // switch rule type }//rules loop // stop if non was found if( !substituted ) break; } // too many substitutions? if ( maxSubstitutions <= 0 && !oneTimeWarningCircularDS ) { oneTimeWarningCircularDS= true; intMsg._()._( "The Limit of 10 domain substitutions was reached. Circular substitution assumed!" + " (This error is only reported once!)" ); logInternal( Verbosity.Error, "DMN", intMsg ); } // anything substituted? if( substPath.Length() > 0 ) { domainPath= substPath; continue; } } return dom; } }