Search in sources :

Example 1 with AcsLogLevel

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

the class TMCDBServicesHelper method getServicesList.

/**
	 * Queries the TMCDB and return the list of services to start for the 
	 * passed configuration name.
	 * 
	 * @param configurationName The not <code>null</code> and not empty name of the configuration
	 * @return The not <code>null</code> list of services to start for the passed configuration
	 * @throws HibernateException In case of error getting data from the TMCDB
	 */
@SuppressWarnings("rawtypes")
public List<AcsServiceToStart> getServicesList(String configurationName) throws HibernateException {
    if (configurationName == null || configurationName.isEmpty()) {
        throw new IllegalArgumentException("Invalid null or empty name of configuration");
    }
    logger.log(AcsLogLevel.DEBUG, "Getting the list of services from TMCDB and configuration " + configurationName);
    Query query = session.createSQLQuery(sqlQuery);
    query.setString(namedParameterName, configurationName);
    List svcs = query.list();
    List<AcsServiceToStart> ret = new ArrayList<TMCDBServicesHelper.AcsServiceToStart>();
    if (svcs != null) {
        AcsLogLevel lvl = (svcs.size() == 0) ? AcsLogLevel.WARNING : AcsLogLevel.DEBUG;
        logger.log(lvl, "Got " + svcs.size() + " services from TMCDB");
        for (Object s : svcs) {
            ret.add(AcsServiceToStart.instanceFromDBRow((Object[]) s));
        }
    } else {
        logger.log(AcsLogLevel.WARNING, "Got a NULL list of services from TMCDB");
    }
    return ret;
}
Also used : Query(org.hibernate.Query) AcsLogLevel(alma.acs.logging.AcsLogLevel) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with AcsLogLevel

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

the class TestLogLevelsCompImpl method logDummyMessages.

/**
	 * @throws IllegalArgumentEx 
	 * @see alma.contLogTest.LogLevelsOperations#logDummyMessagesForAllLevels()
	 */
public void logDummyMessages(int[] coreLevels) throws IllegalArgumentEx {
    // add a minor delay to be sure receiving side is all set-up and ready
    try {
        Thread.sleep(150);
    } catch (InterruptedException ex) {
    }
    AcsLogLevel acsLogLevel = null;
    for (int coreLevel : coreLevels) {
        String name;
        try {
            acsLogLevel = AcsLogLevel.fromAcsCoreLevel(AcsLogLevelDefinition.fromInteger(coreLevel));
            name = AcsLogLevelDefinition.fromInteger(coreLevel).name();
        } catch (AcsJIllegalArgumentEx e) {
            throw e.toIllegalArgumentEx();
        }
        m_logger.log(acsLogLevel, "dummy log message for core level " + coreLevel + "/" + name);
    }
    if (acsLogLevel.compareTo(flushingLevel) < 0) {
        m_logger.log(flushingLevel, "Dummy log to get the local log queue flushed.");
    }
//LOG_TEST_DummyMessage.log(m_logger, "A beautiful name with a cherry on top", "Dr. F. Amous");
}
Also used : AcsLogLevel(alma.acs.logging.AcsLogLevel) AcsJIllegalArgumentEx(alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)

Example 3 with AcsLogLevel

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

the class EngineFilteringTest method testFiltering.

/**
	 * Set a filter and checks if the logs received are those passing a filters.
	 * <P>
	 * In this case we do not need to check the correctness of the logs received 
	 * in the listeners but only if they are received or not because it means that
	 * the engine is using the filters.
	 * <P>
	 * For this example, the test defines 1 filter based on the type of the logs.
	 * <P>
	 * The correctness of the filtering is also tested in another test because the engine 
	 * uses the same filters used by the table.
	 * 
	 * @throws Exception
	 */
public void testFiltering() throws Exception {
    // Randomly generate the logs
    Collection<ILogEntry> logs = CacheUtils.generateLogs(NUMBER_OF_LOGS);
    assertNotNull(logs);
    assertEquals(NUMBER_OF_LOGS, logs.size());
    Collection<ILogEntry> flushLogs = CacheUtils.generateLogsType(100, LogTypeHelper.NOTICE);
    // Create a filter for the type INFO
    Filter f = new ExactFilter(LogField.ENTRYTYPE, false, LogTypeHelper.INFO, false);
    assertNotNull(f);
    // And a filter for the source name
    Filter nameFilter = new ExactFilter(LogField.ROUTINE, false, getName(), false);
    assertNotNull(nameFilter);
    // No filters exists in the engine
    assertNull(engine.getFilters());
    // Add the filters
    engine.addFilter(f);
    engine.addFilter(nameFilter);
    assertNotNull(engine.getFilters());
    assertEquals("Size differ", 2, engine.getFilters().size());
    // connect the engine
    engine.connect();
    // wait until the engine is connected
    int iterCount = 0;
    while (iterCount < TIMEOUT && !engine.isConnected()) {
        iterCount++;
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
        }
    }
    assertTrue(engine.isConnected());
    // publish all the logs and count the number of INFO logs
    int infos = 0;
    for (ILogEntry log : logs) {
        AcsLogLevel level = AcsLogLevel.fromAcsCoreLevel(log.getType().acsCoreLevel);
        m_logger.log(level, (String) log.getField(LogField.LOGMESSAGE));
        if (log.getType() == LogTypeHelper.INFO) {
            infos++;
        }
    }
    // If it is possible then it is better this second option then sending logs..
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Flushing");
    for (ILogEntry log : flushLogs) {
        AcsLogLevel level = AcsLogLevel.fromAcsCoreLevel(log.getType().acsCoreLevel);
        m_logger.log(level, (String) log.getField(LogField.LOGMESSAGE));
    }
    // wait till all the logs are received
    //
    // It additionally waits for TIMEOUT seconds after the last log has been 
    // received to be sure there are no further logs delayed because of caching
    // or similar problems
    // The number of seconds after the last log has been received
    int elapsed = 0;
    // The number of logs at the previous iteration
    int count = 0;
    while (elapsed < TIMEOUT) {
        synchronized (receivedLogs) {
            if (receivedLogs.size() != count) {
                count = receivedLogs.size();
                elapsed = 0;
                continue;
            }
        }
        // No new logs received
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
        }
        elapsed++;
    }
    // If all the logs have been received then xmlLogsCount must be greater then NUMBER_OF_LOGS
    // Not equal because the xml logs are not filtered and there can be logs generated
    // outside of this object
    assertTrue("Received only " + xmlLogsCount.get() + " xml logs, when there should have been at least " + NUMBER_OF_LOGS, xmlLogsCount.get() >= NUMBER_OF_LOGS);
    // Check if the number of received logs is as expected
    assertEquals(infos, receivedLogs.size());
}
Also used : ExactFilter(com.cosylab.logging.engine.ExactFilter) ILogEntry(com.cosylab.logging.engine.log.ILogEntry) ExactFilter(com.cosylab.logging.engine.ExactFilter) Filter(com.cosylab.logging.engine.Filter) AcsLogLevel(alma.acs.logging.AcsLogLevel)

Example 4 with AcsLogLevel

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

the class AcsBinLogFormatter method formatBinary.

LogBinaryRecord formatBinary(LogRecord logRecord) {
    LogBinaryRecord rLog = new LogBinaryRecord();
    // log level 
    AcsLogLevel acsLevel = AcsLogLevel.getNativeLevel(logRecord.getLevel());
    if (acsLevel == null) {
        return null;
    }
    final AcsLogLevelDefinition acsCoreLevel = acsLevel.getAcsLevel();
    // get date
    Date date = new Date(logRecord.getMillis());
    String TimeStamp = IsoDateFormat.formatDate(date);
    LogParameterUtil logParamUtil = new LogParameterUtil(logRecord);
    rLog.type = (short) acsCoreLevel.value;
    rLog.TimeStamp = TimeStamp;
    String file = logRecord.getSourceClassName();
    if (file == null) {
        if (acsCoreLevel == AcsLogLevelDefinition.DEBUG)
            rLog.File = "unknown";
    } else
        rLog.File = file;
    long line = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_LINE, -1);
    if (line < 0) {
        if (acsCoreLevel == AcsLogLevelDefinition.TRACE || acsCoreLevel == AcsLogLevelDefinition.DEBUG)
            rLog.Line = 0;
    } else
        rLog.Line = (int) line;
    String Routine = logRecord.getSourceMethodName();
    if (Routine == null) {
        if (acsCoreLevel == AcsLogLevelDefinition.TRACE) {
            rLog.Routine = "unknown";
        }
    } else {
        rLog.Routine = Routine;
    }
    // host name: may be different from local host if ErrorTrace gets logged
    String hostName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_HOSTNAME, null);
    if (hostName == null || hostName.length() == 0) {
        hostName = getLocalHostName();
    }
    rLog.Host = hostName;
    //		String process = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_PROCESSNAME, null);
    //		if (process != null)
    //            rLog.Process = process;
    //        else{
    String process = logRecord.getLoggerName();
    if (process != null)
        rLog.Process = "LoggerName: " + process;
    else
        rLog.Process = "";
    //      }
    // source object: the container name or component name
    String sourceObject = logRecord.getLoggerName();
    if (sourceObject != null) {
        rLog.SourceObject = sourceObject;
    } else
        rLog.SourceObject = "";
    // add thread ID, or name if given		
    String threadName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_THREAD_NAME, null);
    if (threadName != null && threadName.length() > 0)
        rLog.Thread = threadName;
    else if (logRecord.getThreadID() >= 0)
        rLog.Thread = "" + logRecord.getThreadID();
    else
        rLog.Thread = "";
    // add context		
    String context = logParamUtil.extractStringProperty("Context", null);
    if (context != null)
        rLog.LogContext = context;
    else
        rLog.LogContext = "";
    // add stack info
    rLog.StackId = "";
    rLog.StackLevel = 0;
    if (acsCoreLevel.compareTo(AcsLogLevelDefinition.WARNING) >= 0) {
        // add stack id
        String stackId = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_STACK_ID, null);
        if (stackId == null)
            rLog.StackId = "unknown";
        else
            rLog.StackId = stackId;
        // add stack idlevel
        long stackLevel = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_STACK_LEVEL, -1);
        if (stackLevel > 0)
            rLog.StackLevel = (int) stackLevel;
    }
    // add log id		
    long logId = logRecord.getSequenceNumber();
    if (logId >= 0)
        rLog.LogId = "" + logId;
    else
        rLog.LogId = "";
    // add URI		
    String uri = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_URI, null);
    if (uri != null)
        rLog.Uri = uri;
    else
        rLog.Uri = "";
    // add priority
    // to be written only different as entry priority		
    long priority = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_PRIORITY, acsCoreLevel.value);
    if (priority != acsCoreLevel.value)
        rLog.Priority = (int) priority;
    else
        rLog.Priority = -1;
    // the log message becomes the text in our XML record
    if (logRecord.getMessage() != null) {
        rLog.MsgData = logRecord.getMessage();
    } else
        rLog.MsgData = "";
    //add Audience, Array and Antenna, if applicable
    if (logRecord instanceof AcsLogRecord) {
        rLog.Audience = ((AcsLogRecord) logRecord).getAudience();
        rLog.Array = ((AcsLogRecord) logRecord).getArray();
        rLog.Antenna = ((AcsLogRecord) logRecord).getAntenna();
    }
    // <Data> elements: logged exception or error trace, and log parameters
    //NameValue a;
    //rLog.log_data = new NameValue[propertiesMap.size() + 1];
    //TODO: see why there are not attributes here
    rLog.attributes = new NameValue[0];
    NameValue[] log_data = new NameValue[257];
    //rLog.log_data = new NameValue[257];
    int i = 0;
    try {
        // logged exception
        Throwable loggedThrowable = logRecord.getThrown();
        if (loggedThrowable != null) {
            StringWriter exWriter = new StringWriter();
            loggedThrowable.printStackTrace(new PrintWriter(exWriter));
            log_data[i++] = new NameValue("LoggedException", exWriter.toString());
        }
        // log parameters (except for the special properties which were used already to set specific fields)
        for (Object param : logParamUtil.getNonSpecialPropertiesMapParameters()) {
            if (i >= 255)
                break;
            if (param instanceof Map) {
                // any map that is not the special properties map we interpret as name-value pairs.
                Map propertiesMap = (Map) param;
                for (Object keyName : propertiesMap.keySet()) {
                    String value = propertiesMap.get(keyName).toString();
                    log_data[i++] = new NameValue(keyName.toString(), value);
                }
            } else {
                // a single parameter was logged, but we have to fit it into our name-value scheme using a fake name
                String value = param.toString();
                log_data[i++] = new NameValue("LoggedParameter", value);
            }
        }
    } catch (Exception e) {
        // expected not to happen often at all, thus no try blocks inside every loop, so we may lose some <Data>
        String value = e.toString();
        log_data[i++] = new NameValue("DataConstructionError", value);
    }
    rLog.log_data = new NameValue[i];
    for (int j = 0; j < i; j++) {
        rLog.log_data[j] = log_data[j];
    }
    return rLog;
}
Also used : LogParameterUtil(alma.acs.logging.LogParameterUtil) LogBinaryRecord(alma.ACSLoggingLog.LogBinaryRecord) Date(java.util.Date) AcsLogRecord(alma.acs.logging.AcsLogRecord) NameValue(alma.ACSLoggingLog.NameValue) StringWriter(java.io.StringWriter) AcsLogLevel(alma.acs.logging.AcsLogLevel) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 5 with AcsLogLevel

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

the class AcsXMLLogFormatter method format.

/**
	 * Constructs the XML log message that can be sent to the ACS logging service.
	 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
	 */
public String format(LogRecord logRecord) {
    // log level 
    AcsLogLevel acsLevel = AcsLogLevel.getNativeLevel(logRecord.getLevel());
    if (acsLevel == null) {
        return "";
    }
    final AcsLogLevelDefinition acsCoreLevel = acsLevel.getAcsLevel();
    final String levelName = acsLevel.getEntryName();
    // get date
    String TimeStamp = IsoDateFormat.formatDate(new Date(logRecord.getMillis()));
    LogParameterUtil logParamUtil = new LogParameterUtil(logRecord);
    StringBuffer sb = new StringBuffer("");
    sb.append("<");
    sb.append(levelName);
    sb.append(" ");
    sb.append("TimeStamp=\"" + TimeStamp + "\" ");
    String file = logRecord.getSourceClassName();
    if (file == null) {
        if (acsCoreLevel == AcsLogLevelDefinition.DEBUG)
            sb.append("File=\"unknown\" ");
    } else {
        sb.append("File=\"" + file + "\"  ");
    }
    long line = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_LINE, -1);
    if (line < 0) {
        if (acsCoreLevel == AcsLogLevelDefinition.TRACE || acsCoreLevel == AcsLogLevelDefinition.DEBUG)
            sb.append("Line=\"0\" ");
    } else {
        sb.append("Line=\"" + line + "\" ");
    }
    String Routine = logRecord.getSourceMethodName();
    if (Routine == null) {
        if (acsCoreLevel == AcsLogLevelDefinition.TRACE)
            sb.append("Routine=\"unknown\" ");
    } else {
        sb.append("Routine=\"" + maskAttribute(Routine) + "\" ");
    }
    // host name: may be different from local host if ErrorTrace gets logged
    String hostName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_HOSTNAME, null);
    if (hostName == null || hostName.length() == 0) {
        hostName = this.getLocalHostName();
    }
    //hostName = getLocalHostName();
    sb.append("Host=\"" + hostName + "\" ");
    String process = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_PROCESSNAME, null);
    if (process != null) {
        sb.append("Process=\"" + process + "\" ");
    } else {
        process = logRecord.getLoggerName();
        if (process != null) {
            sb.append("Process=\"" + process + "\" ");
        }
    }
    String sourceObject = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_SOURCEOBJECT, null);
    if (sourceObject != null) {
        sb.append("SourceObject=\"" + sourceObject + "\" ");
    } else {
        sourceObject = logRecord.getLoggerName();
        if (sourceObject != null) {
            sb.append("SourceObject=\"" + sourceObject + "\" ");
        }
    }
    // add thread ID, or name if given		
    String threadName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_THREAD_NAME, null);
    if (threadName != null && threadName.length() > 0) {
        sb.append("Thread=\"" + threadName + "\" ");
    } else if (logRecord.getThreadID() >= 0) {
        sb.append("Thread=\"" + logRecord.getThreadID() + "\" ");
    }
    // add context		
    String context = logParamUtil.extractStringProperty("Context", null);
    if (context != null) {
        sb.append("Context=\"" + context + "\" ");
    }
    // add stack info
    if (acsCoreLevel.compareTo(AcsLogLevelDefinition.WARNING) >= 0) {
        // add stack id
        String stackId = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_STACK_ID, null);
        if (stackId == null)
            sb.append("StackId=\"unknown\" ");
        else
            sb.append("StackId=\"" + stackId + "\" ");
        // add stack idlevel
        long stackLevel = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_STACK_LEVEL, -1);
        if (stackLevel < 0)
            sb.append("StackLevel=\"0\" ");
        else
            sb.append("StackLevel=\"" + stackLevel + "\" ");
    }
    // add log id		
    long logId = logRecord.getSequenceNumber();
    if (logId >= 0) {
        sb.append("LogId=\"" + logId + "\" ");
    }
    // add URI		
    String uri = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_URI, null);
    if (uri != null) {
        sb.append("Uri=\"" + uri + "\" ");
    }
    // add priority
    // to be written only different as entry priority		
    long priority = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_PRIORITY, acsCoreLevel.value);
    if (priority != acsCoreLevel.value) {
        sb.append("Priority=\"" + priority + "\" ");
    }
    //add Audience, if applicable(for typeSafeLogs/Operator logs)
    if (logRecord instanceof AcsLogRecord) {
        String audience = ((AcsLogRecord) logRecord).getAudience();
        if (!audience.equals(""))
            sb.append("Audience=\"" + audience + "\" ");
        //add Array
        String array = ((AcsLogRecord) logRecord).getArray();
        if (!array.equals(""))
            sb.append("Array=\"" + array + "\" ");
        //add Antenna
        String antenna = ((AcsLogRecord) logRecord).getAntenna();
        if (!antenna.equals(""))
            sb.append("Antenna=\"" + antenna + "\" ");
    }
    sb.setCharAt(sb.lastIndexOf("") - 1, '>');
    // the log message becomes the text in our XML record
    if (logRecord.getMessage() != null) {
        sb.append(maskMessage(logRecord.getMessage()));
    }
    try {
        // logged exception
        Throwable loggedThrowable = logRecord.getThrown();
        if (loggedThrowable != null) {
            StringWriter exWriter = new StringWriter();
            loggedThrowable.printStackTrace(new PrintWriter(exWriter));
            sb.append("<Data Name=\"LoggedException\">" + maskMessage(exWriter.toString()) + "</Data>");
        }
        // log parameters (except for the special properties which were used already to set specific fields)
        for (Object param : logParamUtil.getNonSpecialPropertiesMapParameters()) {
            if (param instanceof Map) {
                // any map that is not the special properties map we interpret as name-value pairs.
                Map propertiesMap = (Map) param;
                for (Object keyName : propertiesMap.keySet()) {
                    String value = maskEmptyDataContent(propertiesMap.get(keyName).toString());
                    sb.append("<Data Name=\"" + keyName.toString() + "\">" + maskMessage(value) + "</Data>");
                }
            } else {
                // a single parameter was logged, but we have to fit it into our name-value scheme using a fake name
                String value = maskEmptyDataContent(param.toString());
                sb.append("<Data Name=\"LoggedParameter\">" + maskMessage(value) + "</Data>");
            }
        }
    } catch (Exception e) {
        // expected not to happen often at all, thus no try blocks inside every loop, so we may lose some <Data>
        sb.append("<Data Name=\"DataConstructionError\">" + maskMessage(e.toString()) + "</Data>");
    }
    // end tag of XML record
    sb.append("</" + levelName + ">");
    String Log = sb.toString();
    //		System.out.println("Logging XML log entry " + Log);
    return Log;
}
Also used : LogParameterUtil(alma.acs.logging.LogParameterUtil) Date(java.util.Date) AcsLogRecord(alma.acs.logging.AcsLogRecord) StringWriter(java.io.StringWriter) AcsLogLevel(alma.acs.logging.AcsLogLevel) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Aggregations

AcsLogLevel (alma.acs.logging.AcsLogLevel)8 AcsLogLevelDefinition (alma.acs.logging.level.AcsLogLevelDefinition)3 AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)2 AcsLogRecord (alma.acs.logging.AcsLogRecord)2 LogParameterUtil (alma.acs.logging.LogParameterUtil)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 Map (java.util.Map)2 CBlong (alma.ACS.CBlong)1 AcsJIllegalArgumentEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)1 LogBinaryRecord (alma.ACSLoggingLog.LogBinaryRecord)1 NameValue (alma.ACSLoggingLog.NameValue)1 AcsLoggingHandler (alma.acs.logging.AcsLoggingHandler)1 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)1 LoggingConfig (alma.maci.loggingconfig.LoggingConfig)1 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)1 ExactFilter (com.cosylab.logging.engine.ExactFilter)1 Filter (com.cosylab.logging.engine.Filter)1 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)1