blob: de219477601a05893b5f8bd0d04bcc9032d83702 [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;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.viatra2.framework.properties.VPMProperties;
/**
* @author Andras Balogh
*
* Viatra 2 Framework
*
* This logger implementation support the Eclipse integration, and a
* native Viatra logger at the same time. The error, warning and info
* messages are also logged to the Eclipse log, and all messages are
* logged to the native logger according to the log level settings.
*/
public class EclipseLogger implements Logger {
public EclipseLogger(ILog eclipse_log) {
elog = eclipse_log;
}
ILog elog;
public void setLevel(int 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 p) {
}
public void message(int level, String msg, Throwable cause) {
int eclLevel = 0;
switch (level) {
case Logger.WARNING:
eclLevel = Status.WARNING;
//break; // warnings should be checked in the console
return;
case Logger.DEBUG:
return;
case Logger.ERROR:
eclLevel = Status.ERROR;
break;
case Logger.INFO:
eclLevel = Status.INFO;
// break;
return;
case Logger.FATAL:
eclLevel = Status.ERROR;
break;
}
IStatus ss = new Status(eclLevel, "VIATRA2", 1, msg, cause);
elog.log(ss);
}
public void message(int level, String msg) {
message(level, msg, null);
}
public void printStackTrace(Throwable t) {
elog.log(new Status(Status.ERROR, "VIATRA2", 1, "VIATRA2 exception stack trace", t));
}
}