Skip to content

Commit 68fe63d

Browse files
committed
feat(logs): user-selectable logs limit
When viewing debug logs, the current buffer limit of a 100 is full pretty quick. I'm adding an option for the user to choose a bigger limit (up to a 1000).
1 parent f0a2cf5 commit 68fe63d

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

src/components/logs-page/index.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import { connect } from 'unistore/react';
33
import actions, { UtilsApi } from '../../actions/actions';
4-
import { GlobalState, LogMessage } from '../../store';
4+
import store, { GlobalState, LogMessage } from '../../store';
55
import cx from 'classnames';
66
import escapeRegExp from 'lodash/escapeRegExp';
77
import { BridgeApi } from '../../actions/BridgeApi';
@@ -71,6 +71,7 @@ export function LogRow(props: LogRowProps): JSX.Element {
7171
}
7272

7373
const logLevels = [ALL, 'debug', 'info', 'warning', 'error'];
74+
const logLimits = [100, 200, 500, 1000];
7475

7576
type PropsFromStore = Pick<GlobalState, 'bridgeInfo' | 'logs'>;
7677
class LogsPage extends Component<PropsFromStore & BridgeApi & UtilsApi & WithTranslation<'logs'>, LogsPageState> {
@@ -125,6 +126,28 @@ class LogsPage extends Component<PropsFromStore & BridgeApi & UtilsApi & WithTra
125126
onChange={updateBridgeConfig}
126127
/>
127128
</div>
129+
<div className="col-12 col-sm-4 col-xxl-4">
130+
<label htmlFor="logs-limit" className="form-label">
131+
{t('logs_limit')}
132+
</label>
133+
<select
134+
id="logs-limit"
135+
className="form-select"
136+
onChange={(e) => {
137+
const limit = parseInt(e.target.value);
138+
store.setState({
139+
logsLimit: limit,
140+
logs: [...store.getState().logs.slice(-limit)],
141+
});
142+
}}
143+
>
144+
{logLimits.map((limit) => (
145+
<option key={limit} value={limit} selected={limit == store.getState().logsLimit}>
146+
{limit}
147+
</option>
148+
))}
149+
</select>
150+
</div>
128151
<div className="col-12">
129152
<label htmlFor="reset">&nbsp;</label>
130153
<input

src/i18n/locales/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,8 @@
25342534
"logs": {
25352535
"empty_logs_message": "Nothing to display",
25362536
"filter_by_text": "Filter by text",
2537-
"show_only": "Show only"
2537+
"show_only": "Show only",
2538+
"logs_limit": "Logs limit"
25382539
},
25392540
"map": {
25402541
"help_coordinator_link_description": "Solid lines are the link to the Coordinator",

src/initialState.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
},
2525
"logs": [],
26+
"logsLimit": 100,
2627
"extensions": [],
2728
"theme": "light",
2829
"missingTranslations": {},

src/store.ts

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface GlobalState extends WithDevices, WithDeviceStates, WithGroups,
6767
bridgeConfig: BridgeConfig;
6868
bridgeState: BridgeState;
6969
logs: LogMessage[];
70+
logsLimit: number;
7071
extensions: Extension[];
7172
theme: Theme;
7273
missingTranslations: Map<string, unknown>;

src/ws-client.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import keyBy from 'lodash/keyBy';
1515
import { GraphI } from './components/map/types';
1616
import local from 'store2';
1717

18-
const MAX_LOGS_RECORDS_IN_BUFFER = 100;
1918
const TOKEN_LOCAL_STORAGE_ITEM_NAME = "z2m-token-v2";
2019
const AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME = "z2m-auth-v2";
2120
const UNAUTHORIZED_ERROR_CODE = 4401;
@@ -193,8 +192,8 @@ class Api {
193192

194193
case "bridge/logging":
195194
{
196-
const { logs } = store.getState();
197-
const newLogs = [...logs.slice(-MAX_LOGS_RECORDS_IN_BUFFER)];
195+
const { logs, logsLimit} = store.getState();
196+
const newLogs = [...logs.slice(-logsLimit)];
198197
newLogs.push({ ...(data.payload as unknown as LogMessage), timestamp: new Date() } as LogMessage);
199198
store.setState({ logs: newLogs });
200199
const log = data.payload as unknown as LogMessage;

0 commit comments

Comments
 (0)