blob: b0a3538888c7a9dc17565c7f7895ad0e278d44be [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Andras Schmidt, Andras Balogh, Istvan Rath and Daniel Varro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andras Schmidt, Andras Balogh, Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.logger;
/**
* @author Istvan Rath
*
*/
import java.io.FileOutputStream;
import java.io.PrintStream;
import org.eclipse.viatra2.framework.properties.VPMProperties;
public class SimpleLogger implements Logger {
PrintStream out;
public SimpleLogger() {
out = System.out;
}
int level = 100;
public void setLevel(int l) {
level = l;
}
public void warning(String s) {
message(Logger.WARNING, s);
}
public void error(String s) {
message(Logger.ERROR, s);
}
public void debug(String s) {
message(Logger.DEBUG, s);
}
public void fatal(String s) {
message(Logger.FATAL, s);
}
public void info(String s) {
message(Logger.INFO, s);
}
public void init(VPMProperties props) {
try {
String outs = props.getRuntimeProperty("log", "output");
if ( outs == null || outs.equals("screen") || outs.equals("") )
out = System.out;
else
out = new PrintStream(new FileOutputStream(outs));
} catch (Exception ex) {
System.out.println("Couldn't initialize logger.");
System.out.println("Stopping VPM session.");
System.exit(1);
}
}
public void message(int level, String msg, Throwable cause) {
if (this.level >= level) {
out.println("[" + Logger.levelnames[level] + "] " + msg);
if (cause != null) {
out.println("[" + Logger.levelnames[level]
+ "] Exception stack trace follows:");
cause.printStackTrace();
}
}
}
public void message(int level, String msg) {
message(level, msg, null);
}
public void printStackTrace(Throwable t) {
System.out.println("[exception track trace]");
t.printStackTrace();
}
}