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