Skip to content

Commit c2a3dac

Browse files
committed
Use the Home Assistant System Log
1 parent e7b7b8d commit c2a3dac

File tree

4 files changed

+81
-18
lines changed

4 files changed

+81
-18
lines changed

docs/configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ You can set the following configuration parameters for every individual Home Ass
77
| enabled_on_views | Enable WallPanel on the named views (path) only. See [Enable WallPanel on specific Views](configuration.md#enable-wallpanel-on-specific-views) for details. | [] |
88
| debug | Enable debug mode? | false |
99
| wait_for_browser_mod_time | How long to wait for browser_mod to be available (in seconds)? This config attribute can only be set in the main configuration and not in profiles, user-specific or device-specific. | 0.25 |
10-
| log_level_console | Log level to use for logging to the browser console (error / warn / info / debug). | info |
10+
| log_level_console | Log level to use for logging to the browser console (error / warning / info / debug). | info |
11+
| log_level_system | Log level to use for logging to the HA system log (error / warning / info / debug). | warning |
12+
| system_target_log_level | Always use this log level when logging to the HA system log (error / warning / info / debug). | |
1113
| alert_errors | Display error messages in an alert box. | true |
1214
| hide_toolbar | Hide the upper panel toolbar? Please see [FAQ](faq.md#dashboard-cannot-be-edited) how to edit your dashboard when toolbar is hidden. | false |
1315
| hide_toolbar_on_subviews | Hide the toolbar in subviews too? | false |

docs/troubleshooting.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,25 @@ You should see a message like `🖼️ Wallpanel version x.y.z` if WallPanel has
3232

3333
If not, please check if there are any error messages that give an indication of the problem.
3434

35-
To confgure how much information WallPanel logs to the browser console, you can set the configuration option `log_level_console` to `error`, `warn`, `info` or `debug`.
35+
To confgure how much information WallPanel logs to the browser console, you can set the configuration option `log_level_console` to `error`, `warning`, `info` or `debug`.
3636

3737
!!! example
3838
```yaml
3939
wallpanel:
4040
log_level_console: debug
4141
```
4242

43-
## Home Assistant Log
44-
Please check the [Home Assistant Log](https://www.home-assistant.io/integrations/system_log/) for errors regarding WallPanel.
43+
## Home Assistant System Log
44+
You can configure the log level used for logging to the [Home Assistant System Log](https://www.home-assistant.io/integrations/system_log/).
45+
By default, the original log level is used for the System Log.
46+
If you’d like to map all log levels to a single target level, you can set the `system_target_log_level` option.
47+
48+
!!! example
49+
```yaml
50+
wallpanel:
51+
log_level_system: debug
52+
system_target_log_level: error
53+
```
4554

4655

4756
## Debug mode

wallpanel-src.js

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Released under the GNU General Public License v3.0
44
*/
55

6-
const version = "4.55.1";
6+
const version = "4.56.0";
77
const defaultConfig = {
88
enabled: false,
99
enabled_on_views: [],
1010
debug: false,
1111
wait_for_browser_mod_time: 0.25,
1212
log_level_console: "info",
13+
log_level_system: "warning",
14+
system_target_log_level: "",
1315
alert_errors: true,
1416
hide_toolbar: false,
1517
keep_toolbar_space: false,
@@ -233,7 +235,9 @@ function stringify(obj) {
233235

234236
const logger = {
235237
messages: [],
236-
logLevel: "warn",
238+
logLevelConsole: "warning",
239+
logLevelSystem: "error",
240+
systemTargetLogLevel: "",
237241
addMessage: function (level, args) {
238242
if (!config.debug) {
239243
return;
@@ -262,6 +266,22 @@ const logger = {
262266
logger.messages.shift();
263267
}
264268
},
269+
systemLog(level, message) {
270+
if (!elHass || !elHass.hass) {
271+
return;
272+
}
273+
return elHass.hass.callService(
274+
"system_log",
275+
"write",
276+
{
277+
logger: `frontend.wallpanel${browserId ? "." + browserId : ""}`,
278+
message: message,
279+
level: logger.systemTargetLogLevel || level
280+
},
281+
undefined,
282+
false
283+
);
284+
},
265285
downloadMessages: function () {
266286
const data = new Blob([stringify(logger.messages)], { type: "text/plain" });
267287
const url = window.URL.createObjectURL(data);
@@ -274,32 +294,46 @@ const logger = {
274294
purgeMessages: function () {
275295
logger.messages = [];
276296
},
277-
log: function () {
278-
console.log.apply(this, arguments);
279-
logger.addMessage("info", arguments);
280-
},
281297
debug: function () {
282-
if (["debug"].includes(logger.logLevel)) {
298+
if (["debug"].includes(logger.logLevelConsole)) {
283299
console.debug.apply(this, arguments);
284300
}
301+
if (["debug"].includes(logger.logLevelSystem)) {
302+
logger.systemLog("debug", stringify(arguments));
303+
}
285304
logger.addMessage("debug", arguments);
286305
},
287306
info: function () {
288-
if (["debug", "info"].includes(logger.logLevel)) {
307+
if (["debug", "info"].includes(logger.logLevelConsole)) {
289308
console.info.apply(this, arguments);
290309
}
310+
if (["debug", "info"].includes(logger.logLevelSystem)) {
311+
logger.systemLog("info", stringify(arguments));
312+
}
291313
logger.addMessage("info", arguments);
292314
},
293-
warn: function () {
294-
if (["debug", "info", "warn"].includes(logger.logLevel)) {
315+
log: function () {
316+
logger.info.apply(this, arguments);
317+
},
318+
warning: function () {
319+
if (["debug", "info", "warning"].includes(logger.logLevelConsole)) {
295320
console.warn.apply(this, arguments);
296321
}
297-
logger.addMessage("warn", arguments);
322+
if (["debug", "info", "warning"].includes(logger.logLevelSystem)) {
323+
logger.systemLog("warning", stringify(arguments));
324+
}
325+
logger.addMessage("warning", arguments);
326+
},
327+
warn: function () {
328+
logger.warning.apply(this, arguments);
298329
},
299330
error: function () {
300-
if (["debug", "info", "warn", "error"].includes(logger.logLevel)) {
331+
if (["debug", "info", "warning", "error"].includes(logger.logLevelConsole)) {
301332
console.error.apply(this, arguments);
302333
}
334+
if (["debug", "info", "warning", "error"].includes(logger.logLevelSystem)) {
335+
logger.systemLog("error", stringify(arguments));
336+
}
303337
logger.addMessage("error", arguments);
304338
if (config.alert_errors) {
305339
const msg = `Wallpanel error: ${stringify(arguments)}`;
@@ -309,6 +343,9 @@ const logger = {
309343
alert(msg);
310344
}
311345
}
346+
},
347+
err: function () {
348+
logger.error.apply(this, arguments);
312349
}
313350
};
314351

@@ -694,10 +731,25 @@ function updateConfig() {
694731
config.show_images = false;
695732
}
696733

734+
if (config.log_level_console == "err") {
735+
config.log_level_console = "error";
736+
} else if (config.log_level_console == "warn") {
737+
config.log_level_console = "warning";
738+
}
697739
if (!oldConfig || !Object.keys(oldConfig).length) {
698740
// Keep old log level to get log messages when navigating between different dashboards
699-
logger.logLevel = config.log_level_console;
741+
logger.logLevelConsole = config.log_level_console;
742+
logger.logLevelConsole;
700743
}
744+
745+
if (config.log_level_system == "err") {
746+
config.log_level_system = "error";
747+
} else if (config.log_level_system == "warn") {
748+
config.log_level_system = "warning";
749+
}
750+
logger.logLevelSystem = config.log_level_system;
751+
logger.systemTargetLogLevel = config.system_target_log_level;
752+
701753
logger.debug("Wallpanel config is now:", config);
702754

703755
if (wallpanel) {

wallpanel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)