Search in sources :

Example 11 with LoggerTO

use of org.apache.syncope.common.lib.log.LoggerTO in project syncope by apache.

the class LogsITCase method searchLog.

private Component searchLog(final String property, final String searchPath, final String key) {
    Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
    Component result = component.getPage().visitChildren(ListItem.class, (final ListItem<LoggerTO> object, final IVisit<Component> visit) -> {
        try {
            if (object.getModelObject() instanceof LoggerTO && PropertyResolver.getPropertyGetter(property, object.getModelObject()).invoke(object.getModelObject()).equals(key)) {
                visit.stop(object);
            }
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            LOG.error("Error invoke method", ex);
        }
    });
    return result;
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) IVisit(org.apache.wicket.util.visit.IVisit) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with LoggerTO

use of org.apache.syncope.common.lib.log.LoggerTO in project syncope by apache.

the class LoggerDetails method details.

public void details() {
    if (input.parameterNumber() == 0) {
        try {
            final Map<String, String> details = new LinkedHashMap<>();
            final List<LoggerTO> loggerTOs = loggerSyncopeOperations.list();
            int debugLevel = 0;
            int errorLevel = 0;
            int fatalLevel = 0;
            int infoLevel = 0;
            int offLevel = 0;
            int traceLevel = 0;
            int warnLevel = 0;
            for (final LoggerTO loggerTO : loggerTOs) {
                switch(loggerTO.getLevel()) {
                    case DEBUG:
                        debugLevel++;
                        break;
                    case ERROR:
                        errorLevel++;
                        break;
                    case FATAL:
                        fatalLevel++;
                        break;
                    case INFO:
                        infoLevel++;
                        break;
                    case OFF:
                        offLevel++;
                        break;
                    case TRACE:
                        traceLevel++;
                        break;
                    case WARN:
                        warnLevel++;
                        break;
                    default:
                        break;
                }
            }
            details.put("Total number", String.valueOf(loggerTOs.size()));
            details.put("Set to DEBUG", String.valueOf(debugLevel));
            details.put("Set to ERROR", String.valueOf(errorLevel));
            details.put("Set to FATAL", String.valueOf(fatalLevel));
            details.put("Set to INFO", String.valueOf(infoLevel));
            details.put("Set to OFF", String.valueOf(offLevel));
            details.put("Set to TRACE", String.valueOf(traceLevel));
            details.put("Set to WARN", String.valueOf(warnLevel));
            loggerResultManager.printDetails(details);
        } catch (final SyncopeClientException ex) {
            LOG.error("Error reading details about logger", ex);
            loggerResultManager.genericError(ex.getMessage());
        }
    } else {
        loggerResultManager.unnecessaryParameters(input.listParameters(), LIST_HELP_MESSAGE);
    }
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with LoggerTO

use of org.apache.syncope.common.lib.log.LoggerTO in project syncope by apache.

the class LoggerUpdate method update.

public void update() {
    if (input.parameterNumber() >= 1) {
        final List<LoggerTO> loggerTOs = new ArrayList<>();
        boolean failed = false;
        for (String parameter : input.getParameters()) {
            Pair<String, String> pairParameter = Input.toPairParameter(parameter);
            try {
                LoggerTO loggerTO = loggerSyncopeOperations.read(pairParameter.getKey());
                loggerTO.setLevel(LoggerLevel.valueOf(pairParameter.getValue()));
                loggerSyncopeOperations.update(loggerTO);
                loggerTOs.add(loggerTO);
            } catch (WebServiceException | SyncopeClientException | IllegalArgumentException ex) {
                LOG.error("Error updating logger", ex);
                if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) {
                    loggerResultManager.typeNotValidError("logger level", input.firstParameter(), CommandUtils.fromEnumToArray(LoggerLevel.class));
                } else if ("Parameter syntax error!".equalsIgnoreCase(ex.getMessage())) {
                    loggerResultManager.genericError(ex.getMessage());
                    loggerResultManager.genericError(UPDATE_HELP_MESSAGE);
                } else if (ex.getMessage().startsWith("NotFound")) {
                    loggerResultManager.notFoundError("Logger", parameter);
                } else {
                    loggerResultManager.genericError(ex.getMessage());
                    loggerResultManager.genericError(UPDATE_HELP_MESSAGE);
                }
                failed = true;
                break;
            }
        }
        if (!failed) {
            loggerResultManager.fromUpdate(loggerTOs);
        }
    } else {
        loggerResultManager.commandOptionError(UPDATE_HELP_MESSAGE);
    }
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) WebServiceException(javax.xml.ws.WebServiceException) ArrayList(java.util.ArrayList) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Example 14 with LoggerTO

use of org.apache.syncope.common.lib.log.LoggerTO in project syncope by apache.

the class LoggerUpdateAll method updateAll.

public void updateAll() {
    if (input.parameterNumber() == 1) {
        final List<LoggerTO> loggerTOs = new ArrayList<>();
        boolean failed = false;
        for (final LoggerTO loggerTO : loggerSyncopeOperations.list()) {
            try {
                loggerTO.setLevel(LoggerLevel.valueOf(input.firstParameter()));
                loggerSyncopeOperations.update(loggerTO);
                loggerTOs.add(loggerTO);
            } catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) {
                LOG.error("Error updating logger", ex);
                if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) {
                    loggerResultManager.typeNotValidError("logger level", input.firstParameter(), CommandUtils.fromEnumToArray(LoggerLevel.class));
                } else {
                    loggerResultManager.genericError(ex.getMessage());
                    loggerResultManager.genericError(UPDATE_ALL_HELP_MESSAGE);
                }
                failed = true;
                break;
            }
        }
        if (!failed) {
            loggerResultManager.fromUpdate(loggerTOs);
        }
    } else {
        loggerResultManager.commandOptionError(UPDATE_ALL_HELP_MESSAGE);
    }
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) WebServiceException(javax.xml.ws.WebServiceException) ArrayList(java.util.ArrayList) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Example 15 with LoggerTO

use of org.apache.syncope.common.lib.log.LoggerTO in project syncope by apache.

the class LoggerRestClient method enableAudit.

public void enableAudit(final AuditLoggerName auditLoggerName) {
    LoggerTO loggerTO = new LoggerTO();
    loggerTO.setKey(auditLoggerName.toLoggerName());
    loggerTO.setLevel(LoggerLevel.DEBUG);
    getService(LoggerService.class).update(LoggerType.AUDIT, loggerTO);
}
Also used : LoggerTO(org.apache.syncope.common.lib.log.LoggerTO) LoggerService(org.apache.syncope.common.rest.api.service.LoggerService)

Aggregations

LoggerTO (org.apache.syncope.common.lib.log.LoggerTO)15 AuditLoggerName (org.apache.syncope.common.lib.types.AuditLoggerName)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 WebServiceException (javax.xml.ws.WebServiceException)3 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)2 Logger (org.apache.syncope.core.persistence.api.entity.Logger)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 Response (javax.ws.rs.core.Response)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1 AuditReportletConf (org.apache.syncope.common.lib.report.AuditReportletConf)1 ConnInstanceTO (org.apache.syncope.common.lib.to.ConnInstanceTO)1 ConnPoolConfTO (org.apache.syncope.common.lib.to.ConnPoolConfTO)1