Add loadpoint context to errors and warning (#9813)
This commit is contained in:
parent
ca916c0e17
commit
8f31abd5d4
13 changed files with 77 additions and 43 deletions
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
class="me-2 flex-shrink-0"
|
||||
/>
|
||||
<div class="text-truncate">
|
||||
{{ title || $t("main.loadpoint.fallbackName") }}
|
||||
{{ loadpointTitle }}
|
||||
</div>
|
||||
</h3>
|
||||
<LoadpointSettingsButton
|
||||
|
|
@ -210,6 +210,9 @@ export default {
|
|||
};
|
||||
},
|
||||
computed: {
|
||||
loadpointTitle: function () {
|
||||
return this.title || this.$t("main.loadpoint.fallbackName");
|
||||
},
|
||||
integratedDevice: function () {
|
||||
return this.chargerFeatureIntegratedDevice;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -14,46 +14,46 @@ const state = reactive({
|
|||
notifications: [
|
||||
{
|
||||
message: "Server unavailable",
|
||||
type: "error",
|
||||
level: "error",
|
||||
time: timeAgo(),
|
||||
count: 1,
|
||||
},
|
||||
{
|
||||
message: "charger out of sync: expected disabled, got enabled",
|
||||
type: "warn",
|
||||
level: "warn",
|
||||
count: 4,
|
||||
time: timeAgo(0, 0, 42),
|
||||
},
|
||||
{
|
||||
message: "Sponsortoken: x509: certificate has expired",
|
||||
type: "error",
|
||||
level: "error",
|
||||
count: 1,
|
||||
time: timeAgo(1, 12, 44),
|
||||
},
|
||||
{
|
||||
message:
|
||||
"Block device full: can not write to /tmp/evcc/foobarloremawefhwuiehfwuiehfwiauhefjkajowaeigjwalvmoweivwail",
|
||||
type: "error",
|
||||
level: "error",
|
||||
count: 1,
|
||||
time: timeAgo(1, 12, 44),
|
||||
},
|
||||
{
|
||||
message: "charger out of sync: expected disabled, got enabled",
|
||||
type: "warn",
|
||||
level: "warn",
|
||||
count: 4,
|
||||
time: timeAgo(1, 22, 0),
|
||||
},
|
||||
{
|
||||
message:
|
||||
"vehicle remote charge start: invalid character '<' looking for beginning of value",
|
||||
type: "warn",
|
||||
level: "warn",
|
||||
count: 3,
|
||||
time: timeAgo(4, 2, 0),
|
||||
},
|
||||
{
|
||||
message:
|
||||
"Amet irure quis incididunt voluptate esse. Commodo ea sunt est ipsum tempor nisi laboris voluptate labore elit laborum. Ex irure commodo reprehenderit consequat consequat do ad tempor aliquip deserunt eu. Laboris minim nostrud quis nisi. Dolor occaecat reprehenderit velit dolore exercitation cupidatat et voluptate. Nulla pariatur deserunt esse minim nisi nisi nulla. Sit eiusmod do incididunt sint minim pariatur aute.",
|
||||
type: "warn",
|
||||
level: "warn",
|
||||
count: 1,
|
||||
time: timeAgo(5, 2, 44),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -45,13 +45,13 @@
|
|||
<p class="d-flex align-items-baseline">
|
||||
<shopicon-regular-exclamationtriangle
|
||||
:class="{
|
||||
'text-danger': msg.type === 'error',
|
||||
'text-warning': msg.type === 'warn',
|
||||
'text-danger': msg.level === 'error',
|
||||
'text-warning': msg.level === 'warn',
|
||||
}"
|
||||
class="flex-grow-0 flex-shrink-0 d-block"
|
||||
></shopicon-regular-exclamationtriangle>
|
||||
<span class="flex-grow-1 px-2 py-1 text-break">
|
||||
{{ msg.message }}
|
||||
{{ message(msg) }}
|
||||
</span>
|
||||
<span v-if="msg.count > 1" class="badge rounded-pill bg-secondary">
|
||||
{{ 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();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
{{ siteTitle || "evcc" }}
|
||||
</h1>
|
||||
<div class="d-flex">
|
||||
<Notifications :notifications="notifications" class="me-2" />
|
||||
<Notifications
|
||||
:notifications="notifications"
|
||||
:loadpointTitles="loadpointTitles"
|
||||
class="me-2"
|
||||
/>
|
||||
<TopNavigation v-bind="topNavigation" />
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}]`,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
10
cmd/root.go
10
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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
38
util/log.go
38
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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue