Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 5545b3e

Browse files
authored
Merge pull request #450 from lightninglabs/even-faster-logs
Even faster logs
2 parents 7ea749e + a6cb0a7 commit 5545b3e

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

src/action/log.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export function error(...args) {
2121

2222
function pushLogs(message) {
2323
if (!_store) return;
24-
const { logs } = _store;
25-
logs.push(message);
26-
if (logs.length > MAX_LOG_LENGTH) {
27-
logs.splice(0, logs.length - MAX_LOG_LENGTH);
24+
_store.logs += '\n' + message.replace(/\s+$/, '');
25+
const len = _store.logs.length;
26+
if (len > MAX_LOG_LENGTH) {
27+
_store.logs = _store.logs.substring(len - MAX_LOG_LENGTH, len);
2828
}
2929
}
3030

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports.PREFIX_URI = `${prefixName}:`;
1313

1414
module.exports.DEFAULT_ROUTE = 'Welcome';
1515
module.exports.MIN_PASSWORD_LENGTH = 8;
16-
module.exports.MAX_LOG_LENGTH = 100;
16+
module.exports.MAX_LOG_LENGTH = 10000;
1717

1818
module.exports.UNITS = {
1919
sat: { display: 'SAT', displayLong: 'Satoshi', denominator: 1 },

src/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class Store {
6161
paymentRequest: null,
6262
seedMnemonic: [],
6363
notifications: [],
64-
logs: [],
64+
logs: '',
6565

6666
// Persistent data
6767
settings: {

src/view/cli.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const CLIView = ({ store, nav }) => (
2525
<Title title="Logs" />
2626
<Button disabled onPress={() => {}} />
2727
</Header>
28-
<LogOutput logs={store.logs.slice()} />
28+
<LogOutput logs={store.logs} />
2929
</Background>
3030
);
3131

@@ -55,12 +55,26 @@ const logStyles = StyleSheet.create({
5555
class LogOutput extends Component {
5656
constructor(props) {
5757
super(props);
58+
this._refresh = true;
5859
this._ref = React.createRef();
5960
}
6061

62+
shouldComponentUpdate() {
63+
const current = this._refresh;
64+
this._refresh = false;
65+
setTimeout(() => {
66+
this._refresh = true;
67+
}, 100);
68+
if (!current) {
69+
clearTimeout(this._tLast);
70+
this._tLast = setTimeout(() => this.forceUpdate(), 500);
71+
}
72+
return current;
73+
}
74+
6175
get printLogs() {
6276
setTimeout(() => this._ref.current.scrollToEnd(), 50);
63-
return this.props.logs.map(l => l.replace(/\s+$/, '')).join('\n');
77+
return this.props.logs;
6478
}
6579

6680
render() {
@@ -73,7 +87,7 @@ class LogOutput extends Component {
7387
}
7488

7589
LogOutput.propTypes = {
76-
logs: PropTypes.array.isRequired,
90+
logs: PropTypes.string.isRequired,
7791
};
7892

7993
export default observer(CLIView);

stories/screen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,4 @@ store.logs = [
275275
'[14:00:33.731] [info] lnd: 2018-06-28 14:00:33.730 [INF] LTND: Primary chain is set to: bitcoin',
276276
'[14:00:33.879] [info] lnd: 2018-06-28 14:00:33.879 [INF] BTCN: Loaded 1032 addresses from file /home/valentine/.config/lightning-app/lnd/data/chain/bitcoin/testnet/peers.json',
277277
'[14:00:33.893] [info] lnd: 2018-06-28 14:00:33.892 [INF] CMGR: DNS discovery failed on seed x49.seed.tbtc.petertodd.org: lookup x49.seed.tbtc.petertodd.org: No address associated with hostname',
278-
];
278+
].join('\n');

test/unit/action/log.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ describe('Action Logs Unit Tests', () => {
5151

5252
describe('constructor()', () => {
5353
it('should keep logs trimmed and keep the tail of the logs', () => {
54-
for (var i = 0; i < 101; i++) {
54+
for (var i = 0; i < 10001; i++) {
5555
ipcRendererStub.emit('logs', 'some-event', i.toString());
5656
}
57-
expect(store.logs.length, 'to equal', 100);
58-
expect(store.logs[0], 'to equal', '1');
59-
expect(store.logs[99], 'to equal', '100');
57+
const len = store.logs.length;
58+
expect(store.logs.substring(len - 5, len), 'to equal', '10000');
59+
expect(store.logs.length, 'to equal', 10000);
6060
});
6161
});
6262
});
@@ -69,7 +69,7 @@ describe('Action Logs Unit Tests', () => {
6969

7070
describe('constructor()', () => {
7171
it('should append log on ipcRenderer logs event', () => {
72-
expect(store.logs[0], 'to equal', 'some-arg');
72+
expect(store.logs, 'to equal', '\nsome-arg');
7373
});
7474
});
7575

@@ -94,7 +94,7 @@ describe('Action Logs Unit Tests', () => {
9494
log.error('foo', err);
9595
expect(console.error, 'was called with', 'foo', err);
9696
sandbox.restore();
97-
expect(store.logs.length, 'to equal', 5);
97+
expect(store.logs.length, 'to equal', 25);
9898
expect(ipcRenderer.send, 'was called with', 'log-error', ['foo', err]);
9999
});
100100
});

0 commit comments

Comments
 (0)