diff --git a/src/module/decode/event/CallEvent.java b/src/module/decode/event/CallEvent.java index 8991d4f0..a04eacc4 100644 --- a/src/module/decode/event/CallEvent.java +++ b/src/module/decode/event/CallEvent.java @@ -30,7 +30,8 @@ public abstract class CallEvent implements Comparable protected long mEventStart = System.currentTimeMillis(); protected long mEventEnd; - private SimpleDateFormat mSDF = new SimpleDateFormat("yyyyMMdd','HHmmss"); + private SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMdd"); + private SimpleDateFormat TIME_FORMATTER = new SimpleDateFormat("HHmmss"); protected DecoderType mDecoderType; protected CallEventType mCallEventType; @@ -176,15 +177,23 @@ public abstract class CallEvent implements Comparable StringBuilder sb = new StringBuilder(); sb.append("'"); - sb.append(mSDF.format(new Date(getEventStartTime()))); + + Date eventStart = new Date(getEventStartTime()); + sb.append(DATE_FORMATTER.format(eventStart)); + sb.append("','"); + sb.append(TIME_FORMATTER.format(eventStart)); sb.append("','"); if(mEventEnd != 0) { - sb.append(mSDF.format(new Date(getEventEndTime()))); + Date eventEnd = new Date(getEventEndTime()); + sb.append(DATE_FORMATTER.format(eventEnd)); + sb.append("','"); + sb.append(TIME_FORMATTER.format(eventEnd)); + sb.append("','"); } else { - sb.append("','"); + sb.append("','',"); } sb.append("','"); sb.append(getDecoderType().toString()); diff --git a/src/module/log/EventLogger.java b/src/module/log/EventLogger.java index 120ee29a..b6d800f5 100644 --- a/src/module/log/EventLogger.java +++ b/src/module/log/EventLogger.java @@ -1,22 +1,28 @@ /******************************************************************************* - * 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 + * sdrtrunk + * Copyright (C) 2014-2017 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 + * ******************************************************************************/ package module.log; +import module.Module; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import util.TimeStamp; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -26,117 +32,107 @@ import java.io.Writer; import java.nio.file.Path; import java.util.concurrent.ScheduledExecutorService; -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 ); + 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; + private static final String[] ILLEGAL_FILENAME_CHARACTERS = {"#", "%", "&", "{", "}", "\\", "<", ">", + "*", "?", "/", " ", "$", "!", "'", "\"", ":", "@", "+", "`", "|", "="}; - 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(); - - @Override - public void start( ScheduledExecutorService executor ) + private Path mLogDirectory; + private String mFileNameSuffix; + private String mLogFileName; + protected Writer mLogFile; + + public EventLogger(Path logDirectory, String fileNameSuffix) { - 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 ) ); + mLogDirectory = logDirectory; + mFileNameSuffix = fileNameSuffix; + } - 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 ); - } - } + public String toString() + { + if(mLogFileName != null) + { + return mLogFileName; + } + else + { + return "Unknown"; + } + } + + public abstract String getHeader(); + + @Override + public void start(ScheduledExecutorService executor) + { + 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 ) + private String replaceIllegalCharacters(String filename) { - for( String illegalCharacter: mIllegalCharacters ) - { - filename = filename.replace( illegalCharacter, "_" ); - } + for(String illegalCharacter : ILLEGAL_FILENAME_CHARACTERS) + { + filename = filename.replace(illegalCharacter, "_"); + } - return filename; + 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 + if(mLogFile != null) { - mLogFile.write( eventLogEntry + "\n" ); - mLogFile.flush(); + try + { + mLogFile.flush(); + mLogFile.close(); + mLogFile = null; + } + catch(Exception e) + { + mLog.error("Couldn't close log file:" + mFileNameSuffix); + } } - catch ( IOException e ) + } + + protected void write(String eventLogEntry) + { + try { - mLog.error( "Error writing entry to event log file", e ); + mLogFile.write(eventLogEntry + "\n"); + mLogFile.flush(); + } + catch(IOException e) + { + mLog.error("Error writing entry to event log file", e); } } }