Search in sources :

Example 1 with IbisAppenderWrapper

use of nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper in project iaf by ibissource.

the class ServerStatistics method updateLogConfiguration.

@PUT
@RolesAllowed({ "IbisAdmin", "IbisTester" })
@Path("/server/log")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateLogConfiguration(LinkedHashMap<String, Object> json) throws ApiException {
    initBase(servletConfig);
    Level loglevel = null;
    Boolean logIntermediaryResults = true;
    int maxMessageLength = -1;
    StringBuilder msg = new StringBuilder();
    Logger rootLogger = LogUtil.getRootLogger();
    Appender appender = rootLogger.getAppender("appwrap");
    IbisAppenderWrapper iaw = null;
    if (appender != null && appender instanceof IbisAppenderWrapper) {
        iaw = (IbisAppenderWrapper) appender;
    }
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (key.equalsIgnoreCase("loglevel")) {
            loglevel = Level.toLevel("" + value);
        } else if (key.equalsIgnoreCase("logIntermediaryResults")) {
            logIntermediaryResults = Boolean.parseBoolean("" + value);
        } else if (key.equalsIgnoreCase("maxMessageLength")) {
            maxMessageLength = Integer.parseInt("" + value);
        }
    }
    if (loglevel != null && rootLogger.getLevel() != loglevel) {
        rootLogger.setLevel(loglevel);
        msg.append("LogLevel changed from [" + rootLogger.getLevel() + "] to [" + loglevel + "]");
    }
    boolean logIntermediary = AppConstants.getInstance().getBoolean("log.logIntermediaryResults", true);
    if (logIntermediary != logIntermediaryResults) {
        AppConstants.getInstance().put("log.logIntermediaryResults", "" + logIntermediaryResults);
        if (msg.length() > 0)
            msg.append(", logIntermediaryResults from [" + logIntermediary + "] to [" + logIntermediaryResults + "]");
        else
            msg.append("logIntermediaryResults changed from [" + logIntermediary + "] to [" + logIntermediaryResults + "]");
    }
    if (iaw != null) {
        if (iaw.getMaxMessageLength() != maxMessageLength) {
            if (msg.length() > 0)
                msg.append(", logMaxMessageLength from [" + iaw.getMaxMessageLength() + "] to [" + maxMessageLength + "]");
            else
                msg.append("logMaxMessageLength changed from [" + iaw.getMaxMessageLength() + "] to [" + maxMessageLength + "]");
            iaw.setMaxMessageLength(maxMessageLength);
        }
    }
    if (msg.length() > 0) {
        log.warn(msg.toString());
        LogUtil.getLogger("SEC").info(msg.toString());
    }
    return Response.status(Response.Status.NO_CONTENT).build();
}
Also used : Appender(org.apache.log4j.Appender) Level(org.apache.log4j.Level) LogLevel(org.apache.log4j.lf5.LogLevel) Logger(org.apache.log4j.Logger) IbisAppenderWrapper(nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with IbisAppenderWrapper

use of nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper in project iaf by ibissource.

the class LogHandler method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    String commandIssuedBy = " remoteHost [" + request.getRemoteHost() + "]";
    commandIssuedBy += " remoteAddress [" + request.getRemoteAddr() + "]";
    commandIssuedBy += " remoteUser [" + request.getRemoteUser() + "]";
    Logger lg = LogUtil.getRootLogger();
    DynaActionForm logForm = (DynaActionForm) form;
    String form_logLevel = (String) logForm.get("logLevel");
    boolean form_logIntermediaryResults = false;
    if (null != logForm.get("logIntermediaryResults")) {
        form_logIntermediaryResults = ((Boolean) logForm.get("logIntermediaryResults")).booleanValue();
    }
    log.warn("*** logintermediary results=" + form_logIntermediaryResults);
    String logIntermediaryResults = "false";
    if (form_logIntermediaryResults)
        logIntermediaryResults = "true";
    int form_lengthLogRecords = ((Integer) logForm.get("lengthLogRecords")).intValue();
    Level level = Level.toLevel(form_logLevel);
    Appender appender = lg.getAppender("appwrap");
    IbisAppenderWrapper iaw = null;
    if (appender != null && appender instanceof IbisAppenderWrapper) {
        iaw = (IbisAppenderWrapper) appender;
    }
    String msg = ("LogLevel changed from [" + lg.getLevel() + "] to [" + level + "], logIntermediaryResults from [" + AppConstants.getInstance().getProperty("log.logIntermediaryResults") + "] to [" + "" + form_logIntermediaryResults + "]  and logMaxMessageLength from [" + (iaw != null ? iaw.getMaxMessageLength() : -1) + "] to [" + "" + form_lengthLogRecords + "] by" + commandIssuedBy);
    log.warn(msg);
    secLog.info(msg);
    if (iaw != null) {
        iaw.setMaxMessageLength(form_lengthLogRecords);
    }
    AppConstants.getInstance().put("log.logIntermediaryResults", logIntermediaryResults);
    lg.setLevel(level);
    return (mapping.findForward("success"));
}
Also used : Appender(org.apache.log4j.Appender) DynaActionForm(org.apache.struts.action.DynaActionForm) Level(org.apache.log4j.Level) Logger(org.apache.log4j.Logger) IbisAppenderWrapper(nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper)

Example 3 with IbisAppenderWrapper

use of nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper in project iaf by ibissource.

the class ShowEnvironmentVariables method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    if (ibisManager == null)
        return (mapping.findForward("noIbisContext"));
    DynaActionForm configurationPropertiesForm = getPersistentForm(mapping, form, request);
    Logger rl = LogUtil.getRootLogger();
    configurationPropertiesForm.set("logLevel", rl.getLevel().toString());
    configurationPropertiesForm.set("logIntermediaryResults", new Boolean(false));
    if (AppConstants.getInstance().getResolvedProperty("log.logIntermediaryResults") != null) {
        if (AppConstants.getInstance().getResolvedProperty("log.logIntermediaryResults").equalsIgnoreCase("true")) {
            configurationPropertiesForm.set("logIntermediaryResults", new Boolean(true));
        }
    }
    Appender appender = rl.getAppender("appwrap");
    if (appender != null && appender instanceof IbisAppenderWrapper) {
        IbisAppenderWrapper iaw = (IbisAppenderWrapper) appender;
        configurationPropertiesForm.set("lengthLogRecords", iaw.getMaxMessageLength());
    } else {
        configurationPropertiesForm.set("lengthLogRecords", -1);
    }
    // Retrieve environment variables for browsing
    XmlBuilder configurationsXml = new XmlBuilder("configurations");
    List<Configuration> configurations = ibisManager.getConfigurations();
    for (Configuration configuration : configurations) {
        XmlBuilder configurationXml = new XmlBuilder("configuration");
        configurationXml.setValue(configuration.getConfigurationName());
        configurationXml.addAttribute("nameUC", Misc.toSortName(configuration.getConfigurationName()));
        configurationsXml.addSubElement(configurationXml);
    }
    request.setAttribute("configurations", configurationsXml.toXML());
    Configuration configuration;
    String configurationName = request.getParameter("configuration");
    if (configurationName == null) {
        configurationName = (String) request.getSession().getAttribute("configurationName");
    }
    if (configurationName == null || configurationName.equalsIgnoreCase(CONFIG_ALL) || ibisManager.getConfiguration(configurationName) == null) {
        configuration = configurations.get(0);
        request.getSession().setAttribute("configurationName", configuration.getName());
    } else {
        configuration = ibisManager.getConfiguration(configurationName);
        request.getSession().setAttribute("configurationName", configuration.getName());
    }
    List<String> propsToHide = new ArrayList<String>();
    String propertiesHideString = AppConstants.getInstance(configuration.getClassLoader()).getString("properties.hide", null);
    if (propertiesHideString != null) {
        propsToHide.addAll(Arrays.asList(propertiesHideString.split("[,\\s]+")));
    }
    XmlBuilder envVars = new XmlBuilder("environmentVariables");
    addPropertiesToXmlBuilder(envVars, AppConstants.getInstance(configuration.getClassLoader()), "Application Constants", propsToHide, true);
    addPropertiesToXmlBuilder(envVars, System.getProperties(), "System Properties", propsToHide);
    try {
        addPropertiesToXmlBuilder(envVars, Misc.getEnvironmentVariables(), "Environment Variables");
    } catch (Throwable t) {
        log.warn("caught Throwable while getting EnvironmentVariables", t);
    }
    addPropertiesToXmlBuilder(envVars, JdbcUtil.retrieveJdbcPropertiesFromDatabase(), "Jdbc Properties", propsToHide);
    request.setAttribute("envVars", envVars.toXML());
    // Forward control to the specified success URI
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : Appender(org.apache.log4j.Appender) DynaActionForm(org.apache.struts.action.DynaActionForm) Configuration(nl.nn.adapterframework.configuration.Configuration) ArrayList(java.util.ArrayList) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) Logger(org.apache.log4j.Logger) IbisAppenderWrapper(nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper)

Example 4 with IbisAppenderWrapper

use of nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper in project iaf by ibissource.

the class ServerStatistics method getLogConfiguration.

@GET
@PermitAll
@Path("/server/log")
@Produces(MediaType.APPLICATION_JSON)
public Response getLogConfiguration() throws ApiException {
    Map<String, Object> logSettings = new HashMap<String, Object>(3);
    Logger rootLogger = LogUtil.getRootLogger();
    Appender appender = rootLogger.getAppender("appwrap");
    IbisAppenderWrapper iaw = null;
    if (appender != null && appender instanceof IbisAppenderWrapper) {
        iaw = (IbisAppenderWrapper) appender;
        logSettings.put("maxMessageLength", iaw.getMaxMessageLength());
    } else {
        logSettings.put("maxMessageLength", -1);
    }
    List<String> errorLevels = new ArrayList<String>(Arrays.asList("DEBUG", "INFO", "WARN", "ERROR"));
    logSettings.put("errorLevels", errorLevels);
    for (Iterator<String> iterator = errorLevels.iterator(); iterator.hasNext(); ) {
        String level = iterator.next();
        if (rootLogger.getLevel() == Level.toLevel(level))
            logSettings.put("loglevel", level);
    }
    logSettings.put("logIntermediaryResults", AppConstants.getInstance().getBoolean("log.logIntermediaryResults", true));
    return Response.status(Response.Status.CREATED).entity(logSettings).build();
}
Also used : Appender(org.apache.log4j.Appender) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) IbisAppenderWrapper(nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Aggregations

IbisAppenderWrapper (nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper)4 Appender (org.apache.log4j.Appender)4 Logger (org.apache.log4j.Logger)4 ArrayList (java.util.ArrayList)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Level (org.apache.log4j.Level)2 DynaActionForm (org.apache.struts.action.DynaActionForm)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 PermitAll (javax.annotation.security.PermitAll)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1 LogLevel (org.apache.log4j.lf5.LogLevel)1