From fd3c1ffacdddc9c181b52fed465b4c948879b4e8 Mon Sep 17 00:00:00 2001 From: grog Date: Thu, 12 Oct 2023 11:33:56 -0700 Subject: [PATCH] config added to Log service --- src/main/java/org/myrobotlab/service/Log.java | 45 ++++++++++++++----- .../myrobotlab/service/config/LogConfig.java | 10 +++++ .../resource/WebGui/app/service/js/LogGui.js | 6 +-- .../WebGui/app/service/views/LogGui.html | 2 +- 4 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/myrobotlab/service/config/LogConfig.java diff --git a/src/main/java/org/myrobotlab/service/Log.java b/src/main/java/org/myrobotlab/service/Log.java index fa88732014..bdef4384cb 100644 --- a/src/main/java/org/myrobotlab/service/Log.java +++ b/src/main/java/org/myrobotlab/service/Log.java @@ -34,7 +34,8 @@ import org.myrobotlab.logging.LoggerFactory; import org.myrobotlab.logging.Logging; import org.myrobotlab.logging.LoggingFactory; -import org.myrobotlab.service.config.ServiceConfig; +import org.myrobotlab.service.config.LogConfig; +import org.myrobotlab.service.config.RuntimeConfig; import org.slf4j.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; @@ -44,7 +45,7 @@ import ch.qos.logback.core.spi.FilterReply; import ch.qos.logback.core.status.Status; -public class Log extends Service implements Appender { +public class Log extends Service implements Appender { public static class LogEntry { public long ts; @@ -81,7 +82,7 @@ public String toString() { * broadcast logging is through publishLogEvent (not broadcastState) */ transient List buffer = new ArrayList<>(); - + /** * logging state */ @@ -92,11 +93,8 @@ public String toString() { */ long lastPublishLogTimeTs = 0; - /** - * current log level - */ - String logLevel = null; + /** * max size of log buffer */ @@ -114,8 +112,10 @@ public Log(String n, String id) { public String getLogLevel() { Logging logging = LoggingFactory.getInstance(); - logLevel = logging.getLevel(); - return logLevel; + if (config != null) { + config.level = logging.getLevel(); + } + return logging.getLevel(); } @Override @@ -192,6 +192,7 @@ public void doAppend(ILoggingEvent event) throws LogbackException { synchronized public void flush() { if (buffer.size() > 0) { invoke("publishLogEvents", buffer); + buffer = new ArrayList<>(maxSize); lastPublishLogTimeTs = System.currentTimeMillis(); } @@ -224,6 +225,11 @@ public List publishLogEvents(List entries) { return entries; } + public List publishErrors(List entries) { + return entries; + } + + @Override public void setContext(Context arg0) { // TODO Auto-generated method stub @@ -256,6 +262,18 @@ public void setRootLogLevel(String level) { getLogLevel(); broadcastState(); } + + public LogConfig apply(LogConfig c) { + super.apply(c); + if (c.level != null) { + setRootLogLevel(c.level); + } + return c; + } + + public LogConfig getConfig() { + return config; + } @Override public void setName(String name) { @@ -308,14 +326,17 @@ public static void main(String[] args) { try { // Log4jLoggerAdapter blah; - + Runtime runtime = Runtime.getInstance(); + RuntimeConfig config = runtime.getConfig(); + config.resource = "src/main/resources/resource"; + runtime.apply(config); + Runtime.start("log", "Log"); Runtime.start("python", "Python"); WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui"); webgui.autoStartBrowser(false); webgui.startService(); - Runtime runtime = Runtime.getInstance(); - runtime.startInteractiveMode(); + log.info("this is an info test"); log.warn("this is an warn test"); log.error("this is an error test"); diff --git a/src/main/java/org/myrobotlab/service/config/LogConfig.java b/src/main/java/org/myrobotlab/service/config/LogConfig.java new file mode 100644 index 0000000000..31edbbd23a --- /dev/null +++ b/src/main/java/org/myrobotlab/service/config/LogConfig.java @@ -0,0 +1,10 @@ +package org.myrobotlab.service.config; + +public class LogConfig extends ServiceConfig { + + /** + * level of log error, warn, info, debug + */ + public String level = "info"; + +} diff --git a/src/main/resources/resource/WebGui/app/service/js/LogGui.js b/src/main/resources/resource/WebGui/app/service/js/LogGui.js index 4c37c533f6..a3c61e66d2 100644 --- a/src/main/resources/resource/WebGui/app/service/js/LogGui.js +++ b/src/main/resources/resource/WebGui/app/service/js/LogGui.js @@ -1,5 +1,5 @@ -angular.module('mrlapp.service.LogGui', []).controller('LogGuiCtrl', ['$scope', '$log', 'mrl', function($scope, $log, mrl) { - $log.info('LogGuiCtrl') +angular.module('mrlapp.service.LogGui', []).controller('LogGuiCtrl', ['$scope', 'mrl', function($scope, mrl) { + console.info('LogGuiCtrl') var _self = this var msg = this.msg @@ -116,7 +116,7 @@ angular.module('mrlapp.service.LogGui', []).controller('LogGuiCtrl', ['$scope', } break default: - $log.error("ERROR - unhandled method " + $scope.name + "." + msg.method) + console.error("ERROR - unhandled method " + $scope.name + "." + msg.method) break } } diff --git a/src/main/resources/resource/WebGui/app/service/views/LogGui.html b/src/main/resources/resource/WebGui/app/service/views/LogGui.html index 534ef01f42..065241915e 100644 --- a/src/main/resources/resource/WebGui/app/service/views/LogGui.html +++ b/src/main/resources/resource/WebGui/app/service/views/LogGui.html @@ -3,7 +3,7 @@
- +