@Override @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public synchronized String format(final LogRecord record) { dat.setTime(record.getMillis()); String source; if (record.getSourceClassName() != null) { source = record.getSourceClassName(); if (record.getSourceMethodName() != null) { source += "#" + record.getSourceMethodName(); } } else { source = record.getLoggerName(); } String message = formatMessage(record); String throwable = ""; if (record.getThrown() != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println(); record.getThrown().printStackTrace(pw); pw.close(); throwable = sw.toString(); } return String.format( FORMAT, dat, source, record.getLoggerName(), record.getLevel().getLocalizedName(), message, throwable); }
@SuppressWarnings("unchecked") @Override public void publish(LogRecord record) { if (record.getLoggerName().endsWith("PluginExecutable") && record.getMessage().contains("PluginExecutable")) { try { Class<? extends IPluginExecutable> clazz = (Class<? extends IPluginExecutable>) Class.forName(record.getLoggerName()); EventBus.getInstance().add(EventType.INFO, clazz, record.getSourceClassName()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } }
@Override public void publish(final LogRecord record) { if (record.getLevel().intValue() < this.getLevel().intValue() || record.getLoggerName().equals(getClass().getName())) { return; } try { Mailer.instance() .send( (message) -> { message.addRecipient( Message.RecipientType.TO, new InternetAddress( "clash.nanobot+log." + record.getLevel().getName().toLowerCase() + "@gmail.com")); message.setSubject(record.getLevel() + ": " + record.getMessage()); String emailBody = "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\">"; emailBody += "<tr><td>Version</td><td>" + BuildInfo.instance().getVersion() + "</td></tr>"; emailBody += "<tr><td>BuildTime</td><td>" + BuildInfo.instance().getTimestamp() + "</td></tr>"; emailBody += "<tr><td>Time</td><td>" + record.getMillis() + "</td></tr>"; emailBody += "<tr><td>Thread</td><td>" + record.getThreadID() + "</td></tr>"; emailBody += "<tr><td>Logger</td><td>" + record.getLoggerName() + "</td></tr>"; emailBody += "<tr><td>Class</td><td>" + record.getSourceClassName() + "</td></tr>"; emailBody += "<tr><td>Method</td><td>" + record.getSourceMethodName() + "</td></tr>"; emailBody += "<tr><td>Level</td><td>" + record.getLevel() + "</td></tr>"; emailBody += "<tr><td>Message</td><td>" + record.getMessage() + "</td></tr>"; final Throwable e = record.getThrown(); if (e != null) { final StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); emailBody += "<tr><td>Exception</td><td>" + writer.toString().replace("\n", "<br/>") + "</td></tr>"; } emailBody += "</table>"; message.setContent(emailBody, "text/html"); }); } catch (final Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); } }
/** * This method sends the LogRecord to the remote logging service. * * @param logRecord The LogRecord to be published to the remote logging service. */ public synchronized void publish(java.util.logging.LogRecord logRecord) { logName = logRecord.getLoggerName(); String xml = getFormatter().format(logRecord); if (xml == null || xml.length() <= 0) { if (Debug.warningEnabled()) { Debug.warning(logName + ":RemoteHandler.publish : formatted xml is null"); } return; } Request request = new Request(xml); if (logRecord instanceof ILogRecord) { Map logInfoMap = ((ILogRecord) logRecord).getLogInfoMap(); String loggedBySid = (String) logInfoMap.get(LogConstants.LOGGED_BY_SID); if (loggedBySid != null) { RequestSet reqSet = (RequestSet) reqSetMap.get(loggedBySid); if (reqSet == null) { reqSet = new RequestSet("Logging"); } reqSet.addRequest(request); reqSetMap.put(loggedBySid, reqSet); } } this.recCount++; if (this.recCount >= recCountLimit) { if (Debug.messageEnabled()) { Debug.message( logName + ":RemoteHandler.publish(): got " + recCount + " records, flushing all"); } nonBlockingFlush(); } }
public String format(LogRecord record) { Object[] arguments = new Object[3]; arguments[0] = record.getLoggerName(); arguments[1] = record.getLevel(); arguments[2] = record.getMessage(); return messageFormat.format(arguments); }
public synchronized String format(LogRecord record) { StringBuffer sb = new StringBuffer(); date.setTime(record.getMillis() + timeDiff); sb.append(dFormat.format(date)); if (isShowingThreads) { Thread currentThread = Thread.currentThread(); if (currentThread != lastThread) { lastThread = currentThread; lastThreadName = currentThread.getName(); } sb.append(" [").append(lastThreadName).append(']'); } sb.append(' ') .append(record.getLevel()) .append(' ') .append(getAliasFor(record.getLoggerName())) .append('|') .append(record.getMessage()) .append(EOL); if (record.getThrown() != null) { try { StringWriter out = new StringWriter(); PrintWriter pout = new PrintWriter(out); record.getThrown().printStackTrace(pout); pout.close(); sb.append(out.toString()); } catch (Exception e) { // Ignore any errors while extracting stack trace } } return sb.toString(); }
/** * @param record * @param sb */ private void printSourceClassName(LogRecord record, StringBuffer sb) { if (record.getSourceClassName() != null) { sb.append(record.getSourceClassName()); } else { sb.append(record.getLoggerName()); } sb.append(seperator); }
public String formatClass(final LogRecord record) { final String append = "..."; final String[] className = record.getLoggerName().split("\\."); final String name = className[className.length - 1]; final int maxLen = 16; return String.format( name.length() > maxLen ? name.substring(0, maxLen - append.length()) + append : name); }
@Override public void publish(final LogRecord record) { final String loggerName = record.getLoggerName(); if (record.getLevel().intValue() >= logLevel && loggerName.startsWith("org.glassfish.jersey") && !loggerName.startsWith("org.glassfish.jersey.test")) { records.add(record); } }
@Override public String format(final LogRecord record) { final String[] className = record.getLoggerName().split("\\."); final String name = className[className.length - 1]; final int maxLen = 22; final String append = "..."; return String.format( "[%s] %-" + maxLen + "s %s %s", dateFormat.format(record.getMillis()), name.length() > maxLen ? name.substring(0, maxLen - append.length()) + append : name, record.getMessage(), StringUtil.throwableToString(record.getThrown())); }
private void logOnServer( LogRecord lr, String strongName, StackTraceDeobfuscator deobfuscator, String loggerNameOverride) throws RemoteLoggingServiceUtil.RemoteLoggingException { if (deobfuscator != null) { lr = deobfuscateLogRecord(deobfuscator, lr, strongName); } String loggerName = (null == loggerNameOverride) ? lr.getLoggerName() : loggerNameOverride; Logger log = Logger.getLogger(loggerName); log.log(lr); }
public void publish(LogRecord record, int nLogType) { // first see if this entry should be filtered out try { if (record != null) { // MARKED by zhaoxy@20101119 /* if (getFilter() != null) { if (!getFilter().isLoggable(record)) return; } */ if (isLoggable(record)) { String HmuImei = null; String Message = record.getMessage(); try { int HmuImeiPos = Message.indexOf("HMU:"); if (HmuImeiPos >= 0) { HmuImei = Message.substring(HmuImeiPos + 4); Message = Message.substring(0, HmuImeiPos); } } catch (Exception e) { } // now store the log entry into the table if (activeConnection()) { try { prepInsert.setInt(1, record.getLevel().intValue()); prepInsert.setString(2, truncate(record.getLoggerName(), 63)); prepInsert.setString(3, truncate(Message, 255)); prepInsert.setLong(4, record.getSequenceNumber()); prepInsert.setString(5, truncate(record.getSourceClassName(), 63)); prepInsert.setString(6, truncate(record.getSourceMethodName(), 31)); prepInsert.setInt(7, record.getThreadID()); prepInsert.setTimestamp(8, new Timestamp(System.currentTimeMillis())); prepInsert.setString(9, truncate(HmuImei, 15)); prepInsert.setInt(10, nLogType); prepInsert.executeUpdate(); } catch (SQLException e) { System.err.println("Exception on publish(record,nLogType)." + e); } } } } } catch (Exception e) { } }
private synchronized void logToFile(LogRecord record) { try { try (PrintWriter out = new PrintWriter(new FileWriter(logToFile, true))) { out.println( record.getMillis() + " " + getLogLevel(record) + " " + record.getLoggerName() + ": " + getFormattedMessage(record)); } } catch (IOException e) { e.printStackTrace(); } }
@Override public void publish(LogRecord record) { final Map<String, Object> map = Loggly.getMap(); String level = "UNKN"; if (record.getLevel().equals(Level.WARNING)) { level = "WARN"; } else if (record.getLevel().equals(Level.SEVERE)) { level = "SEVR"; } else if (record.getLevel().equals(Level.INFO)) { level = "INFO"; } else if (record.getLevel().equals(Level.FINE)) { level = "FINE"; } else if (record.getLevel().equals(Level.FINEST)) { level = "FNST"; } else if (record.getLevel().equals(Level.FINER)) { level = "FINR"; } else if (record.getLevel().equals(Level.CONFIG)) { level = "CONF"; } else if (record.getLevel().equals(Level.OFF)) { level = "OFF "; } else if (record.getLevel().equals(Level.ALL)) { level = "ALL "; } // and the log message itself if (record.getParameters() != null && record.getParameters().length > 0) { java.util.Formatter formatter = new java.util.Formatter(); formatter.format(record.getMessage(), record.getParameters()); map.put("message", formatter.toString()); } else { map.put("message", record.getMessage()); } // finally, other metadata map.put("thread", Thread.currentThread().getName()); map.put("loggerName", record.getLoggerName()); map.put("level", level); if (record.getThrown() != null) { StringWriter sw = new StringWriter(); record.getThrown().printStackTrace(new PrintWriter(sw)); map.put("stackTrace", sw.toString()); } pool.submit(new LogglySample(map)); }
@Override public String format(final LogRecord record) { final StringBuilder result = new StringBuilder() .append("[") .append(record.getLevel().getName()) .append("] ") .append(new Date(record.getMillis())) .append(": ") .append(record.getLoggerName()) .append(": ") .append(record.getMessage()) .append(StringUtil.throwableToString(record.getThrown())); if (appendNewLine) { result.append(LogFormatter.LINE_SEPARATOR); } return result.toString(); }
@Override public LogRecord deobfuscateLogRecord(LogRecord value) { // don't deobfuscate DevMode, there's no symbol map if ("HostedMode".equals(getPermutationStrongName())) { return value; } StackTraceDeobfuscator deobf = StackTraceDeobfuscator.fromUrl(getSymbolMapUrl()); HttpServletRequest threadLocalRequest = getThreadLocalRequest(); String strongName = null; if (threadLocalRequest != null) { // can be null during tests strongName = threadLocalRequest.getHeader(RpcRequestBuilder.STRONG_NAME_HEADER); } LogRecord newRecord = RemoteLoggingServiceUtil.deobfuscateLogRecord(deobf, value, strongName); Logger.getLogger(value.getLoggerName()).log(newRecord); return newRecord; }
/* * @see java.util.logging.Handler#publish(java.util.logging.LogRecord) */ @Override public synchronized void publish(final @Nullable LogRecord record) { if ((record == null) || !isLoggable(record)) { return; } final String message; try { message = formatter_.format(record); } catch (final Exception e) { reportError(null, e, ErrorManager.FORMAT_FAILURE); return; } final FrameworkLogEntry logEntry = new FrameworkLogEntry( record.getLoggerName(), getSeverity(record), 0, message, 0, record.getThrown(), null); frameworkLog_.log(logEntry); }
/** A Custom format implementation that is designed for brevity. */ public String format(LogRecord record) { String loggerName = record.getLoggerName(); if (loggerName == null) { loggerName = "root"; } StringBuilder output = new StringBuilder() .append(calcDate(record.getMillis())) .append('|') .append(record.getLevel()) .append('|') .append(Thread.currentThread().getName()) .append('|') .append(loggerName) .append("|") .append(record.getMessage()) .append(lineSep); return output.toString(); }
/** * Loggable - Don't log core java classes * * @param record log record * @return true */ public boolean isLoggable(LogRecord record) { if (record.getLevel() == Level.SEVERE || record.getLevel() == Level.WARNING) return true; // String loggerName = record.getLoggerName(); if (loggerName != null) { // if (loggerName.toLowerCase().indexOf("focus") != -1) // return true; if (loggerName.startsWith("sun.") || loggerName.startsWith("java.awt.") || loggerName.startsWith("javax.")) return false; } String className = record.getSourceClassName(); if (className != null) { if (className.startsWith("sun.") || className.startsWith("java.awt.") || className.startsWith("javax.")) return false; } return true; } // isLoggable
@Override public final String format(final LogRecord record) { // Create The Date Of Logging Date date = new Date(record.getMillis()); // Create The Thread Of Logging Thread thread = Thread.currentThread(); // Create The Name Of Logger String name = record.getLoggerName(); // Create The Stack Trace Object[] trace = record.getParameters(); // Create The Method Name Object method = trace[2]; // Create The String For Logging String message = record.getLevel() + " to " + "STDERR" + " on " + date + " by " + name + " in " + thread + " at " + method; // Append The User Message message += Preferences.sSYSPROPS_LINE_SEPR + record.getMessage() // The Message + Preferences.sSYSPROPS_LINE_SEPR + Preferences.sSYSPROPS_LINE_SEPR; // return The Final Log Message return message; }
protected void appendPrefix(LogRecord record, StringBuilder prefix) { String levelName = record.getLevel().getName(); String padding = BLANKS.substring(0, MAX_LEVEL_LENGTH - levelName.length()); prefix.append(padding).append(levelName).append(": "); String loggerName = record.getLoggerName(); if (loggerName != null) { prefix.append(Thread.currentThread().getName()).append(" - "); String loggerShortName = loggerName.substring(loggerName.lastIndexOf('.') + 1); prefix.append(loggerShortName); String methodName = record.getSourceMethodName(); if (methodName != null) { prefix.append("." + methodName); } prefix.append(": "); } }
@Override public String format(LogRecord r) { Date date = new Date(r.getMillis()); String[] srcPkg = r.getSourceClassName() .split("\\."); // Won't work properly for sub-classes. Who the f**k cares? return (date.toString() + "[" + r.getLoggerName() + "][" + srcPkg[srcPkg.length - 1] + ":" + r.getSourceMethodName() + "][" + r.getLevel() + "]" + r.getMessage() + "\n"); }
/** * Format the given LogRecord. * * @param record the log record to be formatted. * @return a formatted log record */ @Override public synchronized String format(LogRecord record) { StringBuffer sb = m_buffer; sb.setLength(0); m_timestamp.setTime(record.getMillis()); String tmp = record.getSourceClassName(); m_args[1] = tmp == null ? record.getLoggerName() : tmp; m_args[2] = formatMessage(record); s_tsFormatter.format(m_args, sb, null); Throwable thrown = record.getThrown(); if (thrown != null) { sb.append(s_lineSeparator); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); record.getThrown().printStackTrace(pw); pw.close(); sb.append(sw.toString()); } return sb.toString(); }
/** * Overrides SimpleFormatter format function. Writes the output without displaying the * date/timestamp. * * @param iRecord The log record that needs formatted. * @return A string formatted for a logging message */ public synchronized String format(LogRecord iRecord) { StringBuffer sb = new StringBuffer(); if (iRecord.getSourceClassName() != null) { sb.append(iRecord.getSourceClassName()); } else { sb.append(iRecord.getLoggerName()); } if (iRecord.getSourceMethodName() != null) { sb.append(" "); sb.append(iRecord.getSourceMethodName()); } sb.append(" "); String message = formatMessage(iRecord); sb.append(iRecord.getLevel().getLocalizedName()); sb.append(": "); sb.append(message); sb.append(mLineSeparator); return sb.toString(); }
/** * Passes a record to registered handlers, provided the record is considered as loggable both by * {@link #isLoggable(Level)} and a possibly installed custom {@link #setFilter(Filter) filter}. * * <p>If the logger has been configured to use parent handlers, the record will be forwarded to * the parent of this logger in addition to being processed by the handlers registered with this * logger. * * <p>The other logging methods in this class are convenience methods that merely create a new * LogRecord and pass it to this method. Therefore, subclasses usually just need to override this * single method for customizing the logging behavior. * * @param record the log record to be inspected and possibly forwarded. */ public void log(LogRecord record) { synchronized (lock) { if (!isLoggable(record.getLevel())) return; if ((filter != null) && !filter.isLoggable(record)) return; /* * If no logger name has been set for the log record, use the name of * this logger. */ if (record.getLoggerName() == null) record.setLoggerName(name); /* * Avoid that some other thread is changing the logger hierarchy while * we are traversing it. */ synchronized (LogManager.getLogManager()) { Logger curLogger = this; do { /* * The Sun J2SE 1.4 reference implementation seems to call the * filter only for the logger whose log method is called, never * for any of its parents. Also, parent loggers publish log * record whatever their level might be. This is pretty weird, * but GNU Classpath tries to be as compatible as possible to * the reference implementation. */ for (int i = 0; i < curLogger.handlers.length; i++) curLogger.handlers[i].publish(record); if (curLogger.getUseParentHandlers() == false) break; curLogger = curLogger.getParent(); } while (parent != null); } } }
public String format(LogRecord record) { try { StringBuilder sb = new StringBuilder(); String level = "UNKN"; if (record.getLevel().equals(Level.WARNING)) { level = "WARN"; } else if (record.getLevel().equals(Level.SEVERE)) { level = "SEVR"; } else if (record.getLevel().equals(Level.INFO)) { level = "INFO"; } else if (record.getLevel().equals(Level.FINE)) { level = "FINE"; } else if (record.getLevel().equals(Level.FINEST)) { level = "FNST"; } else if (record.getLevel().equals(Level.FINER)) { level = "FINR"; } else if (record.getLevel().equals(Level.CONFIG)) { level = "CONF"; } else if (record.getLevel().equals(Level.OFF)) { level = "OFF "; } else if (record.getLevel().equals(Level.ALL)) { level = "ALL "; } sb.append(level).append(" "); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); sb.append(sdf.format(new Date(record.getMillis()))).append(" "); String className = record.getLoggerName(); int classNameLength = className.length(); int before = sb.length(); if (classNameLength > CLASS_LENGTH) { int index = -1; while (true) { sb.append(className.charAt(index + 1)); int oldIndex = index; index = className.indexOf(".", index + 1); if (index == -1) { String str = className.substring(oldIndex + 2); int rem = CLASS_LENGTH - (sb.length() - before); if (str.length() > rem) { str = str.substring(0, rem - 1) + '~'; } sb.append(str); break; } else { sb.append('.'); } } } else { sb.append(className); } int after = sb.length(); for (int i = (after - before); i <= CLASS_LENGTH - 1; i++) { sb.append(' '); } sb.append(" - "); if (record.getParameters() != null && record.getParameters().length > 0) { java.util.Formatter formatter = new java.util.Formatter(sb); formatter.format(record.getMessage(), record.getParameters()); formatter.format("\n"); } else { sb.append(record.getMessage()).append("\n"); } if (record.getThrown() != null) { StringWriter sw = new StringWriter(); record.getThrown().printStackTrace(new PrintWriter(sw)); sb.append(sw.toString()); } return sb.toString(); } catch (Exception e) { System.err.println("*******************************************************"); System.err.println("There was a problem formatting a log statement:"); e.printStackTrace(); System.err.println("We will return the raw message and print any stack now"); System.err.println("*******************************************************"); if (record.getThrown() != null) { System.err.println("Root stack trace:"); record.getThrown().printStackTrace(); System.err.println("*******************************************************"); } return record.getMessage() + "\n"; } }
public boolean isLoggable(LogRecord record) { return record.getLoggerName().equalsIgnoreCase("audit"); }
@Override public boolean isLoggable(LogRecord record) { return record.getLoggerName().equalsIgnoreCase("item"); }
@Nullable protected Logger getSLF4JLogger(@Nonnull LogRecord record) { final String name = record.getLoggerName(); return logger(name != null ? name : UNKNOWN_LOGGER_NAME); }
/** * Check to see if the filter is in the logrecord * * @param logRecord the log record to format * @return boolean true if the filter exists in the logRecord */ public boolean isLoggable(LogRecord logRecord) { return (logRecord.getLoggerName().indexOf(logFilterValue) > -1); }