X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fkernel%2FNodeLogger.java;h=fef7a7a30a0e4b308cdca33a374fac8f57e6d849;hb=3c7803ca05e2b0276d635e64046d924d3f1884c9;hp=947d4d89e6e90a0199cb8dd1ea84bfaceeaf0bf1;hpb=09d97fb1d28c9bbe4b2ec9fc511adf5127a256c1;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java index 947d4d89e..fef7a7a30 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java @@ -1,18 +1,3 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.argeo.cms.internal.kernel; import java.io.IOException; @@ -46,11 +31,11 @@ import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.spi.LoggingEvent; +import org.argeo.api.ArgeoLogListener; +import org.argeo.api.ArgeoLogger; +import org.argeo.api.NodeConstants; import org.argeo.cms.CmsException; import org.argeo.cms.auth.CurrentUser; -import org.argeo.node.ArgeoLogListener; -import org.argeo.node.ArgeoLogger; -import org.argeo.node.NodeConstants; import org.argeo.osgi.useradmin.UserAdminConf; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; @@ -101,30 +86,32 @@ class NodeLogger implements ArgeoLogger, LogListener { }; public NodeLogger(LogReaderService lrs) { - Enumeration logEntries = lrs.getLog(); - while (logEntries.hasMoreElements()) - logged(logEntries.nextElement()); - lrs.addLogListener(this); - - // configure log4j watcher - String log4jConfiguration = KernelUtils.getFrameworkProp("log4j.configuration"); - if (log4jConfiguration != null && log4jConfiguration.startsWith("file:")) { - if (log4jConfiguration.contains("..")) { - if (log4jConfiguration.startsWith("file://")) - log4jConfiguration = log4jConfiguration.substring("file://".length()); - else if (log4jConfiguration.startsWith("file:")) - log4jConfiguration = log4jConfiguration.substring("file:".length()); - } - try { - Path log4jconfigPath; - if (log4jConfiguration.startsWith("file:")) - log4jconfigPath = Paths.get(new URI(log4jConfiguration)); - else - log4jconfigPath = Paths.get(log4jConfiguration); - Thread log4jConfWatcher = new Log4jConfWatcherThread(log4jconfigPath); - log4jConfWatcher.start(); - } catch (Exception e) { - stdErr("Badly formatted log4j configuration URI " + log4jConfiguration + ": " + e.getMessage()); + if (lrs != null) { + Enumeration logEntries = lrs.getLog(); + while (logEntries.hasMoreElements()) + logged(logEntries.nextElement()); + lrs.addLogListener(this); + + // configure log4j watcher + String log4jConfiguration = KernelUtils.getFrameworkProp("log4j.configuration"); + if (log4jConfiguration != null && log4jConfiguration.startsWith("file:")) { + if (log4jConfiguration.contains("..")) { + if (log4jConfiguration.startsWith("file://")) + log4jConfiguration = log4jConfiguration.substring("file://".length()); + else if (log4jConfiguration.startsWith("file:")) + log4jConfiguration = log4jConfiguration.substring("file:".length()); + } + try { + Path log4jconfigPath; + if (log4jConfiguration.startsWith("file:")) + log4jconfigPath = Paths.get(new URI(log4jConfiguration)); + else + log4jconfigPath = Paths.get(log4jConfiguration); + Thread log4jConfWatcher = new Log4jConfWatcherThread(log4jconfigPath); + log4jConfWatcher.start(); + } catch (Exception e) { + stdErr("Badly formatted log4j configuration URI " + log4jConfiguration + ": " + e.getMessage()); + } } } }