View Javadoc
1   package com.nilhcem.fakesmtp.log;
2   
3   import java.util.Observable;
4   
5   import ch.qos.logback.classic.spi.ILoggingEvent;
6   import ch.qos.logback.core.AppenderBase;
7   
8   /**
9    * Logback appender class, which will redirect all logs to the {@code LogsPane} object.
10   *
11   * @author Nilhcem
12   * @since 1.0
13   * @param <E> a Logback logging event.
14   */
15  public final class SMTPLogsAppender<E> extends AppenderBase<E> {
16  	private SMTPLogsObservable observable = new SMTPLogsObservable();
17  
18  	/**
19  	 * Receives a log from Logback, and sends it to the {@code LogsPane} object.
20  	 *
21  	 * @param event a Logback {@code ILoggingEvent} event.
22  	 */
23  	@Override
24  	protected void append(E event) {
25  		if (event instanceof ILoggingEvent) {
26  			ILoggingEvent loggingEvent = (ILoggingEvent) event;
27  			observable.notifyObservers(loggingEvent.getFormattedMessage());
28  		}
29  	}
30  
31  	/**
32  	 * Returns the log observable object.
33  	 *
34  	 * @return the log observable object.
35  	 */
36  	public Observable getObservable() {
37  		return observable;
38  	}
39  }