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();
}
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"));
}
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"));
}
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();
}
Aggregations