mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 09:07:27 -05:00
Adds event logging, code cleanup and some decoder issue resolution.
This commit is contained in:
63
src/module/log/CallEventLogger.java
Normal file
63
src/module/log/CallEventLogger.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package module.log;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import module.decode.event.CallEvent;
|
||||
import module.decode.event.ICallEventListener;
|
||||
import sample.Listener;
|
||||
|
||||
public class CallEventLogger extends EventLogger implements ICallEventListener,
|
||||
Listener<CallEvent>
|
||||
{
|
||||
public CallEventLogger( Path logDirectory, String fileNameSuffix )
|
||||
{
|
||||
super( logDirectory, fileNameSuffix );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( CallEvent callEvent )
|
||||
{
|
||||
write( callEvent.toCSV() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader()
|
||||
{
|
||||
return CallEvent.getCSVHeader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<CallEvent> getCallEventListener()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
super.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.start();
|
||||
}
|
||||
}
|
||||
97
src/module/log/EventLogComponentEditor.java
Normal file
97
src/module/log/EventLogComponentEditor.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package module.log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import module.log.config.EventLogConfiguration;
|
||||
import controller.channel.AbstractChannelEditor;
|
||||
import controller.channel.ChannelNode;
|
||||
|
||||
public class EventLogComponentEditor extends AbstractChannelEditor
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private JCheckBox mBinaryLogger = new JCheckBox( "Binary Messages" );
|
||||
private JCheckBox mDecodedLogger = new JCheckBox( "Decoded Messages" );
|
||||
private JCheckBox mCallEventLogger = new JCheckBox( "Call Events" );
|
||||
|
||||
public EventLogComponentEditor( ChannelNode channelNode )
|
||||
{
|
||||
super( channelNode );
|
||||
|
||||
add( mBinaryLogger, "span" );
|
||||
add( mDecodedLogger, "span" );
|
||||
add( mCallEventLogger, "span" );
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the combo box to the type stored in the config object, causing the
|
||||
* editor panel to reset with the stored config
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
SwingUtilities.invokeLater(new Runnable()
|
||||
{
|
||||
final List<EventLogType> mLoggers = mChannelNode.getChannel()
|
||||
.getEventLogConfiguration().getLoggers();
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mBinaryLogger.setSelected(
|
||||
mLoggers.contains( EventLogType.BINARY_MESSAGE ) );
|
||||
mDecodedLogger.setSelected(
|
||||
mLoggers.contains( EventLogType.DECODED_MESSAGE ) );
|
||||
mCallEventLogger.setSelected(
|
||||
mLoggers.contains( EventLogType.CALL_EVENT ) );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the current configuration as the stored configuration
|
||||
*/
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
EventLogConfiguration config = mChannelNode.getChannel()
|
||||
.getEventLogConfiguration();
|
||||
|
||||
config.clear();
|
||||
|
||||
if( mBinaryLogger.isSelected() )
|
||||
{
|
||||
config.addLogger( EventLogType.BINARY_MESSAGE );
|
||||
}
|
||||
|
||||
if( mDecodedLogger.isSelected() )
|
||||
{
|
||||
config.addLogger( EventLogType.DECODED_MESSAGE );
|
||||
}
|
||||
if( mCallEventLogger.isSelected() )
|
||||
{
|
||||
config.addLogger( EventLogType.CALL_EVENT );
|
||||
}
|
||||
}
|
||||
}
|
||||
71
src/module/log/EventLogManager.java
Normal file
71
src/module/log/EventLogManager.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package module.log;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import module.Module;
|
||||
import module.log.MessageEventLogger.Type;
|
||||
import module.log.config.EventLogConfiguration;
|
||||
import properties.SystemProperties;
|
||||
|
||||
public class EventLogManager
|
||||
{
|
||||
private Path mDirectory;
|
||||
|
||||
public EventLogManager()
|
||||
{
|
||||
mDirectory = SystemProperties.getInstance()
|
||||
.getApplicationFolder( "event_logs" );
|
||||
}
|
||||
|
||||
public List<Module> getLoggers( EventLogConfiguration config, String prefix )
|
||||
{
|
||||
List<Module> loggers = new ArrayList<Module>();
|
||||
|
||||
for( EventLogType type: config.getLoggers() )
|
||||
{
|
||||
loggers.add( getLogger( type, prefix ) );
|
||||
}
|
||||
|
||||
return loggers;
|
||||
}
|
||||
|
||||
public EventLogger getLogger( EventLogType eventLogType, String prefix )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append( prefix );
|
||||
sb.append( eventLogType.getFileSuffix() );
|
||||
sb.append( ".log" );
|
||||
|
||||
switch( eventLogType )
|
||||
{
|
||||
case BINARY_MESSAGE:
|
||||
return new MessageEventLogger( mDirectory, sb.toString(), Type.BINARY );
|
||||
case DECODED_MESSAGE:
|
||||
return new MessageEventLogger( mDirectory, sb.toString(), Type.DECODED );
|
||||
case CALL_EVENT:
|
||||
return new CallEventLogger( mDirectory, sb.toString() );
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/module/log/EventLogType.java
Normal file
51
src/module/log/EventLogType.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package module.log;
|
||||
|
||||
|
||||
public enum EventLogType
|
||||
{
|
||||
BINARY_MESSAGE( "Binary Messages", "_binary_messages" ),
|
||||
DECODED_MESSAGE( "Decoded Messages", "_decoded_messages" ),
|
||||
CALL_EVENT( "Call Events", "_call_events" );
|
||||
|
||||
private String mDisplayString;
|
||||
private String mFileSuffix;
|
||||
|
||||
EventLogType( String displayString, String fileSuffix )
|
||||
{
|
||||
mDisplayString = displayString;
|
||||
mFileSuffix = fileSuffix;
|
||||
}
|
||||
|
||||
public String getDisplayString()
|
||||
{
|
||||
return mDisplayString;
|
||||
}
|
||||
|
||||
public String getFileSuffix()
|
||||
{
|
||||
return mFileSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return mDisplayString;
|
||||
}
|
||||
}
|
||||
139
src/module/log/EventLogger.java
Normal file
139
src/module/log/EventLogger.java
Normal file
@@ -0,0 +1,139 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package module.log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import module.Module;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import util.TimeStamp;
|
||||
|
||||
public abstract class EventLogger extends Module
|
||||
{
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger( EventLogger.class );
|
||||
|
||||
/* Illegal filename characters */
|
||||
private static final String[] mIllegalCharacters =
|
||||
{ "#", "%", "&", "{", "}", "\\", "<", ">", "*", "?", "/",
|
||||
" ", "$", "!", "'", "\"", ":", "@", "+", "`", "|", "=" };
|
||||
|
||||
private Path mLogDirectory;
|
||||
private String mFileNameSuffix;
|
||||
private String mLogFileName;
|
||||
protected Writer mLogFile;
|
||||
|
||||
public EventLogger( Path logDirectory, String fileNameSuffix )
|
||||
{
|
||||
mLogDirectory = logDirectory;
|
||||
mFileNameSuffix = fileNameSuffix;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
if( mLogFileName != null )
|
||||
{
|
||||
return mLogFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String getHeader();
|
||||
|
||||
public void start()
|
||||
{
|
||||
if( mLogFile == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append( mLogDirectory );
|
||||
sb.append( File.separator );
|
||||
sb.append( TimeStamp.getTimeStamp( "_" ) );
|
||||
sb.append( "_" );
|
||||
sb.append( replaceIllegalCharacters( mFileNameSuffix ) );
|
||||
|
||||
mLogFileName = sb.toString();
|
||||
|
||||
mLog.info( "Creating log file:" + mLogFileName );
|
||||
|
||||
mLogFile = new OutputStreamWriter(new FileOutputStream( mLogFileName ) );
|
||||
|
||||
write( getHeader() );
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
mLog.error("Couldn't create log file in directory:" + mLogDirectory );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces any illegal filename characters in the proposed filename
|
||||
*/
|
||||
private String replaceIllegalCharacters( String filename )
|
||||
{
|
||||
for( String illegalCharacter: mIllegalCharacters )
|
||||
{
|
||||
filename = filename.replace( illegalCharacter, "_" );
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
if( mLogFile != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
mLogFile.flush();
|
||||
mLogFile.close();
|
||||
mLogFile = null;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
mLog.error( "Couldn't close log file:" + mFileNameSuffix );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void write( String eventLogEntry )
|
||||
{
|
||||
try
|
||||
{
|
||||
mLogFile.write( eventLogEntry + "\n" );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
mLog.error( "Error writing entry to event log file", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/module/log/MessageEventLogger.java
Normal file
89
src/module/log/MessageEventLogger.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package module.log;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import message.IMessageListener;
|
||||
import message.Message;
|
||||
import sample.Listener;
|
||||
import util.TimeStamp;
|
||||
|
||||
public class MessageEventLogger extends EventLogger implements
|
||||
IMessageListener, Listener<Message>
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
BINARY, DECODED
|
||||
};
|
||||
|
||||
private Type mType;
|
||||
|
||||
public MessageEventLogger( Path logDirectory,
|
||||
String fileNameSuffix,
|
||||
Type type )
|
||||
{
|
||||
super( logDirectory, fileNameSuffix );
|
||||
|
||||
mType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener<Message> getMessageListener()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
super.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( Message message )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append( TimeStamp.getTimeStamp( " " ) );
|
||||
sb.append( "," );
|
||||
sb.append( ( message.isValid() ? "PASSED" : "FAILED" ) );
|
||||
sb.append( "," );
|
||||
|
||||
if ( mType == Type.BINARY )
|
||||
{
|
||||
sb.append( message.getBinaryMessage() );
|
||||
} else
|
||||
{
|
||||
sb.append( message.getMessage() );
|
||||
}
|
||||
|
||||
write( sb.toString() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader()
|
||||
{
|
||||
return mType.toString() + " Message Logger\n";
|
||||
}
|
||||
}
|
||||
58
src/module/log/config/EventLogConfiguration.java
Normal file
58
src/module/log/config/EventLogConfiguration.java
Normal file
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package module.log.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import module.log.EventLogType;
|
||||
import controller.config.Configuration;
|
||||
|
||||
@XmlRootElement( name = "event_log_configuration" )
|
||||
public class EventLogConfiguration extends Configuration
|
||||
{
|
||||
protected List<EventLogType> mLoggers = new ArrayList<EventLogType>();
|
||||
|
||||
public EventLogConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
@XmlElement( name = "logger" )
|
||||
public List<EventLogType> getLoggers()
|
||||
{
|
||||
return mLoggers;
|
||||
}
|
||||
|
||||
public void setLoggers( ArrayList<EventLogType> loggers )
|
||||
{
|
||||
mLoggers = loggers;
|
||||
}
|
||||
|
||||
public void addLogger( EventLogType logger )
|
||||
{
|
||||
mLoggers.add( logger );
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
mLoggers.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user