IGNITE-1182 control-center-agent: user should be able to specify loggin configuration.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4ea5f07f Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4ea5f07f Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4ea5f07f Branch: refs/heads/ignite-843 Commit: 4ea5f07f330b9d68a93619c83196450644a025b2 Parents: c958a11 Author: sevdokimov <sevdoki...@gridgain.com> Authored: Fri Jul 31 16:57:54 2015 +0300 Committer: sevdokimov <sevdoki...@gridgain.com> Committed: Fri Jul 31 16:57:54 2015 +0300 ---------------------------------------------------------------------- .../org/apache/ignite/agent/AgentLauncher.java | 7 +- .../ignite/agent/LoggingConfigurator.java | 89 ++++++++++++++++++++ 2 files changed, 90 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ea5f07f/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java index 141652e..5404448 100644 --- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java @@ -31,12 +31,7 @@ import java.util.logging.*; public class AgentLauncher { /** Static initializer. */ static { - try { - LogManager.getLogManager().readConfiguration(AgentLauncher.class.getResourceAsStream("/logging.properties")); - } - catch (IOException e) { - throw new RuntimeException(e); - } + LoggingConfigurator.configure(); } /** */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ea5f07f/modules/control-center-agent/src/main/java/org/apache/ignite/agent/LoggingConfigurator.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/LoggingConfigurator.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/LoggingConfigurator.java new file mode 100644 index 0000000..93cc8a9 --- /dev/null +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/LoggingConfigurator.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.ignite.agent; + +import java.io.*; +import java.net.*; +import java.util.logging.*; + +/** + * Configurator for java.util.Logger. + */ +public class LoggingConfigurator { + /** + * Perform configure. + */ + public static void configure() { + try { + if (System.getProperty("log.config.path") != null) { + File logCfg = new File(System.getProperty("log.config.path")); + + if (!logCfg.isFile()) { + System.err.println("Failed to load loggin configuration, file not found: " + logCfg); + + System.exit(1); + } + + readConfiguration(logCfg); + + return; + } + + URL jarLogCfgUrl = AgentLauncher.class.getResource("/logging.properties"); + + String path = jarLogCfgUrl.getFile(); + + int jarSeparatorIdx = path.lastIndexOf("!/"); + + if (jarSeparatorIdx != -1) { + path = path.substring(0, jarSeparatorIdx); + + if (path.startsWith("file:")) + path = path.substring("file:".length()); + + File jarFile = new File(path); + + File logCfg = new File(jarFile.getParentFile(), "logging.properties"); + + if (logCfg.isFile()) { + readConfiguration(logCfg); + + return; + } + } + + LogManager.getLogManager().readConfiguration(AgentLauncher.class.getResourceAsStream("/logging.properties")); + } + catch (IOException e) { + System.err.println("Failed to load loggin configuration"); + + e.printStackTrace(); + + System.exit(1); + } + } + + /** + * @param file File. + */ + private static void readConfiguration(File file) throws IOException { + try (InputStream in = new BufferedInputStream(new FileInputStream(file))) { + LogManager.getLogManager().readConfiguration(in); + } + } +}