You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ie...@apache.org on 2020/06/17 19:55:26 UTC

[james-project] branch master updated: JAMES-3221 #comment Improved logging around configuration files for devops

This is an automated email from the ASF dual-hosted git repository.

ieugen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new b90d05e  JAMES-3221 #comment Improved logging around configuration files for devops
b90d05e is described below

commit b90d05ee7cdd68bb16bb60e6bda1943ba6a89d81
Author: Eugen Stan <ie...@apache.org>
AuthorDate: Tue Jun 16 12:25:18 2020 +0300

    JAMES-3221 #comment Improved logging around configuration files for devops
    
    * When loading a configuration file, print it's absolute
    * Usefull for debugging production miss-configurations
    * Added documentation
---
 docs/modules/development/pages/logging.adoc        | 43 ++++++++++++++++++++++
 .../server/core/JamesServerResourceLoader.java     | 10 +++++
 .../server/core/configuration/Configuration.java   |  8 ++++
 .../org/apache/james/CassandraJamesServerMain.java |  1 +
 .../apache/james/CassandraLdapJamesServerMain.java |  1 +
 .../james/CassandraRabbitMQJamesServerMain.java    |  1 +
 .../CassandraRabbitMQLdapJamesServerMain.java      |  1 +
 .../org/apache/james/utils/PropertiesProvider.java |  7 +++-
 .../java/org/apache/james/JamesServerMain.java     |  6 +++
 .../java/org/apache/james/JPAJamesServerMain.java  |  1 +
 .../java/org/apache/james/JPAJamesServerMain.java  |  1 +
 .../org/apache/james/MemoryJamesServerMain.java    |  2 +-
 12 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/docs/modules/development/pages/logging.adoc b/docs/modules/development/pages/logging.adoc
new file mode 100644
index 0000000..c6c3353
--- /dev/null
+++ b/docs/modules/development/pages/logging.adoc
@@ -0,0 +1,43 @@
+= Logging in Apache James
+
+NOTE: This information targets developers.
+
+Logging is very important when running a software.
+Most of the time people use logs for debugging and troubleshooting issues in production.
+In Apache James we leverage a logging facade for logging http://www.slf4j.org/[Slf4j] .
+Please see the documentation for exact details.
+
+In a typical application logs are stored for a specific period.
+This can be 1 day, 1 week, etc.
+
+Some other typical scenarios include:
+
+* Rotating logs periodically.
+* Shipping logs centrally.
+* Saving some logging messages to other files / end devices
+
+By leveraging a logging facade like Slf4j, the end user has the ability to use different logging back ends and achieve the above requirements.
+
+Logging is something we do to help the people running our code.
+We also help ourselves when they encounter bugs, and they need to share information with us for a fix.
+As developers, we should be mindful of the logging statements.
+We should also be mindful about the performance implications of logging and not abuse it.
+
+== Loggers used in code
+
+You can define a logger using a string or a class.
+For common loggers it's ok to use a string name.
+
+[source,java]
+--
+    private static final Logger LOGGER = LoggerFactory.getLogger("org.apache.james.CONFIGURATION");
+    private static final Logger LOGGER = LoggerFactory.getLogger(JamesServerMain.class);
+--
+
+Loggers can be hierarchical.
+This helps when we build a logger from a class name, and we use package structure to drive the logger hierarchy.
+
+The most useful loggers should to be documented below.
+Please maintain this list of loggers.
+
+org.apache.james.CONFIGURATION:: It is used to log events related to configuration loading and updating.
\ No newline at end of file
diff --git a/server/container/core/src/main/java/org/apache/james/server/core/JamesServerResourceLoader.java b/server/container/core/src/main/java/org/apache/james/server/core/JamesServerResourceLoader.java
index 2a4c66f..cd4d7a7 100644
--- a/server/container/core/src/main/java/org/apache/james/server/core/JamesServerResourceLoader.java
+++ b/server/container/core/src/main/java/org/apache/james/server/core/JamesServerResourceLoader.java
@@ -20,6 +20,8 @@ package org.apache.james.server.core;
 
 import org.apache.james.filesystem.api.JamesDirectoriesProvider;
 
+import com.google.common.base.MoreObjects;
+
 public class JamesServerResourceLoader implements JamesDirectoriesProvider {
 
     private final String rootDirectory;
@@ -58,4 +60,12 @@ public class JamesServerResourceLoader implements JamesDirectoriesProvider {
         return rootDirectory;
     }
 
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("rootDirectory", rootDirectory)
+            .add("varDirectory", getVarDirectory())
+            .add("confDirectory", getConfDirectory())
+            .toString();
+    }
 }
\ No newline at end of file
diff --git a/server/container/core/src/main/java/org/apache/james/server/core/configuration/Configuration.java b/server/container/core/src/main/java/org/apache/james/server/core/configuration/Configuration.java
index 58baecb..3ced531 100644
--- a/server/container/core/src/main/java/org/apache/james/server/core/configuration/Configuration.java
+++ b/server/container/core/src/main/java/org/apache/james/server/core/configuration/Configuration.java
@@ -134,6 +134,14 @@ public interface Configuration {
         public JamesDirectoriesProvider directories() {
             return directories;
         }
+
+        @Override
+        public String toString() {
+            return MoreObjects.toStringHelper(this)
+                .add("configurationPath", configurationPath)
+                .add("directories", directories)
+                .toString();
+        }
     }
 
     static Basic.Builder builder() {
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index 2c2e189..bef678e 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -171,6 +171,7 @@ public class CassandraJamesServerMain implements JamesServerMain {
             .useWorkingDirectoryEnvProperty()
             .build();
 
+        LOGGER.info("Loading configuration {}", configuration.toString());
         GuiceJamesServer server = createServer(configuration)
             .combineWith(new JMXServerModule());
 
diff --git a/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java b/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java
index a84f51d..ce1c6ac 100644
--- a/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java
+++ b/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java
@@ -37,6 +37,7 @@ public class CassandraLdapJamesServerMain implements JamesServerMain {
             .useWorkingDirectoryEnvProperty()
             .build();
 
+        LOGGER.info("Loading configuration {}", configuration.toString());
         GuiceJamesServer server = createServer(configuration)
             .combineWith(new JMXServerModule());
 
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
index 588ee9b..38a1816 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
@@ -44,6 +44,7 @@ public class CassandraRabbitMQJamesServerMain implements JamesServerMain {
             .useWorkingDirectoryEnvProperty()
             .build();
 
+        LOGGER.info("Loading configuration {}", configuration.toString());
         GuiceJamesServer server = createServer(configuration)
             .combineWith(new JMXServerModule());
 
diff --git a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/main/java/org/apache/james/CassandraRabbitMQLdapJamesServerMain.java b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/main/java/org/apache/james/CassandraRabbitMQLdapJamesServerMain.java
index 7743afa..d91eb1c 100644
--- a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/main/java/org/apache/james/CassandraRabbitMQLdapJamesServerMain.java
+++ b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/main/java/org/apache/james/CassandraRabbitMQLdapJamesServerMain.java
@@ -38,6 +38,7 @@ public class CassandraRabbitMQLdapJamesServerMain implements JamesServerMain {
             .useWorkingDirectoryEnvProperty()
             .build();
 
+        LOGGER.info("Loading configuration {}", configuration.toString());
         GuiceJamesServer server = createServer(configuration)
             .combineWith(new JMXServerModule());
 
diff --git a/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java b/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java
index cefa9d4..831f18d 100644
--- a/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java
+++ b/server/container/guice/configuration/src/main/java/org/apache/james/utils/PropertiesProvider.java
@@ -35,6 +35,8 @@ import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
 import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.server.core.configuration.Configuration.ConfigurationPath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
@@ -42,6 +44,7 @@ import com.google.common.base.Strings;
 
 public class PropertiesProvider {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger("org.apache.james.CONFIGURATION");
     private static final char COMMA = ',';
     private static final String COMMA_STRING = ",";
 
@@ -85,7 +88,9 @@ public class PropertiesProvider {
 
     private Optional<File> getConfigurationFile(String fileName) {
         try {
-            return Optional.of(fileSystem.getFile(configurationPrefix.asString() + fileName + ".properties"))
+            File file = fileSystem.getFile(configurationPrefix.asString() + fileName + ".properties");
+            LOGGER.info("Load configuration file {}", file.getAbsolutePath());
+            return Optional.of(file)
                 .filter(File::exists);
         } catch (FileNotFoundException e) {
             return Optional.empty();
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/JamesServerMain.java b/server/container/guice/guice-common/src/main/java/org/apache/james/JamesServerMain.java
index 534354e..5c01985 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/JamesServerMain.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/JamesServerMain.java
@@ -19,7 +19,13 @@
 
 package org.apache.james;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public interface JamesServerMain {
+
+    Logger LOGGER = LoggerFactory.getLogger("org.apache.james.CONFIGURATION");
+
     static void main(GuiceJamesServer server) throws Exception {
         server.start();
 
diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
index 5895e24..210ee2f 100644
--- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -101,6 +101,7 @@ public class JPAJamesServerMain implements JamesServerMain {
             .useWorkingDirectoryEnvProperty()
             .build();
 
+        LOGGER.info("Loading configuration {}", configuration.toString());
         GuiceJamesServer server = createServer(configuration)
             .combineWith(new JMXServerModule());
 
diff --git a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
index aeef5b6..c65f618 100644
--- a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -64,6 +64,7 @@ public class JPAJamesServerMain implements JamesServerMain {
             .useWorkingDirectoryEnvProperty()
             .build();
 
+        LOGGER.info("Loading configuration {}", configuration.toString());
         GuiceJamesServer server = createServer(configuration);
 
         JamesServerMain.main(server);
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
index d0a30c2..32256c5 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
@@ -138,7 +138,7 @@ public class MemoryJamesServerMain implements JamesServerMain {
             .useWorkingDirectoryEnvProperty()
             .build();
 
-
+        LOGGER.info("Loading configuration {}", configuration.toString());
         GuiceJamesServer server = createServer(configuration)
             .combineWith(new FakeSearchMailboxModule(), new JMXServerModule());
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org