import org.simantics.db.AsyncReadGraph;
import org.simantics.db.ReadGraph;
import org.simantics.db.common.request.ReadRequest;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncListener;
import org.simantics.db.procedure.Procedure;
import org.simantics.db.procedure.SyncListener;
+import org.slf4j.LoggerFactory;
final public class SyncToAsyncListener<T> implements AsyncListener<T> {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(SyncToAsyncListener.class);
+
final private SyncListener<T> procedure;
public SyncToAsyncListener(SyncListener<T> procedure) {
@Override
public void exception(Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("{} failed", SyncToAsyncListener.this.toString(), t);
}
@Override
/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2010, 2018 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - Deprecating and replace with SLF4J Logger
*******************************************************************************/
package org.simantics.db.common.utils;
-import java.util.Properties;
-
-import org.apache.log4j.Level;
-import org.simantics.databoard.Bindings;
-import org.simantics.db.DevelopmentKeys;
-import org.simantics.db.common.internal.config.InternalClientConfig;
-import org.simantics.utils.Development;
+import org.slf4j.LoggerFactory;
+@Deprecated
public class Logger {
- public static final boolean ENABLED = true;
- //public static final boolean ECHO = Development.DEVELOPMENT || false;
- public static final Properties defaultProperties = new Properties();
- static {
- defaultProperties.put("log4j.rootCategory", "ERROR, default");
- defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");
- defaultProperties.put("log4j.appender.default.File", InternalClientConfig.DB_CLIENT_LOG_FILE);
- defaultProperties.put("log4j.appender.default.append", "true");
- defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");
- defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%d{ISO8601} %-6r [%15.15t] %-5p %30.30c - %m%n");
- }
- private static LogManager defaultLogManager = new LogManager(defaultProperties);
- private static final Logger defaultErrorLogger = new Logger(LogManager.class);
- private org.apache.log4j.Logger logger;
- Logger(Class<?> clazz) {
- logger = defaultLogManager.getLogger(clazz);
- }
-
- /**
- * Log a trace event.
- *
- * @param message message of the trace
- * @param exception the exception, or <code>null</code>
- */
- public void logTrace(String message, Throwable exception) {
-
- if(!logger.isTraceEnabled()) return;
-
- // Errors are much more useful with a stack trace!
- if (exception == null) {
- exception = new RuntimeException();
- }
- logger.trace(message, exception);
-
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {
- System.err.println("Logger.logTrace: " + message);
- }
- }
-
- }
-
- /**
- * Log an info event.
- *
- * @param message message of the info
- * @param exception the exception, or <code>null</code>
- */
- public void logInfo(String message, Throwable exception) {
-
- if(!logger.isInfoEnabled()) return;
-
- // Errors are much more useful with a stack trace!
- if (exception == null) {
- exception = new RuntimeException();
- }
- logger.info(message, exception);
-
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {
- System.err.println("Logger.logInfo: " + message);
- }
- }
-
- }
-
- /**
- * Log an error event.
- *
- * @param message message of the error
- * @param exception the exception, or <code>null</code>
- */
- public void logError(String message, Throwable exception) {
-
- if(!logger.isEnabledFor(Level.ERROR)) return;
- // Errors are much more useful with a stack trace!
- if (exception == null) {
- exception = new RuntimeException();
- }
- logger.error(message, exception);
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Logger.class);
+ private static final String TODO_REPLACE_RIGHT_LOGGER = "[TODO: Replace with right logger instance]";
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {
- System.err.println("Logger.logError: " + message);
- }
- }
-
- }
-
- /**
- * Log an error event.
- *
- * @param message message of the error
- * @param exception the exception, or <code>null</code>
- */
- public void logWarning(String message, Throwable exception) {
-
- if(!logger.isEnabledFor(Level.WARN)) return;
-
- // Errors are much more useful with a stack trace!
- if (exception == null) {
- exception = new RuntimeException();
- }
- logger.error(message, exception);
-
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {
- System.err.println("Logger.logWarning: " + message);
- }
- }
-
- }
-
- /**
- * Log message.
- *
- * @param message to log.
- */
- public void logMessage(String message) {
- Level level = logger.getLevel();
- boolean toggle = !logger.isInfoEnabled();
- if (toggle)
- logger.setLevel((Level)Level.INFO);
- logger.info(message);
- if (toggle)
- logger.setLevel(level);
- if (Development.DEVELOPMENT) {
- if(Development.<Boolean>getProperty(DevelopmentKeys.LOGGER_ECHO, Bindings.BOOLEAN)) {
- System.err.println("Logger.logMessage: " + message);
- }
- }
- }
-
- public static Logger getDefault() {
- return defaultErrorLogger;
- }
-
- public static LogManager getDefaultLogManager() {
- return defaultLogManager;
- }
public static void defaultLogError(Throwable exception) {
- if(!ENABLED) return;
- getDefault().logError(exception.getLocalizedMessage(), exception);
+ LOGGER.error(TODO_REPLACE_RIGHT_LOGGER, exception);
}
public static void defaultLogError(String message) {
- if(!ENABLED) return;
- getDefault().logError(message, null);
+ LOGGER.error("{} {}", TODO_REPLACE_RIGHT_LOGGER, message);
}
public static void defaultLogError(String message, Throwable exception) {
- if(!ENABLED) return;
- getDefault().logError(message, exception);
+ LOGGER.error("{} {}", TODO_REPLACE_RIGHT_LOGGER, message, exception);
}
public static void defaultLogInfo(String message) {
- if(!ENABLED) return;
- getDefault().logInfo(message, null);
- }
- public static void defaultLogTrace(String message) {
- if(!ENABLED) return;
- getDefault().logTrace(message, null);
- }
- public static void defaultLog(String message) {
- if(!ENABLED) return;
- getDefault().logMessage(message);
+ LOGGER.info("{} {}", TODO_REPLACE_RIGHT_LOGGER, message);
}
}
s += clazz.getSimpleName() + " called.\n";
if (null != message)
s += message;
- Logger.defaultLogTrace(s);
+ Logger.defaultLogInfo(s);
}
private static String NL = System.getProperty("line.separator");
static class Choice {
}
private ResourceImpl getBuiltinResource(String name)
throws DatabaseException {
- Logger.defaultLogTrace("Asking for builtin " + name);
synchronized (this) {
if (null == builtinMap) {
ClusterSupport cs = session.getService(ClusterSupport.class);
synchronized (this) {
builtin = builtinMap.get(name);
if (null == builtin) {
- Logger.defaultLogInfo("Asking for missing builtin " + name);
return null;
}
if (null != builtin.weakResource) {
import org.simantics.db.Database.Session.ClusterChanges;
import org.simantics.db.DevelopmentKeys;
import org.simantics.db.SessionVariables;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.ClusterDoesNotExistException;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.ResourceNotFoundException;
import org.simantics.db.service.ClusterCollectorPolicy.CollectorCluster;
import org.simantics.db.service.ClusterUID;
import org.simantics.utils.Development;
+import org.slf4j.LoggerFactory;
import fi.vtt.simantics.procore.DebugPolicy;
import fi.vtt.simantics.procore.internal.ClusterControlImpl.ClusterStateImpl;
public final class ClusterTable implements IClusterTable {
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ClusterTable.class);
+
private static final boolean VALIDATE_SIZE = false;
int maximumBytes = 128 * 1024 * 1024;
ClusterImpl cluster = ClusterImpl.make(clusterUID, clusterKey, sessionImpl.clusterTranslator);
clusters.create(cluster);
if (!cluster.isLoaded())
- Logger.defaultLogError(new Exception("Bug in ClusterTable.makeCluster(long, boolean), cluster not loaded"));
+ LOGGER.error("", new Exception("Bug in ClusterTable.makeCluster(long, boolean), cluster not loaded"));
importanceMap.put(cluster.getImportance(), new ImportanceEntry(cluster));
if (VALIDATE_SIZE)
validateSize("makeCluster");
clusters.replace((ClusterImpl)cluster);
if (!cluster.isLoaded())
- Logger.defaultLogError(new Exception("Bug in ClusterTable.replaceCluster(ClusterI), cluster not loaded"));
+ LOGGER.error("", new Exception("Bug in ClusterTable.replaceCluster(ClusterI), cluster not loaded"));
importanceMap.put(cluster.getImportance(), new ImportanceEntry((ClusterImpl)cluster));
if(collectorPolicy != null) collectorPolicy.added((ClusterImpl)cluster);
result += cluster.getCachedSize();
}
} catch (Throwable t) {
- Logger.defaultLogError(t);
+ LOGGER.error("Could not calculate size", t);
}
}
return true;
final long getClusterIdByResourceKeyNoThrow(final int resourceKey) {
int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(resourceKey);
if (ClusterTraitsBase.isVirtualClusterKey(clusterKey)) {
- Logger.defaultLogError("Tried to get a persistent cluster for a virtual resource. key=" + resourceKey);
+ LOGGER.error("Tried to get a persistent cluster for a virtual resource. key=" + resourceKey);
return 0;
}
ClusterI c = clusterArray[clusterKey];
if (c == null) {
- Logger.defaultLogError("No cluster for key " + resourceKey);
+ LOGGER.error("No cluster for key " + resourceKey);
return 0;
}
return c.getClusterId();
collectorPolicy.removed(oldCluster);
clusters.replace(newCluster);
if (!newCluster.isLoaded())
- Logger.defaultLogError(new Exception("Bug in ClusterTable.refresh, cluster not loaded"));
+ LOGGER.error("", new Exception("Bug in ClusterTable.refresh, cluster not loaded"));
importanceMap.put(newCluster.getImportance(), new ImportanceEntry(newCluster));
if (collectorPolicy != null)
collectorPolicy.added(newCluster);
// Now we have fetched the new cluster but to emulate effects of the changes in it we fetch the cluster changes from server.
refreshCluster(csid, session, oldCluster, clusterUID[i], newCluster.clusterId, clusterKey);
} catch (Throwable t) {
- Logger.defaultLogError("Failed to load cluster in refresh.", t);
+ LOGGER.error("Failed to load cluster in refresh.", t);
}
}
if (VALIDATE_SIZE)
try {
cc = session.graphSession.getClusterChanges(clusterUID, csid);
} catch (Exception e) {
- Logger.defaultLogError("Could not get cluster changes. cluster=" + clusterUID, e);
+ LOGGER.error("Could not get cluster changes. cluster=" + clusterUID, e);
release(clusterId);
return;
}
// System.err.println("refreshImportance " + c.getClusterId() + " => " + newImportance);
c.setImportance(newImportance);
if (!c.isLoaded())
- Logger.defaultLogError(new Exception("Bug in ClusterTable.refreshImportance(ClusterImpl), cluster not loaded"));
+ LOGGER.error("", new Exception("Bug in ClusterTable.refreshImportance(ClusterImpl), cluster not loaded"));
importanceMap.put(c.getImportance(), new ImportanceEntry(c));
if(collectorPolicy != null) collectorPolicy.added(c);
cluster = load2(cs.getClusterId(), cs.getClusterKey());
}
} catch (DatabaseException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("Could not load cluster", e);
if (DebugPolicy.REPORT_CLUSTER_EVENTS)
e.printStackTrace();
String msg = "Failed to load cluster " + cs.getClusterUID();// + " resourceId=" + (((cs.getClusterId() << 16 + (resourceKey & 65535))));
return (T) c;
}
if (!(c instanceof ClusterSmall)) {
- Logger.defaultLogError("Proxy must be instance of ClusterSmall");
+ LOGGER.error("Proxy must be instance of ClusterSmall");
return null;
}
return ensureLoaded((T)c);
return (T) c;
}
if (!(c instanceof ClusterSmall)) {
- Logger.defaultLogError("Proxy must be instance of ClusterSmall");
+ LOGGER.error("Proxy must be instance of ClusterSmall");
return null;
}
ClusterI cluster;
int resourceIndex = resourceKey & ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(resourceKey);
long resourceId = ClusterTraitsBase.createResourceIdNoThrow(cs.getClusterId(), resourceIndex);
String msg = "Failed to load cluster " + cs.getClusterUID() + " for resource key " + resourceKey + " resourceIndex=" + resourceIndex + " resourceId=" + resourceId;
- Logger.defaultLogError(msg, e);
+ LOGGER.error(msg, e);
c.setDeleted(true, null);
return (T)c;
}
try {
s.acquire();
} catch (InterruptedException e) {
- Logger.defaultLogError(e);
+ LOGGER.error("unable to acquire", e);
}
if (null != ex[0])
throw ex[0];
} catch (Throwable t) {
// It's totally legal to call for non-existing cluster.
// Sometimes this indicates an error, though.
- Logger.getDefault().logInfo("Load cluster failed.", t);
+ LOGGER.error("Load cluster failed", t);
if (t instanceof DatabaseException)
e = (DatabaseException) t;
else
@Override
public long reserveIds(int count)
throws DatabaseException {
- Logger.defaultLogTrace("Asking for ids " + count + ".");
long firstId = dbSession.reserveIds(count);
- Logger.defaultLogTrace("First id is " + firstId + ".");
if (DebugPolicy.REPORT_CLUSTER_ID_ALLOCATION)
System.out.println("Client reserves new ids [" + firstId + " - " + (firstId+count-1) + "] from server.");
return firstId;
import java.util.ArrayList;
import org.simantics.db.Resource;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.ExternalValueException;
import org.simantics.db.exception.ValidationException;
import org.simantics.db.impl.TableFactory;
import org.simantics.db.impl.TableSizeListener;
import org.simantics.db.impl.graph.ReadGraphImpl;
-import org.simantics.db.procedure.AsyncContextMultiProcedure;
import org.simantics.db.procedure.SyncContextMultiProcedure;
import org.simantics.db.procedure.SyncMultiProcedure;
import org.simantics.db.procore.cluster.PredicateTable.Status;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
final class ResourceElement {
class CalculateStatements
implements ClusterI.PredicateProcedure<CalculateStatements> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CalculateStatements.class);
private ObjectTable ot;
private final int sRef;
try {
oIndex = ClusterTraits.statementIndexGet(oIndex);
} catch (DatabaseException e) {
- Logger.getDefault().logError("Missing object set for s="
- + sRef + " p=" + pKey, null);
+ LOGGER.error("Missing object set for s="
+ + sRef + " p=" + pKey, e);
return false; // continue looping
}
int osize = ot.getObjectSetSize(oIndex);
import java.util.ArrayList;
import org.simantics.db.Resource;
-import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.ClusterBase;
import org.simantics.db.impl.ClusterI;
import org.simantics.db.procedure.SyncContextMultiProcedure;
import org.simantics.db.procedure.SyncMultiProcedure;
import org.simantics.db.procore.cluster.PredicateTable.Status;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
class CalculateStatementsSmall
implements ClusterI.PredicateProcedure<CalculateStatements> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CalculateStatementsSmall.class);
+
private ObjectTable ot;
private final int sRef;
try {
oIndex = ClusterTraits.statementIndexGet(oIndex);
} catch (DatabaseException e) {
- Logger.getDefault().logError("Missing object set for s="
- + sRef + " p=" + pKey, null);
+ LOGGER.error("Missing object set for s="
+ + sRef + " p=" + pKey, e);
return false; // continue looping
}
int osize = ot.getObjectSetSize(oIndex);
Bundle-ActivationPolicy: lazy
Require-Bundle: org.simantics.databoard,
org.simantics.db,
- org.simantics.fastlz
+ org.simantics.fastlz,
+ org.slf4j.api
Eclipse-BundleShape: dir
// System.err.println("############### YIELD ##############################");
Thread.yield();
if (left > 0)
- Logger.defaultLogTrace("Could not send the whole byte buffer, left count = " + left + ", buffer remaining = " + byteBuffer.remaining()
+ Logger.defaultLogInfo("Could not send the whole byte buffer, left count = " + left + ", buffer remaining = " + byteBuffer.remaining()
+ ", write return =" + n);
}
}
import org.simantics.db.server.internal.ProCoreServer.TailFile;
import org.simantics.db.server.protocol.MessageNumber;
import org.simantics.db.server.protocol.MessageText;
+import org.slf4j.LoggerFactory;
public class DatabaseI implements Database {
+
+ private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DatabaseI.class);
+
private static String NL = System.getProperty("line.separator");
private static String TEMP_PREFIX = "db.temp.";
public static DatabaseI newDatabaseI(File dbFolder) {
}
long nextFreeId = getNextClusterId(db);
boolean cleanHead = Files.isDirectory(dbHead) && !isFolderEmpty(dbHead);
- Logger.defaultLog("Purging old history and exit information. folder=" + db);
+ LOGGER.info("Purging old history and exit information. folder=" + db);
if (cleanHead) {
deleteClusters(dbHead, dbTail);
movePath(dbHead, dbTail, ProCoreServer.TAIL_FILE, FileOption.OVERWRITE);
import org.simantics.db.server.protocol.CloseClientSessionFunction;
import org.simantics.db.server.protocol.ExecuteFunction;
import org.simantics.db.server.protocol.MessageNumber;
+import org.slf4j.LoggerFactory;
public class ProCoreServer {
private static Map<String, ProCoreServer> workingDirs = new HashMap<String, ProCoreServer>();
msg.append(nl);
msg.append("svn id=$Id: ProCoreServer.java r31684 2015-09-10 13:45:00Z $");
String str = msg.toString();
- Logger.defaultLog(str);
+ LoggerFactory.getLogger(ProCoreServer.class).info(str);
}
private static String[] getFileLines(final File aFile, int maxLines) {
final String[] STRING_EMPTY_ARRAY = new String[0];
s += clazz.getSimpleName() + " called.\n";
if (null != message)
s += message;
- Logger.defaultLogTrace(s);
+ Logger.defaultLogInfo(s);
}
public static void log(String message) {
- Logger.defaultLog(message);
+ Logger.defaultLogInfo(message);
}
public static void showDebug(String message) {
String t = "DEBUG: " + message;