errors..........
c:\Users\rgmat\Desktop>javac logger.java
location: class Logger.IConsole
logger.java:113: error: non-static variable this cannot be referenced from a static context
Logger l = new Logger(new IConsole(), logFile, false, false, false);
^
logger.java:113: error: non-static variable logFile cannot be referenced from a static context
Logger l = new Logger(new IConsole(), logFile, false, false, false);
^
2 errors
*********************************************
current code
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Vector;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.io.*;
class Logger {
private IConsole console = null;
private String logFile = "C:/Users/Bob/Documents/BM_mod14.log";
private boolean info = true;
private boolean error = true;
private boolean debug = true;
public Logger(IConsole cons, String lf, boolean inf, boolean err, boolean dbg) {
console = cons;
logFile = lf;
info = inf;
error = err;
debug = dbg;
if (!"".equals(lf)) new File(logFile).delete();
}
// add code to call some of the logger class's methods
class IConsole { // ADDED <<<<<<<<
PrintStream getOut() {
return System.out;
}
}
public void info(String Data) {
if (info) {
Data = "INFO : " + Data;
Log(Data);
}
}
public void error(String Data) {
if (error) {
Data = "ERROR : " + Data;
Log(Data);
}
}
public void debug(String Data) {
if (debug) {
Data = "DEBUG : " + Data;
Log(Data);
}
}
private void Log(String Data) {
try {
if (console != null) console.getOut().println(Data);
LogToFile(Data);
} catch (Exception e) {
}
}
private void LogToFile(String Data) {
try {
if ("".equals(Data)) return;
if ("".equals(logFile)) return;
File file = new File(logFile);
FileOutputStream fos = new FileOutputStream(file, true);
OutputStreamWriter osw = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
BufferedWriter bw = new BufferedWriter(osw);
try {
bw.write(Data + "\n");
} finally {
try {
bw.flush();
bw.close();
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
try {
osw.flush();
osw.close();
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
try {
fos.flush();
fos.close();
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
} // end LogToFile
public static void main(String[] args) {
// add code here to declare an instance of the logger class
Logger l = new Logger(new IConsole(), logFile, false, false, false);
l.Log("This is a test 2");
// add code to call some of the logger class's methods
} // end main
} // end of class Logger
Answers:-
"Can you give me some history of where the Logger class came from?"
It is a small part of a rather large strategy I have a copy of - dates from Jan 2010
"Did it ever work?"
I can not tell
"Can you contact the author for a fix?"
No
The IConsole class comes from the Dukascopy API