1 package org.simantics.logging;
3 import java.lang.reflect.Field;
5 import java.nio.file.Path;
6 import java.nio.file.Paths;
7 import java.util.ArrayList;
10 import org.eclipse.core.runtime.Platform;
11 import org.osgi.framework.Bundle;
12 import org.slf4j.LoggerFactory;
14 public class DBAndMetadataLogProvider implements LogProvider {
16 private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DBAndMetadataLogProvider.class);
19 public List<Path> get() {
20 List<Path> logs = new ArrayList<>();
21 Path dbClientLog = getDBClientLogLocation();
22 if (dbClientLog != null)
23 logs.add(dbClientLog);
24 Path metadataLogLocation = getMetadataLogLocation();
25 if (metadataLogLocation != null)
26 logs.add(metadataLogLocation);
30 private static Path getDBClientLogLocation() {
31 Bundle bundle = Platform.getBundle("org.simantics.db.common");
33 Class<?> forName = bundle.loadClass("org.simantics.db.common.internal.config.InternalClientConfig");
34 Field field = forName.getField("DB_CLIENT_LOG_FILE");
35 String value = (String) field.get(null);
36 return Paths.get(value);
37 } catch (ClassNotFoundException | NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
38 LOGGER.error("Could not read db-client.log location", e);
43 private static Path getMetadataLogLocation() {
44 String prop = System.getProperty("osgi.instance.area", null);
47 URL url = new URL(prop);
48 if ("file".equals(url .getProtocol())) {
49 Path path = Paths.get(url.toURI());
50 return path.resolve(".metadata").resolve(".log");
52 LOGGER.warn("Unsupported protocol {}", url);
54 } catch (Throwable t) {
55 LOGGER.error("Could not get .metadata/.log", t);