예제 #1
0
    public void        SetVerbosity( Logger logger, Verbosity verbosity, String domain = "/",
                                     int priority = Configuration.PrioDefault,
    [CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" )
    {
        #if ALOX_DBG_LOG || ALOX_REL_LOG
        try { Acquire();

            // initialize scope information
            scopeInfo.Set( cln,csf,cmn, owner );

            // check
            if ( logger == null )
            {
                logInternal( Verbosity.Error, "LGR", intMsg._()
                    ._NC( "Given Logger is \"null\". Verbosity not set."  ) );
                return;
            }

            // this might create the (path of) domain(s) and set the \e Loggers' verbosity like their
            // first parent's or as given in configuration
            Domain dom= evaluateResultDomain( domain );

            // search logger, insert if not found
            bool isNewLogger= false;
            int no= dom.GetLoggerNo( logger );
            if( no < 0 )
            {
                no= dom.AddLogger( logger );

                // error, logger with same name already exists
                if( no < 0 )
                {
                    logInternal( Verbosity.Error, "LGR",  intMsg._()
                            ._NC( "Unable to add logger \"" )._NC(logger)
                            ._NC("\". Logger with same name exists." ) );

                    logInternal( Verbosity.Verbose, "LGR",  intMsg._()
                              ._NC( "  Request was: SetVerbosity( \"")._(logger)._NC("\", \"")
                              ._(domain)        ._NC("\", Verbosity.")
                              ._NC(verbosity)   ._NC("\", ")
                              ._(priority)      ._NC(" )." ));

                    Logger existingLogger= dom.GetLogger( logger.GetName() );
                    logInternal( Verbosity.Verbose, "LGR", intMsg._()
                        ._NC( "  Existing Logger: \"")._NC(existingLogger)._('\"') );

                    return;
                }

                // We have to register with the SmartLock facility of the \e Logger.
                // But only if we have not done this yet, via the 'other' root domain tree
                if ( (dom.GetRoot() == domains ? internalDomains.GetLoggerNo( logger )
                                               :         domains.GetLoggerNo( logger ) ) < 0 )
                    logger.AddAcquirer( this );

                // store size of name to support tabular internal log output
                String loggerName= logger.GetName();
                if ( maxLoggerNameLength < loggerName.Length )
                    maxLoggerNameLength=   loggerName.Length;

                // for internal log
                isNewLogger= true;

                // remember that a logger was set after the last removal
                // (for variable LOXNAME_DUMP_STATE_ON_EXIT)
                loggerAddedSinceLastDebugState= true;
            }

            // do
            dom.SetVerbosity( no, verbosity, priority );

            // get verbosities from configuration
            if( isNewLogger )
            {
                logInternal( Verbosity.Info, "LGR",  intMsg._()
                    ._("Logger \"")._( logger )
                    ._(domain.StartsWith(ALox.InternalDomains) ?
                            "\" added for internal log messages." : "\" added." ) );

                // we have to get all verbosities of already existing domains
                Variable variable= new Variable( ALox.VERBOSITY, GetName(), logger.GetName() );
                if( 0 != variable.Load() )
                {
                    getAllVerbosities( logger, domains         , variable );
                    getAllVerbosities( logger, internalDomains , variable );
                }
            }

            intMsg._()._("Logger \"")._( logger.GetName() )._NC( "\":").Tab(11 + maxLoggerNameLength)
                          ._('\'')._NC( dom.FullPath )
                          ._( '\'' ).InsertChars(' ', maxDomainPathLength - dom.FullPath.Length() + 1 )
                          ._( "= Verbosity." );
                          ALox.ToString( verbosity, priority, intMsg ).TrimEnd()._('.');

            Verbosity actVerbosity= dom.GetVerbosity( no );
            if( actVerbosity != verbosity )
                intMsg._( " Lower priority (")._( priority )
                      ._(" < ")._(dom.GetPriority(no))
                      ._( "). Remains " )._NC( actVerbosity )._( '.' );
            logInternal( Verbosity.Info, "LGR", intMsg );

        } finally { Release(); }
        #endif
    }