diff --git a/assets/js/api.js b/assets/js/api.js
index 3ca9d5caa..211755ecb 100644
--- a/assets/js/api.js
+++ b/assets/js/api.js
@@ -20,7 +20,7 @@ api.interceptors.response.use(
const url = error.config.baseURL + error.config.url;
message += `: API request failed ${url}`;
}
- window.app.error({ message });
+ window.app.raise({ message });
return Promise.reject(error);
}
);
diff --git a/assets/js/app.js b/assets/js/app.js
index d86ec2630..cb668f951 100644
--- a/assets/js/app.js
+++ b/assets/js/app.js
@@ -27,10 +27,10 @@ const app = createApp({
},
methods: {
raise: function (msg) {
- console[msg.type](msg);
+ if (!msg.level) msg.level = "error";
const now = new Date();
const latestMsg = this.notifications[0];
- if (latestMsg && latestMsg.message === msg.message) {
+ if (latestMsg && latestMsg.message === msg.message && latestMsg.lp === msg.lp) {
latestMsg.count++;
latestMsg.time = now;
} else {
@@ -47,20 +47,12 @@ const app = createApp({
clear: function () {
this.notifications = [];
},
- error: function (msg) {
- msg.type = "error";
- this.raise(msg);
- },
setOnline: function () {
this.offline = false;
},
setOffline: function () {
this.offline = true;
},
- warn: function (msg) {
- msg.type = "warn";
- this.raise(msg);
- },
},
render: function () {
return h(App, { notifications: this.notifications, offline: this.offline });
diff --git a/assets/js/baseapi.js b/assets/js/baseapi.js
index 380b546d1..da1299adc 100644
--- a/assets/js/baseapi.js
+++ b/assets/js/baseapi.js
@@ -12,7 +12,7 @@ baseAPI.interceptors.response.use(
(error) => {
const url = error.config.baseURL + error.config.url;
const message = `${error.message}: API request failed ${url}`;
- window.app.error({ message });
+ window.app.raise({ message });
}
);
diff --git a/assets/js/communityApi.js b/assets/js/communityApi.js
index 292789f6c..140ac6518 100644
--- a/assets/js/communityApi.js
+++ b/assets/js/communityApi.js
@@ -13,7 +13,7 @@ api.interceptors.response.use(
(error) => {
const url = error.config.baseURL + error.config.url;
const message = `${error.message}: API request failed ${url}`;
- window.app.error({ message });
+ window.app.raise({ message });
return Promise.reject(error);
}
);
diff --git a/assets/js/components/Loadpoint.vue b/assets/js/components/Loadpoint.vue
index 5b380b212..04b869af8 100644
--- a/assets/js/components/Loadpoint.vue
+++ b/assets/js/components/Loadpoint.vue
@@ -9,7 +9,7 @@
class="me-2 flex-shrink-0"
/>
- {{ title || $t("main.loadpoint.fallbackName") }}
+ {{ loadpointTitle }}
- {{ msg.message }}
+ {{ message(msg) }}
{{ msg.count }}
@@ -85,13 +85,14 @@ export default {
mixins: [formatter],
props: {
notifications: Array,
+ loadpointTitles: Array,
},
computed: {
iconVisible: function () {
return this.notifications.length > 0;
},
iconClass: function () {
- return this.notifications.find((m) => m.type === "error")
+ return this.notifications.find((m) => m.level === "error")
? "text-danger"
: "text-warning";
},
@@ -105,6 +106,13 @@ export default {
clearTimeout(this.interval);
},
methods: {
+ message({ message, lp }) {
+ let context = "";
+ if (lp) {
+ context = `${this.loadpointTitles[lp - 1] || lp}: `;
+ }
+ return `${context}${message}`;
+ },
clear: function () {
window.app && window.app.clear();
},
diff --git a/assets/js/components/Site.vue b/assets/js/components/Site.vue
index 41f4aad22..ed332cd0d 100644
--- a/assets/js/components/Site.vue
+++ b/assets/js/components/Site.vue
@@ -6,7 +6,11 @@
{{ siteTitle || "evcc" }}
-
+
@@ -104,6 +108,9 @@ export default {
energyflow: function () {
return this.collectProps(Energyflow);
},
+ loadpointTitles: function () {
+ return this.loadpoints.map((lp) => lp.title);
+ },
loadpointsCompact: function () {
return this.loadpoints.map((lp) => {
const icon = lp.chargerIcon || lp.vehicleIcon || "car";
diff --git a/assets/js/store.js b/assets/js/store.js
index d91ba15c8..1841ec006 100644
--- a/assets/js/store.js
+++ b/assets/js/store.js
@@ -26,8 +26,8 @@ const store = {
state,
update: function (msg) {
Object.keys(msg).forEach(function (k) {
- if (typeof window.app[k] === "function") {
- window.app[k]({ message: msg[k] });
+ if (k === "log") {
+ window.app.raise(msg[k]);
} else {
setProperty(state, k.split("."), msg[k]);
}
diff --git a/assets/js/views/App.vue b/assets/js/views/App.vue
index c6290c22b..b13a0b640 100644
--- a/assets/js/views/App.vue
+++ b/assets/js/views/App.vue
@@ -59,7 +59,7 @@ export default {
console.log("websocket connect");
const supportsWebSockets = "WebSocket" in window;
if (!supportsWebSockets) {
- window.app.error({
+ window.app.raise({
message: "Web sockets not supported. Please upgrade your browser.",
});
return;
@@ -99,7 +99,7 @@ export default {
var msg = JSON.parse(evt.data);
store.update(msg);
} catch (error) {
- window.app.error({
+ window.app.raise({
message: `Failed to parse web socket data: ${error.message} [${evt.data}]`,
});
}
diff --git a/cmd/root.go b/cmd/root.go
index 297022345..41f2071bf 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -38,9 +38,9 @@ var (
log = util.NewLogger("main")
cfgFile string
- ignoreEmpty = "" // ignore empty keys
- ignoreErrors = []string{"warn", "error"} // ignore errors
- ignoreMqtt = []string{"auth", "releaseNotes"} // excessive size may crash certain brokers
+ ignoreEmpty = "" // ignore empty keys
+ ignoreLogs = []string{"log"} // ignore log messages, including warn/error
+ ignoreMqtt = []string{"auth", "releaseNotes"} // excessive size may crash certain brokers
)
// rootCmd represents the base command when called without any subcommands
@@ -137,7 +137,7 @@ func runRoot(cmd *cobra.Command, args []string) {
// value cache
cache := util.NewCache()
- go cache.Run(pipe.NewDropper(ignoreErrors...).Pipe(tee.Attach()))
+ go cache.Run(pipe.NewDropper(ignoreLogs...).Pipe(tee.Attach()))
// create web server
socketHub := server.NewSocketHub()
@@ -193,7 +193,7 @@ func runRoot(cmd *cobra.Command, args []string) {
// setup database
if err == nil && conf.Influx.URL != "" {
- configureInflux(conf.Influx, site, pipe.NewDropper(append(ignoreErrors, ignoreEmpty)...).Pipe(tee.Attach()))
+ configureInflux(conf.Influx, site, pipe.NewDropper(append(ignoreLogs, ignoreEmpty)...).Pipe(tee.Attach()))
}
// setup mqtt publisher
diff --git a/cmd/setup.go b/cmd/setup.go
index 77462ba9d..134b43444 100644
--- a/cmd/setup.go
+++ b/cmd/setup.go
@@ -657,7 +657,7 @@ func configureLoadpoints(conf globalConfig) (loadpoints []*core.Loadpoint, err e
return nil, fmt.Errorf("failed decoding loadpoint configuration: %w", err)
}
- log := util.NewLogger("lp-" + strconv.Itoa(id+1))
+ log := util.NewLoggerWithLoadpoint("lp-"+strconv.Itoa(id+1), id+1)
lp, err := core.NewLoadpointFromConfig(log, lpc)
if err != nil {
return nil, fmt.Errorf("failed configuring loadpoint: %w", err)
diff --git a/util/log.go b/util/log.go
index 979f27ec6..707767b53 100644
--- a/util/log.go
+++ b/util/log.go
@@ -31,10 +31,20 @@ var LogAreaPadding = 6
type Logger struct {
*jww.Notepad
*Redactor
+ lp int
}
// NewLogger creates a logger with the given log area and adds it to the registry
func NewLogger(area string) *Logger {
+ return newLogger(area, 0)
+}
+
+// NewLoggerWithLoadpoint creates a logger with reference to at loadpoint
+func NewLoggerWithLoadpoint(area string, lp int) *Logger {
+ return newLogger(area, lp)
+}
+
+func newLogger(area string, lp int) *Logger {
loggersMux.Lock()
defer loggersMux.Unlock()
@@ -54,6 +64,7 @@ func NewLogger(area string) *Logger {
logger := &Logger{
Notepad: notepad,
Redactor: redactor,
+ lp: lp,
}
// capture loggers created after uiChan is initialized
@@ -130,17 +141,29 @@ var uiChan chan<- Param
type uiWriter struct {
re *regexp.Regexp
level string
+ lp int
}
func (w *uiWriter) Write(p []byte) (n int, err error) {
// trim level and timestamp
s := string(w.re.ReplaceAll(p, []byte{}))
- uiChan <- Param{
- Key: w.level,
- Val: strings.Trim(strconv.Quote(strings.TrimSpace(s)), "\""),
+ val := struct {
+ Message string `json:"message"`
+ Level string `json:"level"`
+ Loadpoint int `json:"lp,omitempty"`
+ }{
+ Message: strings.Trim(strconv.Quote(strings.TrimSpace(s)), "\""),
+ Level: w.level,
+ Loadpoint: w.lp,
}
+ param := Param{
+ Key: "log",
+ Val: val,
+ }
+
+ uiChan <- param
return 0, nil
}
@@ -159,18 +182,19 @@ func CaptureLogs(c chan<- Param) {
}
func captureLogger(l *Logger) {
- captureLogLevel("warn", l.Notepad.WARN)
- captureLogLevel("error", l.Notepad.ERROR)
- captureLogLevel("error", l.Notepad.FATAL)
+ captureLogLevel("warn", l.lp, l.Notepad.WARN)
+ captureLogLevel("error", l.lp, l.Notepad.ERROR)
+ captureLogLevel("error", l.lp, l.Notepad.FATAL)
}
-func captureLogLevel(level string, l *log.Logger) {
+func captureLogLevel(level string, lp int, l *log.Logger) {
re, err := regexp.Compile(`^\[[a-zA-Z0-9-]+\s*\] \w+ .{19} `)
if err != nil {
panic(err)
}
ui := uiWriter{
+ lp: lp,
re: re,
level: level,
}