jAER project on SourceForge

net.sf.jaer.util
Class TobiLogger

java.lang.Object
  extended by net.sf.jaer.util.TobiLogger

public class TobiLogger
extends java.lang.Object

Eases writing log files for any purpose. To use it, construct a new instance, then enable it to open the file and enable the subsequent logging calls to write. Enabling logging automatically opens the file. The logging files are created in the startup directory, e.g. in jAER, in the folder host/java. Each log call prepends the system time automatically as the first field.

Author:
tobi

Field Summary
protected  java.io.PrintStream logStream
           
 
Constructor Summary
TobiLogger(java.lang.String filename, java.lang.String headerLineComment)
          Creates a new instance of TobiLogger.
 
Method Summary
 boolean isAbsoluteTimeEnabled()
           
 boolean isEnabled()
           
 boolean isNanotimeEnabled()
           
 void log(java.lang.String s)
          Logs a string to the file (\n is appended), if logging is enabled.
 void setAbsoluteTimeEnabled(boolean absoluteTimeEnabled)
          If true, then absolute time (since 1970) in ms is first item in line, otherwise, time since file creation is logged.
 void setEnabled(boolean logDataEnabled)
          Enables or disables logging; default is disabled.
 void setNanotimeEnabled(boolean nanotimeEnabled)
          Sets whether to use System.nanotime() or the (default) System.currentTimeMillis()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logStream

protected java.io.PrintStream logStream
Constructor Detail

TobiLogger

public TobiLogger(java.lang.String filename,
                  java.lang.String headerLineComment)
Creates a new instance of TobiLogger.

Parameters:
filename - the filename. Date/Timestamp string us appended to the filename and ".txt" is appended if it is not already the suffix, e.g. "PencilBalancer-2008-10-12T10-23-58+0200.txt". The file is created in the program startup folder.
headerLineComment - a comment usuually specifying the contents and data fields, a # is prepended automatically. A second header line is also written automatically with the file creation date, e.g. "# created Sat Oct 11 13:04:34 CEST 2008"
Method Detail

log

public void log(java.lang.String s)
Logs a string to the file (\n is appended), if logging is enabled. Prepends the relative or absolute time in ms or nanoseconds, depending on nanotimeEnabled, comma separated from the rest of the string.

Parameters:
s - the string
See Also:
setEnabled(boolean)

isEnabled

public boolean isEnabled()

setEnabled

public void setEnabled(boolean logDataEnabled)
Enables or disables logging; default is disabled. Each time logging is enabled a new log file is created with its own timetamped filename. Each time logging is disabled the existing log file is closed. Reenabling logging opens a new logging file.

Parameters:
logDataEnabled - true to enable logging

isAbsoluteTimeEnabled

public boolean isAbsoluteTimeEnabled()

setAbsoluteTimeEnabled

public void setAbsoluteTimeEnabled(boolean absoluteTimeEnabled)
If true, then absolute time (since 1970) in ms is first item in line, otherwise, time since file creation is logged. This facility eases use in matlab which doesn't like to deal with these large integers, preferring to round them off to doubles that resolve the actual time differences of interest to 0.

Parameters:
absoluteTimeEnabled - default false

isNanotimeEnabled

public boolean isNanotimeEnabled()

setNanotimeEnabled

public void setNanotimeEnabled(boolean nanotimeEnabled)
Sets whether to use System.nanotime() or the (default) System.currentTimeMillis()

Parameters:
nanotimeEnabled - true to use nanotime

jAER project on SourceForge