001 /*
002 * Copyright (C) 2006-2010 Enrique Lara (k957@68k.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package net.sf.jmorse.log4j;
018
019 import net.sf.jmorse.AudioMorseWriter;
020
021 import org.apache.log4j.AppenderSkeleton;
022 import org.apache.log4j.spi.LoggingEvent;
023
024 /**
025 * @author <a href="mailto:k957@68k.org">Enrique Lara</a>
026 */
027 public class AudioMorseAppender extends AppenderSkeleton {
028 AudioMorseWriter morse = new AudioMorseWriter();
029
030 // --------------------------------------------------- Properties
031 public int getVolume() {
032 return morse.getVolume();
033 }
034
035 public int getTone() {
036 return morse.getTone();
037 }
038
039 public int getWpm() {
040 return morse.getWpm();
041 }
042
043 public void setVolume(int volume) {
044 morse.setVolume(volume);
045 }
046
047 public void setTone(int tone) {
048 morse.setTone(tone);
049 }
050
051 public void setWpm(int wpm) {
052 morse.setWpm(wpm);
053 }
054
055 public AudioMorseAppender() {
056 //CTOR
057 }
058
059 public void activateOptions() {
060 // morse.setWpm(wpm);
061 // morse.setVolume(volume);
062 // morse.setTone(tone);
063 }
064
065 public synchronized void close() {
066 //
067 }
068
069 public void append(LoggingEvent event) {
070 if (event == null) {
071 return;
072 }
073
074 String msg = this.layout.format(event);
075
076 //System.out.println("map.msg=" + msg);
077 morse.write(msg);
078 }
079
080 public boolean requiresLayout() {
081 return true;
082 }
083 }