/** * Put a given {@code LogRecord} into internal buffer. If given record is * not loggable, just return. Otherwise it is stored in the buffer. * Furthermore if the record's level is not less than the push level, the * push action is triggered to output all the buffered records to the target * handler, and the target handler will publish them. * * @param record * the log record */ @Override public synchronized void publish(LogRecord record) { if (!isLoggable(record)) { return; } if (cursor >= size) { cursor = 0; } buffer[cursor++] = record; if (record.getLevel().intValue() >= push.intValue()) { push(); } }
printInvalidPropMessage(className + ".size", sizeString, e); push = Level.parse(pushName); } catch (Exception e) { printInvalidPropMessage(className + ".push", pushName, e); initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size];
/** * Close this handler and target handler, free all associated resources. */ @Override public void close() { manager.checkAccess(); target.close(); setLevel(Level.OFF); }
protected static void dumpMemoryTrace47(java.util.logging.Logger logger) { MemoryHandler mHand = null; if (logger!= null) { Handler[] handlers = logger.getHandlers(); for (int i=0; i<handlers.length; i++) { if (handlers[i] instanceof java.util.logging.MemoryHandler) { synchronized (handlers[i]) { mHand = ((java.util.logging.MemoryHandler)handlers[i]); mHand.push(); return; } // synchronized (handler). } } // for handlers... dumpMemoryTrace47(logger.getParent()); } }
class MyMemoryConsoleHandler { private Logger rootLogger; private MemoryHandler mh; private Logger l; private int size = 3; private int entries = 0; public MyMemoryConsoleHandler() { this.rootLogger = Logger.getLogger(""); this.rootLogger.removeHandler(rootLogger.getHandlers()[0]); ConsoleHandler ch = new ConsoleHandler(); this.l = Logger.getLogger("test"); this.mh = new MemoryHandler(ch,this.size,Level.OFF); } public synchronized void push() { this.mh.push(); if (this.entries > this.size) { this.l.severe("Entries in log discarded !!!"); this.mh.push(); } this.entries = 0; } public synchronized void addMessage(String m) { this.entries++; this.l.severe(m); } }
/** * Construct and init a {@code MemoryHandler} using given target, size and * push level, other properties using {@code LogManager} properties or * default values. * * @param target * the given {@code Handler} to output * @param size * the maximum number of buffered {@code LogRecord}, greater than * zero * @param pushLevel * the push level * @throws IllegalArgumentException * if {@code size <= 0} * @throws RuntimeException * if property value are invalid and no default value could be * used. */ public MemoryHandler(Handler target, int size, Level pushLevel) { if (size <= 0) { throw new IllegalArgumentException("size <= 0"); } target.getLevel(); pushLevel.intValue(); this.target = target; this.size = size; this.push = pushLevel; initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size]; }
} catch (Exception ex) { Logger.getLogger(LoggerFactory.class.getName()).log(Level.SEVERE, null, ex); result = new MemoryHandler();
@Override public void push() { super.push(); flush(); }
handler = mh; try { handler = new MemoryHandler(mh, mh.getCapacity(), mh.getPushLevel()); ses = newScheduledThreadPool(1, backgroundThreadFactory()); task = ses.scheduleAtFixedRate(this, 30L, 30L, TimeUnit.MINUTES); try { if (h instanceof MemoryHandler) { ((MemoryHandler) h).push();
/** * Construct and init a {@code MemoryHandler} using given target, size and * push level, other properties using {@code LogManager} properties or * default values. * * @param target * the given {@code Handler} to output * @param size * the maximum number of buffered {@code LogRecord}, greater than * zero * @param pushLevel * the push level * @throws IllegalArgumentException * if {@code size <= 0} * @throws RuntimeException * if property value are invalid and no default value could be * used. */ public MemoryHandler(Handler target, int size, Level pushLevel) { if (size <= 0) { throw new IllegalArgumentException("size <= 0"); } target.getLevel(); pushLevel.intValue(); this.target = target; this.size = size; this.push = pushLevel; initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size]; }
private Handler loadMemoryHandler(final JDKLoggerPluginConfiguration confirguration) throws Exception { final String message = "Must correctly configure target, size, and pushLevel for logging MemoryHandler."; if (confirguration.memoryHandlerTarget() == null || confirguration.memoryHandlerSize() == -1 || confirguration.memoryHandlerPushLevel() == null) { throw new IllegalArgumentException(message); } try { Class<?> targetClass = Class.forName(confirguration.memoryHandlerTarget()); return new MemoryHandler((Handler) targetClass.newInstance(), confirguration.memoryHandlerSize(), Level.parse(confirguration.memoryHandlerPushLevel())); } catch (Exception e) { throw new IllegalArgumentException(message, e); } }
/** * Put a given {@code LogRecord} into internal buffer. If given record is * not loggable, just return. Otherwise it is stored in the buffer. * Furthermore if the record's level is not less than the push level, the * push action is triggered to output all the buffered records to the target * handler, and the target handler will publish them. * * @param record * the log record */ @Override public synchronized void publish(LogRecord record) { if (!isLoggable(record)) { return; } if (cursor >= size) { cursor = 0; } buffer[cursor++] = record; if (record.getLevel().intValue() >= push.intValue()) { push(); } }
printInvalidPropMessage(className + ".size", sizeString, e); push = Level.parse(pushName); } catch (Exception e) { printInvalidPropMessage(className + ".push", pushName, e); initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size];
public String pushToString() { super.push(); return monHandle.logsToString(); } }
/** * Close this handler and target handler, free all associated resources. */ @Override public void close() { manager.checkAccess(); target.close(); setLevel(Level.OFF); }
/** * Construct and init a {@code MemoryHandler} using given target, size and * push level, other properties using {@code LogManager} properties or * default values. * * @param target * the given {@code Handler} to output * @param size * the maximum number of buffered {@code LogRecord}, greater than * zero * @param pushLevel * the push level * @throws IllegalArgumentException * if {@code size <= 0} * @throws RuntimeException * if property value are invalid and no default value could be * used. */ public MemoryHandler(Handler target, int size, Level pushLevel) { if (size <= 0) { throw new IllegalArgumentException("size <= 0"); } target.getLevel(); pushLevel.intValue(); this.target = target; this.size = size; this.push = pushLevel; initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size]; }
private Handler loadMemoryHandler(final JDKLoggerPluginConfiguration confirguration) throws Exception { final String message = "Must correctly configure target, size, and pushLevel for logging MemoryHandler."; if (confirguration.memoryHandlerTarget() == null || confirguration.memoryHandlerSize() == -1 || confirguration.memoryHandlerPushLevel() == null) { throw new IllegalArgumentException(message); } try { Class<?> targetClass = Class.forName(confirguration.memoryHandlerTarget()); return new MemoryHandler((Handler) targetClass.newInstance(), confirguration.memoryHandlerSize(), Level.parse(confirguration.memoryHandlerPushLevel())); } catch (Exception e) { throw new IllegalArgumentException(message, e); } }
/** * Put a given {@code LogRecord} into internal buffer. If given record is * not loggable, just return. Otherwise it is stored in the buffer. * Furthermore if the record's level is not less than the push level, the * push action is triggered to output all the buffered records to the target * handler, and the target handler will publish them. * * @param record * the log record */ @Override public synchronized void publish(LogRecord record) { if (!isLoggable(record)) { return; } if (cursor >= size) { cursor = 0; } buffer[cursor++] = record; if (record.getLevel().intValue() >= push.intValue()) { push(); } }
printInvalidPropMessage(className + ".size", sizeString, e); push = Level.parse(pushName); } catch (Exception e) { printInvalidPropMessage(className + ".push", pushName, e); initProperties("ALL", null, "java.util.logging.SimpleFormatter", null); buffer = new LogRecord[size];
@Override public void push() { super.push(); flush(); } }