Search in sources :

Example 1 with AcsLogLevelDefinition

use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.

the class LogLevelSelectorPanel method getMinLogLevel.

/**
	 * Get the minimum log level among the loggers
	 * 
	 * @param isLocal true for local log level, false for global log level 
	 * @return the minimum level
	 */
private LogTypeHelper getMinLogLevel(boolean isLocal) {
    LogTypeHelper errret = LogTypeHelper.TRACE;
    LogLevelHelper[] levels;
    try {
        levels = loggersLbl();
    } catch (Exception e) {
        System.err.println("Function not yet implemented by " + getName());
        return errret;
    }
    // @todo should this be OFF (OFF is kind of special)
    int minval = LogTypeHelper.EMERGENCY.getAcsCoreLevel().value;
    for (LogLevelHelper l : levels) {
        int val = isLocal ? l.getLocalLevel() : l.getGlobalLevel();
        if (minval > val)
            minval = val;
    }
    LogTypeHelper logType;
    try {
        AcsLogLevelDefinition levelDef = AcsLogLevelDefinition.fromInteger(minval);
        logType = LogTypeHelper.fromAcsCoreLevel(levelDef);
    } catch (Exception e) {
        System.err.println("Error parsing a log type: " + minval);
        e.printStackTrace(System.err);
        return errret;
    }
    return logType;
}
Also used : LogTypeHelper(com.cosylab.logging.engine.log.LogTypeHelper) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) SystemException(org.omg.CORBA.SystemException) LogLvlSelNotSupportedException(alma.acs.gui.loglevel.LogLvlSelNotSupportedException)

Example 2 with AcsLogLevelDefinition

use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.

the class AcsLogger method configureLevels.

/**
	 * Extracted from {@link #configureLogging(LogConfig)} to support also configuration of Loggers created with 
	 * {@link #createUnconfiguredLogger(String, String)} which do not know about a shared {@link LogConfig}. 
	 * 
	 * @param loggerConfig
	 */
void configureLevels(UnnamedLogger loggerConfig) {
    try {
        // the logger must let through the lowest log level required for either local or remote logging.
        AcsLogLevelDefinition minLogLevelACS = AcsLogLevelDefinition.fromXsdLogLevel(loggerConfig.getMinLogLevel().getType() < loggerConfig.getMinLogLevelLocal().getType() ? loggerConfig.getMinLogLevel() : loggerConfig.getMinLogLevelLocal());
        setLevel(AcsLogLevel.getLowestMatchingJdkLevel(minLogLevelACS));
    } catch (Exception ex) {
        log(Level.INFO, "Failed to configure logger.", ex);
    }
}
Also used : AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition)

Example 3 with AcsLogLevelDefinition

use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.

the class AcsLoggingHandler method configureLogging.

/**
     * Called whenever the logging configuration is updated, for example when the CDB is read.
     * @see alma.acs.logging.config.LogConfigSubscriber#configureLogging(alma.acs.logging.config.LogConfig)
     */
public void configureLogging(LogConfig logConfig) {
    // we expect always the same singleton object, but there is no reason for this class to rely on this 
    // or even assert this behavior. Instead we just update our reference.
    this.logConfig = logConfig;
    // this handler still needs to filter out log records whose levels are in between the thresholds.
    try {
        AcsLogLevelDefinition minLogLevelACS = AcsLogLevelDefinition.fromXsdLogLevel(logConfig.getNamedLoggerConfig(loggerName).getMinLogLevel());
        setLevel(AcsLogLevel.getLowestMatchingJdkLevel(minLogLevelACS));
        immediateDispatchLevel = logConfig.getImmediateDispatchLevel();
    } catch (Exception ex) {
        publish(new LogRecord(Level.WARNING, "Failed to configure remote log handler: " + ex.toString()));
    }
}
Also used : LogRecord(java.util.logging.LogRecord) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition)

Example 4 with AcsLogLevelDefinition

use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.

the class ClientLogManager method getLoggerForCorba.

/**
	 * Gets a logger to be used by ORB and POA classes, or by hibernate or another 3rd party framework whose logging we redirect. 
	 * The logger is connected to the central ACS logger.
	 * <p>
	 * @TODO rename this method to accommodate non-corba frameworks into which we insert ACS loggers, such as hibernate,
	 *       see {@link org.slf4j.impl.ACSLoggerFactory}.
	 * <p>
	 * For hibernate and scxml loggers, the logger automatically receives an initial custom log level configuration, 
	 * to avoid jamming the log system with hibernate or scxml logs. 
	 * The applied custom log level is the maximum of the default log level and WARNING.
	 * Note that the hibernate/scxml logger can still be set to a more verbose level by giving it a custom log config
	 * in the CDB, or dynamically using logLevelGUI etc.
	 * <p>
	 * @TODO Instead of this hard coded and probably confusing application of a custom log level,
	 * the CDB should offer a central configuration option for all jacorb, hibernate, scxml etc loggers,
	 * independently of the process (container or manager etc).
	 * <p>
	 * @param frameworkName
	 *            e.g. <code>jacorb</code> or <code>laser</code>.
	 * @param autoConfigureContextName
	 *            if true, the context (e.g. container name) will be appended to this logger's name as soon as it is
	 *            available, changing the logger name to something like <code>jacorb@frodoContainer</code>.
	 */
public AcsLogger getLoggerForCorba(String frameworkName, boolean autoConfigureContextName) {
    String loggerName = frameworkName;
    AcsLogger frameworkLogger = null;
    processNameLock.lock();
    try {
        // if the process name is not known yet (e.g. during startup), then we need to schedule its update
        if (autoConfigureContextName && processName != null) {
            // if the process name is already known, we can even use it for the regular logger name instead of using a later workaround
            loggerName += "@" + processName;
        }
        frameworkLogger = getAcsLogger(loggerName, LoggerOwnerType.FrameworkLogger);
        if (frameworkName.equals(JacorbLoggerHelper.JACORB_LOGGER_NAME)) {
            // Suppress logs inside the call to the Log service, which could happen e.g. when policies are set and jacorb-debug is enabled.
            // As of ACS 8, that trashy log message would be "get_policy_overrides returns 1 policies"
            frameworkLogger.addIgnoreLogs("org.omg.DsLogAdmin._LogStub", "write_records");
            frameworkLogger.addIgnoreLogs("alma.Logging._AcsLogServiceStub", "write_records");
            frameworkLogger.addIgnoreLogs("alma.Logging._AcsLogServiceStub", "writeRecords");
        }
        if (autoConfigureContextName && processName == null) {
            // mark this logger for process name update
            AcsLoggerInfo loggerInfo = loggers.get(loggerName);
            loggerInfo.needsProcessNameUpdate = true;
        }
    } finally {
        processNameLock.unlock();
    }
    // fix levels if we suppress corba remote logging 
    if (suppressCorbaRemoteLogging) {
        // TODO: Skip this for non-ORB framework loggers, see comment at #suppressCorbaRemoteLogging()
        sharedLogConfig.setAndLockMinLogLevel(AcsLogLevelDefinition.OFF, loggerName);
    } else if (!sharedLogConfig.hasCustomConfig(loggerName)) {
        // In the absence of their own custom logger config, some very verbose loggers 
        // get a minimum log level applied to ensure that a carelessly set low default log level
        // does not swamp the system with log messages.
        AcsLogLevelDefinition minCustomLevel = null;
        if (frameworkName.startsWith(HibernateLoggerHelper.HIBERNATE_LOGGER_NAME_PREFIX) || frameworkName.startsWith(HibernateLoggerHelper.HIBERNATE_SQL_LOGGER_NAME_PREFIX) || frameworkName.startsWith(CommonsLoggingFactory.SCXML_LOGGER_NAME_PREFIX)) {
            minCustomLevel = AcsLogLevelDefinition.WARNING;
        } else if (frameworkName.equals(JacorbLoggerHelper.JACORB_LOGGER_NAME)) {
            // jacorb loggers have a special property that we can use as default, 
            // instead of blindly going for WARNING like we do with the other loggers.
            AcsLogLevelDefinition level = AcsJacorbLoggingInitializer.getLogLevelFromJacorbVerbosity();
            if (level != null) {
                minCustomLevel = level;
            } else {
                minCustomLevel = AcsLogLevelDefinition.WARNING;
                m_internalLogger.info("Failed to consider jacorb log level property, will use only ACS log level mechanisms.");
            }
        }
        if (minCustomLevel != null) {
            // We are dealing with one of the known framework loggers, and it has no other custom log level set.
            // We apply as custom level the maximum of minCustomLevel and the process default level.
            //
            // TODO: These default values currently get lost when calling LoggingConfigurable#refresh_logging_config().
            AcsLogLevelDefinition customLevel = (minCustomLevel.compareTo(sharedLogConfig.getDefaultMinLogLevel()) > 0 ? minCustomLevel : sharedLogConfig.getDefaultMinLogLevel());
            sharedLogConfig.setMinLogLevel(customLevel, loggerName);
            AcsLogLevelDefinition customLevelLocal = (minCustomLevel.compareTo(sharedLogConfig.getDefaultMinLogLevelLocal()) > 0 ? minCustomLevel : sharedLogConfig.getDefaultMinLogLevelLocal());
            sharedLogConfig.setMinLogLevelLocal(customLevelLocal, loggerName);
            m_internalLogger.info("Logger " + loggerName + " created with custom log levels local=" + customLevelLocal.name + ", remote=" + customLevel.name + " to avoid log jams due to careless default log level settings.");
        }
    }
    return frameworkLogger;
}
Also used : AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition)

Example 5 with AcsLogLevelDefinition

use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.

the class StatsCalculator method evalLogLevel.

/**
	 * Evaluate the log level to use using the one defined by {@link #LOGLEVELPROPNAME} property name
	 * or using the default.
	 *  
	 * @return
	 */
private AcsLogLevel evalLogLevel() {
    String propValue = System.getProperty(LOGLEVELPROPNAME);
    if (propValue == null) {
        // No property defined: use default!
        return DEFAULTLOGLEVEL;
    }
    AcsLogLevelDefinition logLevelDef = null;
    // The string can be an integer or a the name of the log level
    try {
        Integer level = Integer.parseInt(propValue);
        logLevelDef = AcsLogLevelDefinition.fromInteger(level.intValue());
    } catch (Throwable t1) {
        // The string should contain the name of the log level like Info
        try {
            logLevelDef = AcsLogLevelDefinition.fromName(propValue);
        } catch (Throwable t2) {
            logLevelDef = null;
        }
    }
    if (logLevelDef == null) {
        // Fall back to the default
        return DEFAULTLOGLEVEL;
    }
    return AcsLogLevel.fromAcsCoreLevel(logLevelDef);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition)

Aggregations

AcsLogLevelDefinition (alma.acs.logging.level.AcsLogLevelDefinition)21 AcsLogLevel (alma.acs.logging.AcsLogLevel)4 LogConfig (alma.acs.logging.config.LogConfig)3 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)3 LogRecord (java.util.logging.LogRecord)3 AcsLogRecord (alma.acs.logging.AcsLogRecord)2 LogParameterUtil (alma.acs.logging.LogParameterUtil)2 LogReceiver (alma.acs.logging.engine.LogReceiver)2 StopWatch (alma.acs.util.StopWatch)2 AlarmTestComponent (alma.alarmContainerTest.AlarmTestComponent)2 LoggingConfig (alma.maci.loggingconfig.LoggingConfig)2 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 Map (java.util.Map)2 Level (java.util.logging.Level)2 Test (org.junit.Test)2 ContainerLogLevelSpec (acs.benchmark.util.ContainerUtil.ContainerLogLevelSpec)1 ACSComponentOperations (alma.ACS.ACSComponentOperations)1