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

wodiwudi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozhera.git


The following commit(s) were added to refs/heads/master by this push:
     new fba7769c fix: support parsing the OpenCLAW log path (#660)
fba7769c is described below

commit fba7769c2ef8f7bb6aa13af43ce2789595c182d0
Author: Xue <[email protected]>
AuthorDate: Tue May 12 22:07:45 2026 +0800

    fix: support parsing the OpenCLAW log path (#660)
    
    * fix: Handling special openclaw logs
    
    * fix: use string type matching for OPENCLAW log type instead of numeric 
code
    
    * fix: Handling special openclaw logs
---
 .../agent/channel/WildcardChannelServiceImpl.java  | 85 ++++++++++++++++++++--
 .../log-agent/src/main/resources/config.properties |  5 +-
 .../src/main/resources/config/dev.properties       |  5 +-
 .../src/main/resources/config/open.properties      |  5 +-
 4 files changed, 91 insertions(+), 9 deletions(-)

diff --git 
a/ozhera-log/log-agent/src/main/java/org/apache/ozhera/log/agent/channel/WildcardChannelServiceImpl.java
 
b/ozhera-log/log-agent/src/main/java/org/apache/ozhera/log/agent/channel/WildcardChannelServiceImpl.java
index fc24ca23..0242c92b 100644
--- 
a/ozhera-log/log-agent/src/main/java/org/apache/ozhera/log/agent/channel/WildcardChannelServiceImpl.java
+++ 
b/ozhera-log/log-agent/src/main/java/org/apache/ozhera/log/agent/channel/WildcardChannelServiceImpl.java
@@ -45,10 +45,12 @@ import org.apache.ozhera.log.agent.input.Input;
 import org.apache.ozhera.log.api.enums.LogTypeEnum;
 import org.apache.ozhera.log.api.model.meta.FilterConf;
 import org.apache.ozhera.log.api.model.msg.LineMessage;
+import org.apache.ozhera.log.common.Config;
 import org.apache.ozhera.log.common.PathUtils;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 import java.time.Instant;
 import java.util.*;
 import java.util.concurrent.*;
@@ -63,6 +65,7 @@ import static org.apache.ozhera.log.common.Constant.GSON;
 import static org.apache.ozhera.log.common.Constant.SYMBOL_MULTI;
 import static org.apache.ozhera.log.common.PathUtils.*;
 
+
 /**
  * @author wtt
  * @version 1.0
@@ -90,6 +93,9 @@ public class WildcardChannelServiceImpl extends 
AbstractChannelService {
 
     private static final String POINTER_FILENAME_PREFIX = ".ozhera_pointer";
 
+    private static final String OPENCLAW_LOG_TYPE_KEY = "openclaw.log.type";
+    private static final String OPENCLAW_DIR_PREFIX_KEY = 
"openclaw.directory.prefix";
+
     private final List<LineMessage> lineMessageList = new ArrayList<>();
 
     private ScheduledFuture<?> scheduledFuture;
@@ -135,8 +141,11 @@ public class WildcardChannelServiceImpl extends 
AbstractChannelService {
         this.logPattern = input.getLogPattern();
         this.linePrefix = input.getLinePrefix();
 
-        List<String> patterns = PathUtils.parseLevel5Directory(logPattern);
-        log.info("channel start, logPattern:{},fileList:{}, channelId:{}, 
instanceId:{}", logPattern, GSON.toJson(patterns), channelId, instanceId());
+        String effectiveLogPattern = expandOpenclawIfNeeded(logPattern, input);
+
+        List<String> patterns = 
PathUtils.parseLevel5Directory(effectiveLogPattern);
+        log.info("channel start, logPattern:{}, effectiveLogPattern:{}, 
fileList:{}, channelId:{}, instanceId:{}",
+                logPattern, effectiveLogPattern, GSON.toJson(patterns), 
channelId, instanceId());
 
         channelMemory = memoryService.getMemory(channelId);
         if (null == channelMemory) {
@@ -144,7 +153,7 @@ public class WildcardChannelServiceImpl extends 
AbstractChannelService {
         }
         memoryService.cleanChannelMemoryContent(channelId, patterns);
 
-        startCollectFile(channelId, input);
+        startCollectFile(channelId, input, effectiveLogPattern);
 
         startExportQueueDataThread();
         memoryService.refreshMemory(channelMemory);
@@ -152,7 +161,71 @@ public class WildcardChannelServiceImpl extends 
AbstractChannelService {
 
     }
 
-    private void startCollectFile(Long channelId, Input input) {
+    private String expandOpenclawIfNeeded(String logPattern, Input input) {
+        String openclawLogType = Config.ins().get(OPENCLAW_LOG_TYPE_KEY, "");
+        String openclawDirPrefix = Config.ins().get(OPENCLAW_DIR_PREFIX_KEY, 
"");
+        if (StringUtils.isBlank(openclawLogType) || 
StringUtils.isBlank(openclawDirPrefix)) {
+            return logPattern;
+        }
+        if (!openclawLogType.trim().equals(input.getType())) {
+            return logPattern;
+        }
+        List<String> expanded = expandOpenclawWildcardPaths(logPattern, 
openclawDirPrefix);
+        if (expanded.isEmpty()) {
+            return logPattern;
+        }
+        String result = String.join(",", expanded);
+        log.info("OPENCLAW path expanded: {} -> {}", logPattern, result);
+        return result;
+    }
+
+    private List<String> expandOpenclawWildcardPaths(String origPath, String 
dirPrefix) {
+        List<String> result = Lists.newArrayList();
+        String[] pathArray = origPath.split(",");
+        for (String path : pathArray) {
+            path = path.replaceAll("//", "/").trim();
+            String[] segments = path.split(SEPARATOR);
+            int wildcardIndex = -1;
+            for (int i = 0; i < segments.length; i++) {
+                if (PATH_WILDCARD.equals(segments[i])) {
+                    wildcardIndex = i;
+                    break;
+                }
+            }
+            if (wildcardIndex < 1) {
+                result.add(path);
+                continue;
+            }
+            String baseDir = String.join(SEPARATOR, 
Arrays.copyOfRange(segments, 0, wildcardIndex));
+            File baseDirFile = new File(baseDir);
+            if (!baseDirFile.isDirectory()) {
+                log.warn("OPENCLAW baseDir not found: {}", baseDir);
+                result.add(path);
+                continue;
+            }
+            String[] subDirs = baseDirFile.list();
+            if (subDirs == null || subDirs.length == 0) {
+                log.warn("OPENCLAW baseDir is empty: {}", baseDir);
+                result.add(path);
+                continue;
+            }
+            String suffix = String.join(SEPARATOR, 
Arrays.copyOfRange(segments, wildcardIndex + 1, segments.length));
+            boolean matched = false;
+            for (String subDir : subDirs) {
+                if (subDir.startsWith(dirPrefix) && new File(baseDir + 
SEPARATOR + subDir).isDirectory()) {
+                    result.add(baseDir + SEPARATOR + subDir + SEPARATOR + 
suffix);
+                    matched = true;
+                }
+            }
+            if (!matched) {
+                log.warn("OPENCLAW no directory matched prefix '{}' under {}", 
dirPrefix, baseDir);
+                result.add(path);
+            }
+        }
+        return result;
+    }
+
+    private void startCollectFile(Long channelId, Input input, String 
effectiveLogPattern) {
         try {
             // Load the restart file
             String restartFile = buildRestartFilePath();
@@ -160,9 +233,9 @@ public class WildcardChannelServiceImpl extends 
AbstractChannelService {
 
             fileMonitor = createFileMonitor(input.getPatternCode());
 
-            String fileExpression = buildFileExpression(input.getLogPattern());
+            String fileExpression = buildFileExpression(effectiveLogPattern);
 
-            List<String> monitorPaths = 
buildMonitorPaths(input.getLogPattern());
+            List<String> monitorPaths = buildMonitorPaths(effectiveLogPattern);
 
             wildcardGraceShutdown(monitorPaths, fileExpression);
 
diff --git a/ozhera-log/log-agent/src/main/resources/config.properties 
b/ozhera-log/log-agent/src/main/resources/config.properties
index 7c9570b3..bfd49414 100644
--- a/ozhera-log/log-agent/src/main/resources/config.properties
+++ b/ozhera-log/log-agent/src/main/resources/config.properties
@@ -38,4 +38,7 @@ registration_initiation_flag=true
 
 filter_log_level_prefix_length = ${filter_log_level_prefix_length}
 
-app_partition_key_switch=true
\ No newline at end of file
+app_partition_key_switch=true
+
+openclaw.log.type=${openclaw.log.type}
+openclaw.directory.prefix=${openclaw.directory.prefix}
\ No newline at end of file
diff --git a/ozhera-log/log-agent/src/main/resources/config/dev.properties 
b/ozhera-log/log-agent/src/main/resources/config/dev.properties
index 8305f380..1e9fc1f7 100644
--- a/ozhera-log/log-agent/src/main/resources/config/dev.properties
+++ b/ozhera-log/log-agent/src/main/resources/config/dev.properties
@@ -24,4 +24,7 @@ app_id=10010
 env_id=1
 env_name=default_env
 
-filter_log_level_prefix_length = 60
\ No newline at end of file
+filter_log_level_prefix_length = 60
+
+openclaw.log.type=OPENCLAW_LOG
+openclaw.directory.prefix=china-efficiency-openclaw-
\ No newline at end of file
diff --git a/ozhera-log/log-agent/src/main/resources/config/open.properties 
b/ozhera-log/log-agent/src/main/resources/config/open.properties
index 919ca098..ddc3a80d 100644
--- a/ozhera-log/log-agent/src/main/resources/config/open.properties
+++ b/ozhera-log/log-agent/src/main/resources/config/open.properties
@@ -26,4 +26,7 @@ app_id=10010
 env_id=1
 env_name=default_env
 
-filter_log_level_prefix_length = 60
\ No newline at end of file
+filter_log_level_prefix_length = 60
+
+openclaw.log.type=OPENCLAW_LOG
+openclaw.directory.prefix=china-efficiency-openclaw-
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to