protected LinkedList<MLogTarget> logTargets = new LinkedList<MLogTarget>();
+ protected boolean pausedState = false;
+ protected LinkedList<MLogMessage> logMessageQueue = new LinkedList<MLogMessage>();
+
/* */
public MLogFilter(MLogFilter.Threshold threshold) {
/* Output */
+ public void setPausedState(boolean pausedState) throws MLoggingException {
+ this.pausedState = pausedState;
+ //
+ if (!this.getPausedState()) {
+ this.flushMessages();
+ }
+ }
+
+ public boolean getPausedState() {
+ return this.pausedState;
+ }
+
public void appendMessage(MLogFilter.Threshold level, String message) throws MLoggingException {
this.appendMessage(level, message, 0);
}
if (level.ordinal() > this.getThreshold().ordinal()) {
return;
}
- for (MLogTarget t: this.getLogTargetsReference()) {
- t.appendMessage(message, indentation);
+ //
+ this.logMessageQueue.add(new MLogMessage(message, indentation));
+ //
+ if (!this.getPausedState()) {
+ this.flushMessages();
+ }
+ }
+
+ protected void flushMessages() throws MLoggingException {
+ while (0 < this.logMessageQueue.size()) {
+ MLogMessage logMessage = this.logMessageQueue.remove();
+ String message = logMessage.getMessage();
+ int indentation = logMessage.getIndentation();
+ //
+ for (MLogTarget logTarget: this.getLogTargetsReference()) {
+ logTarget.appendMessage(message, indentation);
+ }
}
}
--- /dev/null
+/**
+ * Macaco
+ * Copyright (c) 2009-2013 Marco Zanon <info@marcozanon.com>.
+ * Released under MIT license (see LICENSE for details).
+ */
+
+package com.marcozanon.macaco.logging;
+
+import com.marcozanon.macaco.MObject;
+
+public class MLogMessage extends MObject {
+
+ protected String message = null;
+ protected int indentation = 0;
+
+ /* */
+
+ public MLogMessage(String message, int indentation) {
+ if (null == message) {
+ throw new IllegalArgumentException("Invalid 'message': null.");
+ }
+ if (0 > indentation) {
+ throw new IllegalArgumentException(String.format("Invalid 'indentation': %s: cannot be negative.", indentation));
+ }
+ //
+ this.message = message;
+ this.indentation = indentation;
+ }
+
+ /* Values */
+
+ public String getMessage() {
+ return this.message;
+ }
+
+ public int getIndentation() {
+ return this.indentation;
+ }
+
+}