List of usage examples for java.util.logging LogRecord getMessage
public String getMessage()
From source file:alma.acs.logging.adapters.JacORBFilter.java
/** * Discards less useful or misleading Jacorb logs based on the message. * <p>/*from w w w .j a va2 s .c om*/ * TODO-: to improve performance, we could instead match file and line, but then would have to update * that information with the next jacorb code change. * The implementation already minimizes string comparison by checking only those messages that can occur at the given log level. * <p> * TODO: Add repeat guard based on the message, e.g. using MultipleRepeatGuard from jacsutil. */ public boolean isLoggable(LogRecord record) { String message = record.getMessage(); boolean isLoggable = true; if (record.getLevel().intValue() == Level.FINE.intValue()) { // map from FINE to FINEST if (message.startsWith("POA ") && (message.endsWith("shutdown is in progress") || message.endsWith("destruction is apparent") || message.endsWith("clear up the queue...") || message.endsWith("... done") || message.endsWith("stop the request controller") || message.endsWith("etherialize all servants ..."))) { record.setLevel(Level.FINEST); } else if (message.startsWith("get_policy_overrides returns") || message.startsWith("read GIOP message of size") || message.startsWith("wrote GIOP message of size")) { // From ACS unit tests it seems that this message is totally harmless, // caused by a Corba stub calling org.jacorb.orb.Delegate#getRelativeRoundtripTimeout() // and asking for the RELATIVE_RT_TIMEOUT_POLICY_TYPE policy. // We do not fully discard the log though because it may have other causes at the AOS. record.setLevel(Level.FINEST); // // Enable the following 2 lines to investigate for http://jira.alma.cl/browse/COMP-8302, to see where all these logs come from // String stackTrace = org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(new Throwable()); // System.out.println("Hack for COMP-8302 debugging: 'get_policy_overrides returns' message logged with trace " + stackTrace); } // from FINE to discard else isLoggable = !(message.endsWith("_invoke: queuing request") || message.indexOf("is queued (queue size:") > 0 || message.endsWith("trying to get a RequestProcessor") || message.endsWith("waiting for queue") || message.endsWith("with request processing") || // for "starts...", "ends..." message.endsWith("invokeOperation on servant (stream based)") || message.endsWith("reset a previous completion call") || message.startsWith("Delegate.getReference") || message.startsWith("Received CodeSetContext. Using") || message.startsWith("ClientConnectionManager: releasing ClientGIOPConnection") || message.startsWith("Delegate released!") || message.endsWith(": streamClosed()") // findPOA: impl_name mismatch ); } else if (record.getLevel().intValue() == Level.INFO.intValue()) { // from INFO to CONFIG if (message.indexOf("(C) The JacORB project") > 0 || message.startsWith("Received CloseConnection on ClientGIOPConnection") || message.startsWith("prepare ORB for shutdown") || message.startsWith("Client-side TCP transport to") || message.startsWith("ORB going down...") || message.startsWith("ORB run") || // also "ORB run, exit" message.equals("ORB shutdown complete") || (message.startsWith("POA ") && (message.endsWith("destroyed"))) || message.startsWith("Opened new server-side TCP/IP")) { record.setLevel(Level.CONFIG); } // from INFO to FINEST else if (message.startsWith("Connected to ") || message.startsWith("Closed server-side transport to") || (message.startsWith("POA ") && (message.endsWith("up the queue ...") || message.endsWith("... done"))) || message.startsWith("Retrying to connect to") || message.startsWith("ClientConnectionManager: created new ClientGIOPConnection") || message.startsWith("ClientConnectionManager: found ClientGIOPConnection") || message.startsWith("Initialising ORB with ID") || message.startsWith("Set default native char codeset to") || message.startsWith("Set default native wchar codeset to") || message.equals("Listener exiting") || message.equals("ConsumerTie exited")) { record.setLevel(Level.FINEST); } // from INFO to stdout shortcut else if ((message.startsWith("ClientGIOPConnection to ") || message.startsWith("ServerGIOPConnection to ")) && message.contains(" BufferDump:\n") || message.startsWith("sendMessages(): ")) { // The jacorb dumps from org.jacorb.orb.etf.StreamConnectionBase.flush() // and org.jacorb.orb.giop.GIOPConnection.getMessage() are very special. // They get enabled via properties 'jacorb.debug.dump_outgoing_messages' // and 'jacorb.debug.dump_incoming_messages' and logged as INFO. // If they are enabled, we still want to see them only in the local logs // (otherwise there may be even "positive feedback" leading to log explosion). // A cleaner concept would be to only flag this LogRecord as "log only locally", // return "isLoggable = true" and leave the rest to the local and remote log handlers. // The fact that we are dealing with a generic LogRecord (not AcsLogRecord) makes this // option also ugly though (LogParameterUtil tricks), and thus we just print and drop // the log right away here. String timeStamp = IsoDateFormat.formatDate(new Date(record.getMillis())); System.out.println(timeStamp + " " + message); isLoggable = false; } // from INFO to discard else isLoggable = !(message.startsWith("oid: ") || message.startsWith("InterceptorManager started with") || message.startsWith("Using server ID (")); } else if (record.getLevel().intValue() == Level.WARNING.intValue()) { // from WARNING to CONFIG // if (message.indexOf("") > 0) { // record.setLevel(Level.CONFIG); // } // // from WARNING to FINEST // else if (message.startsWith("")) { // record.setLevel(Level.FINEST); // } // from WARNING to discard // else isLoggable = !(message.startsWith("no adapter activator exists for") // client tries to find remote poa locally and then complains if not there... ); } else if (record.getLevel().intValue() == Level.SEVERE.intValue()) { // HSO 07-02-19: thought this adapter activator crap was logged as warning, but now it showed up in jcont test as ACS-level "Emergency", which is JDK-SEVERE isLoggable = !(message.startsWith("no adapter activator exists for") // client tries to find remote poa locally and then complains if not there... ); } // filter by possibly modified log level if (isLoggable && record.getLevel().intValue() < this.logLevel) { isLoggable = false; } // if (!isLoggable) { // System.out.println("dropping JacORB message " + message + " with Level " + record.getLevel().getName()); // } // Remove non-ascii chars from the log message, which seems to occur only in logs coming from jacorb, // see http://jira.alma.cl/browse/COMP-3243 // For simplicity we blank all non-ascii-7-printable chars except newline and tab, // at the low risk of erroneously blanking more sophisticated (Umlaut etc) chars that jacorb may send us. // If that turns out to be the case, and the encoding turns out as unicode, then see http://en.wikipedia.org/wiki/C0_and_C1_control_codes if (isLoggable && message != null) { String message2 = null; int mlen = message.length(); for (int i = 0; i < mlen; i++) { char ch = message.charAt(i); if ((ch < 32 || ch >= 127) && ch != '\n' && ch != '\t') { // got a bad char if (message2 == null) { // copy the leading good chars only if needed, to improve performance message2 = message.substring(0, i); } // blank the bad char message2 += '#'; } else if (message2 != null) { message2 += ch; } } if (message2 != null) { record.setMessage(message2); } } return isLoggable; }
From source file:com.skelril.aurora.jail.CSVInmateDatabase.java
public CSVInmateDatabase(File inmateStorageDir) { inmateFile = new File(inmateStorageDir, "inmates.csv"); // Set up an audit trail try {//from w w w . j a v a2s. c o m FileHandler handler = new FileHandler( (new File(inmateStorageDir, "inmates.%g.%u.log")).getAbsolutePath().replace("\\", "/"), true); handler.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n"; } }); auditLogger.addHandler(handler); } catch (SecurityException | IOException e) { log.warning("Failed to setup audit log for the " + "CSV inmate database: " + e.getMessage()); } }
From source file:com.skelril.aurora.jail.CSVJailCellDatabase.java
public CSVJailCellDatabase(File cellStorageDir) { cellFile = new File(cellStorageDir, "cells.csv"); // Set up an audit trail try {/*from w w w . ja va2s.co m*/ FileHandler handler = new FileHandler( (new File(cellStorageDir, "cells.%g.%u.log")).getAbsolutePath().replace("\\", "/"), true); handler.setFormatter(new java.util.logging.Formatter() { @Override public String format(LogRecord record) { return "[" + dateFormat.format(new Date()) + "] " + record.getMessage() + "\r\n"; } }); auditLogger.addHandler(handler); } catch (SecurityException | IOException e) { log.warning("Failed to setup audit log for the CSV cell database: " + e.getMessage()); } }
From source file:at.bitfire.davdroid.log.PlainTextFormatter.java
@Override @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public String format(LogRecord r) { StringBuilder builder = new StringBuilder(); if (!logcat)/* www .ja v a2 s . c o m*/ builder.append(DateFormatUtils.format(r.getMillis(), "yyyy-MM-dd HH:mm:ss")).append(" ") .append(r.getThreadID()).append(" "); builder.append(String.format("[%s] %s", shortClassName(r.getSourceClassName()), r.getMessage())); if (r.getThrown() != null) builder.append("\nEXCEPTION ").append(ExceptionUtils.getStackTrace(r.getThrown())); if (r.getParameters() != null) { int idx = 1; for (Object param : r.getParameters()) builder.append("\n\tPARAMETER #").append(idx++).append(" = ").append(param); } if (!logcat) builder.append("\n"); return builder.toString(); }
From source file:org.dstadler.commons.logging.jdk.PatternFormatter.java
@Override public String format(LogRecord record) { Date time = new Date(record.getMillis()); String formattedTime = dateFormat.format(time); final String logMessage; if (record.getThrown() == null) { Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(), record.getSourceClassName(), record.getSourceMethodName() }; logMessage = logMessageFormat.format(log); } else {/*from w ww.j a v a 2s . c o m*/ String stack = getStackLayout(record.getThrown(), ""); Object[] log = { record.getLoggerName(), record.getLevel(), formattedTime, record.getMessage(), record.getSourceClassName(), record.getSourceMethodName(), record.getThrown().getMessage(), stack }; logMessage = exceptionMessageFormat.format(log); } return logMessage; }
From source file:net.officefloor.plugin.woof.servlet.container.ServletContainerWoofApplicationExtensionServiceTest.java
/** * Ensure {@link Servlet} container is not loaded for marker * <code>web.xml</code>./*from w ww . j ava 2s.co m*/ */ public void testNotLoadServletContainerForMarkerFile() throws Exception { // Ensure log invalid web.xml LoggerAssertion log = LoggerAssertion .setupLoggerAssertion(ServletContainerWoofApplicationExtensionService.class.getName()); try { // Test this.startServer("src/test/invalid-webapp", "invalid-application.woof"); String responseText = this.doGetEntity("/servlet.html"); assertEquals("Should be resource as servlet container not loaded for marker web.xml", "NOT HTTP_SERVLET", responseText); } finally { // Validate log records LogRecord[] records = log.disconnectFromLogger(); assertEquals("Incorrect number of log reords", 1, records.length); LogRecord record = records[0]; String cause = "Invalid web.xml configuration [XmlMarshallException]: Content is not allowed in prolog."; assertEquals("Incorrect log message", "Invalid WEB-INF/web.xml so not loading Servlet servicers: " + cause, record.getMessage()); assertNull("Should not be cause as contained in message", record.getThrown()); } }
From source file:ch.jamiete.hilda.LogFormat.java
@Override public String format(final LogRecord record) { String log = ""; log += this.sdf.format(new Date(record.getMillis())); log += " [" + record.getLevel().getLocalizedName().toUpperCase() + "]"; if (record.getSourceClassName() != null) { final String[] split = record.getSourceClassName().split("\\."); log += " [" + split[split.length == 1 ? 0 : split.length - 1] + "]"; }/* w ww. j av a 2 s . c om*/ log += " " + record.getMessage(); if (record.getThrown() != null) { log += System.getProperty("line.separator") + ExceptionUtils.getStackTrace(record.getThrown()); } log += System.getProperty("line.separator"); return log; }
From source file:org.apache.zeppelin.lens.LensInterpreter.java
private InterpreterResult HandleHelp(JLineShell shell, String st) { java.util.logging.StreamHandler sh = null; java.util.logging.Logger springLogger = null; java.util.logging.Formatter formatter = new java.util.logging.Formatter() { public String format(java.util.logging.LogRecord record) { return record.getMessage(); }/* ww w . j a va 2s. co m*/ }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { sh = new java.util.logging.StreamHandler(baos, formatter); springLogger = HandlerUtils.getLogger(org.springframework.shell.core.SimpleParser.class); springLogger.addHandler(sh); shell.executeCommand(st); } catch (Exception e) { s_logger.error(e.getMessage(), e); return new InterpreterResult(Code.ERROR, e.getMessage()); } finally { sh.flush(); springLogger.removeHandler(sh); sh.close(); } return new InterpreterResult(Code.SUCCESS, baos.toString()); }
From source file:com.acuityph.commons.logging.SimpleFormatter.java
/** * {@inheritDoc}// ww w.ja va2 s . com * * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) */ @Override public final String format(final LogRecord logRecord) { final StringBuilder sb = new StringBuilder(); sb.append(LEVELS_MAP.get(logRecord.getLevel())); final DateFormat sdf = DateFormat.getDateTimeInstance(); sb.append(sdf.format(new Date(logRecord.getMillis()))).append(' '); sb.append(getShortName(logRecord.getSourceClassName())); sb.append('.').append(logRecord.getSourceMethodName()).append(": "); sb.append(logRecord.getMessage()).append("\n"); return sb.toString(); }
From source file:net.officefloor.plugin.woof.WoofOfficeFloorSourceTest.java
/** * Ensure can extend the {@link WebAutoWireApplication}. *//*from w w w.j a va 2s .c om*/ public void testWebApplicationExtension() throws Exception { // Run the application (extended by MockWoofApplicationExtensionService) WoofOfficeFloorSource.start(); // Validate log not loading unknown extension LogRecord[] records = this.sourceLoggerAssertion.getLogRecords(); StringBuilder messages = new StringBuilder(); for (LogRecord record : records) { messages.append("\t" + record.getMessage() + "\n"); } assertEquals("Incorrect number of records:\n" + messages.toString(), 1, records.length); LogRecord record = records[0]; assertEquals("Incorrect unknown extension log record", WoofApplicationExtensionService.class.getName() + ": Provider woof.application.extension.not.available.Service not found", record.getMessage()); // Test that loaded servicer String response = this.doRequest("/chain"); assertEquals("Should be serviced by chained servicer", "CHAINED", response); }