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

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 1ca96bde43 feat(#3721): Add optional file logging (#3722)
1ca96bde43 is described below

commit 1ca96bde433ef61f370be313ac9eeee7374b19df
Author: Dominik Riemer <[email protected]>
AuthorDate: Fri Aug 8 08:44:16 2025 +0200

    feat(#3721): Add optional file logging (#3722)
    
    * feat(#3721): Add optional file logging
    
    * Fix rat
    
    * Fix pattern
---
 pom.xml                                            |  17 ++++
 streampipes-client/pom.xml                         |   5 -
 .../apache/streampipes/commons/constants/Envs.java |  13 ++-
 .../commons/environment/DefaultEnvironment.java    |  25 +++++
 .../commons/environment/Environment.java           |   6 ++
 streampipes-data-explorer-influx/pom.xml           |   6 +-
 streampipes-extensions-management/pom.xml          |   6 ++
 .../streampipes-sinks-databases-jvm/pom.xml        |   8 --
 streampipes-service-base/pom.xml                   |   4 +
 .../base/logging/LogbackRollingFileConfig.java     | 101 +++++++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   |  19 ++++
 streampipes-storage-couchdb/pom.xml                |   6 ++
 streampipes-wrapper-siddhi/pom.xml                 |   4 +
 13 files changed, 201 insertions(+), 19 deletions(-)

diff --git a/pom.xml b/pom.xml
index 5859fe83b8..6e3c575efc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -545,11 +545,23 @@
                 <groupId>org.apache.httpcomponents</groupId>
                 <artifactId>fluent-hc</artifactId>
                 <version>${httpclient.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>commons-logging</groupId>
+                        <artifactId>commons-logging</artifactId>
+                    </exclusion>
+                </exclusions>
             </dependency>
             <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
                 <artifactId>httpclient</artifactId>
                 <version>${httpclient.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>commons-logging</groupId>
+                        <artifactId>commons-logging</artifactId>
+                    </exclusion>
+                </exclusions>
             </dependency>
             <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
@@ -701,6 +713,11 @@
                 <artifactId>spring-boot-starter-jersey</artifactId>
                 <version>${spring-boot.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-logging</artifactId>
+                <version>${spring-boot.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-security</artifactId>
diff --git a/streampipes-client/pom.xml b/streampipes-client/pom.xml
index 9721e65d62..5713a17827 100644
--- a/streampipes-client/pom.xml
+++ b/streampipes-client/pom.xml
@@ -72,11 +72,6 @@
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>fluent-hc</artifactId>
         </dependency>
-
-        <dependency>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
-        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
index 19123ced95..d374030e42 100644
--- 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
+++ 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
@@ -137,7 +137,18 @@ public enum Envs {
 
   // PLC4X connection cache
   SP_PLC4X_CONN_MAX_WAIT_TIME_MS("SP_PLC4X_CONN_MAX_WAIT_TIME_MS", "20000"),
-  SP_PLC4X_CONN_MAX_LEASE_TIME_MS("SP_PLC4X_CONN_MAX_LEASE_TIME_MS", "4000");
+  SP_PLC4X_CONN_MAX_LEASE_TIME_MS("SP_PLC4X_CONN_MAX_LEASE_TIME_MS", "4000"),
+
+  // Logging
+  SP_LOGGING_FILE_ENABLED("SP_LOGGING_FILE_ENABLED", "false"),
+  SP_LOGGING_CONSOLE_ENABLED("SP_LOGGING_CONSOLE_ENABLED", "true"),
+  SP_LOGGING_FILE_PREFIX("SP_LOGGING_FILE_PREFIX", "streampipes"),
+  SP_LOGGING_FILE_DIR("SP_LOGGING_FILE_DIR", "logs"),
+  SP_LOGGING_FILE_PATTERN(
+      "SP_LOGGING_FILE_PATTERN",
+      "%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n"
+  );
+
 
   private final String envVariableName;
   private String defaultValue;
diff --git 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
index 473f625562..f314d20cca 100644
--- 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
+++ 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
@@ -407,4 +407,29 @@ public class DefaultEnvironment implements Environment {
   public IntEnvironmentVariable getPlc4xMaxLeaseTimeMs() {
     return new IntEnvironmentVariable(Envs.SP_PLC4X_CONN_MAX_LEASE_TIME_MS);
   }
+
+  @Override
+  public BooleanEnvironmentVariable getFileLoggingEnabled() {
+    return new BooleanEnvironmentVariable(Envs.SP_LOGGING_FILE_ENABLED);
+  }
+
+  @Override
+  public StringEnvironmentVariable getFileLoggingPrefix() {
+    return new StringEnvironmentVariable(Envs.SP_LOGGING_FILE_PREFIX);
+  }
+
+  @Override
+  public StringEnvironmentVariable getFileLoggingDir() {
+    return new StringEnvironmentVariable(Envs.SP_LOGGING_FILE_DIR);
+  }
+
+  @Override
+  public StringEnvironmentVariable getFileLoggingPattern() {
+    return new StringEnvironmentVariable(Envs.SP_LOGGING_FILE_PATTERN);
+  }
+
+  @Override
+  public BooleanEnvironmentVariable getConsoleLoggingEnabled() {
+    return new BooleanEnvironmentVariable(Envs.SP_LOGGING_CONSOLE_ENABLED);
+  }
 }
diff --git 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
index 187a03587d..2bf125b32a 100644
--- 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
+++ 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
@@ -158,4 +158,10 @@ public interface Environment {
 
   IntEnvironmentVariable getPlc4xMaxWaitTimeMs();
   IntEnvironmentVariable getPlc4xMaxLeaseTimeMs();
+
+  BooleanEnvironmentVariable getFileLoggingEnabled();
+  BooleanEnvironmentVariable getConsoleLoggingEnabled();
+  StringEnvironmentVariable getFileLoggingPrefix();
+  StringEnvironmentVariable getFileLoggingDir();
+  StringEnvironmentVariable getFileLoggingPattern();
 }
diff --git a/streampipes-data-explorer-influx/pom.xml 
b/streampipes-data-explorer-influx/pom.xml
index 9c7e7bb511..9d97e82690 100644
--- a/streampipes-data-explorer-influx/pom.xml
+++ b/streampipes-data-explorer-influx/pom.xml
@@ -63,10 +63,6 @@
         </dependency>
 
         <!-- External dependency -->
-        <dependency> <!-- SHOULD BE REMOVED SOON -->
-            <groupId>org.lightcouch</groupId>
-            <artifactId>lightcouch</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.influxdb</groupId>
             <artifactId>influxdb-java</artifactId>
@@ -97,4 +93,4 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 
-</project>
\ No newline at end of file
+</project>
diff --git a/streampipes-extensions-management/pom.xml 
b/streampipes-extensions-management/pom.xml
index 219a30efcd..09ac5b4e50 100644
--- a/streampipes-extensions-management/pom.xml
+++ b/streampipes-extensions-management/pom.xml
@@ -93,6 +93,12 @@
         <dependency>
             <groupId>com.opencsv</groupId>
             <artifactId>opencsv</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>commons-logging</groupId>
+                    <artifactId>commons-logging</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.apache.avro</groupId>
diff --git a/streampipes-extensions/streampipes-sinks-databases-jvm/pom.xml 
b/streampipes-extensions/streampipes-sinks-databases-jvm/pom.xml
index 557c0de036..a4733bbf82 100644
--- a/streampipes-extensions/streampipes-sinks-databases-jvm/pom.xml
+++ b/streampipes-extensions/streampipes-sinks-databases-jvm/pom.xml
@@ -157,14 +157,6 @@
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
-        </dependency>
     </dependencies>
 
     <build>
diff --git a/streampipes-service-base/pom.xml b/streampipes-service-base/pom.xml
index 114d63f7cb..a9f6ae6e14 100644
--- a/streampipes-service-base/pom.xml
+++ b/streampipes-service-base/pom.xml
@@ -41,6 +41,10 @@
         </dependency>
 
         <!-- External dependencies -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-logging</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-undertow</artifactId>
diff --git 
a/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/logging/LogbackRollingFileConfig.java
 
b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/logging/LogbackRollingFileConfig.java
new file mode 100644
index 0000000000..9758d2bbce
--- /dev/null
+++ 
b/streampipes-service-base/src/main/java/org/apache/streampipes/service/base/logging/LogbackRollingFileConfig.java
@@ -0,0 +1,101 @@
+/*
+ * 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.streampipes.service.base.logging;
+
+import org.apache.streampipes.commons.environment.Environment;
+import org.apache.streampipes.commons.environment.Environments;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.rolling.RollingFileAppender;
+import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.SpringApplicationRunListener;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import java.io.File;
+
+public class LogbackRollingFileConfig implements SpringApplicationRunListener {
+
+  private static final org.slf4j.Logger LOG = 
LoggerFactory.getLogger(LogbackRollingFileConfig.class);
+  private static final String CONSOLE_LOGGER = "CONSOLE";
+  private final Environment env;
+
+  public LogbackRollingFileConfig(SpringApplication application, String[] 
args) {
+    env = Environments.getEnvironment();
+  }
+
+  @Override
+  public void contextPrepared(ConfigurableApplicationContext ctx) {
+    var fileLoggingEnabled = env.getFileLoggingEnabled().getValueOrDefault();
+    if (!fileLoggingEnabled) {
+      return;
+    }
+
+    var logDir = env.getFileLoggingDir().getValueOrDefault();
+    var logPattern = env.getFileLoggingPattern().getValueOrDefault();
+    var prefix = env.getFileLoggingPrefix().getValueOrDefault();
+
+    File dir = new File(logDir);
+    if (!dir.exists() && !dir.mkdirs()) {
+      System.err.println("Failed to create log directory: " + logDir);
+      return;
+    }
+
+    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+    // Encoder
+    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
+    encoder.setContext(context);
+    encoder.setPattern(logPattern);
+    encoder.start();
+
+    // Rolling policy
+    TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new 
TimeBasedRollingPolicy<>();
+    rollingPolicy.setContext(context);
+    rollingPolicy.setFileNamePattern(logDir + "/" + prefix + 
".%d{yyyy-MM-dd}.log");
+    rollingPolicy.setMaxHistory(7);
+    rollingPolicy.setParent(new RollingFileAppender<>());
+    rollingPolicy.start();
+
+    // Rolling File Appender
+    RollingFileAppender<ILoggingEvent> fileAppender = new 
RollingFileAppender<>();
+    fileAppender.setContext(context);
+    fileAppender.setName("FILE");
+    fileAppender.setFile(logDir + "/" + prefix + ".log");
+    fileAppender.setEncoder(encoder);
+    fileAppender.setAppend(true);
+    fileAppender.setRollingPolicy(rollingPolicy);
+    rollingPolicy.setParent(fileAppender);
+    fileAppender.start();
+
+    // Add to root logger
+    Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
+    rootLogger.addAppender(fileAppender);
+    if (!env.getConsoleLoggingEnabled().getValueOrDefault()) {
+      LOG.info("Console logging is set to disabled. Set 
SP_LOGGING_CONSOLE_ENABLED to true to enable console logging.");
+      rootLogger.detachAppender(CONSOLE_LOGGER);
+    }
+
+  }
+}
+
diff --git 
a/streampipes-service-base/src/main/resources/META-INF/spring.factories 
b/streampipes-service-base/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000000..65a57ba60c
--- /dev/null
+++ b/streampipes-service-base/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+#
+
+org.springframework.boot.SpringApplicationRunListener=org.apache.streampipes.service.base.logging.LogbackRollingFileConfig
diff --git a/streampipes-storage-couchdb/pom.xml 
b/streampipes-storage-couchdb/pom.xml
index d61d1ea8a0..abe330889a 100644
--- a/streampipes-storage-couchdb/pom.xml
+++ b/streampipes-storage-couchdb/pom.xml
@@ -57,6 +57,12 @@
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>fluent-hc</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>commons-logging</groupId>
+                    <artifactId>commons-logging</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
diff --git a/streampipes-wrapper-siddhi/pom.xml 
b/streampipes-wrapper-siddhi/pom.xml
index ffa7f21674..9ed69dca13 100644
--- a/streampipes-wrapper-siddhi/pom.xml
+++ b/streampipes-wrapper-siddhi/pom.xml
@@ -53,6 +53,10 @@
                     <groupId>org.apache.logging.log4j</groupId>
                     <artifactId>log4j-core</artifactId>
                 </exclusion>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-simple</artifactId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>

Reply via email to