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

Commit ce33e4c

Browse files
authored
Merge pull request #420 from lightninglabs/cli-logs
Cli logs
2 parents 4552063 + 05caef1 commit ce33e4c

File tree

10 files changed

+119
-4
lines changed

10 files changed

+119
-4
lines changed

src/action/log.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class LogAction {
1515
_ipcRenderer = ipcRenderer;
1616
_ipcRenderer.on('logs', (event, arg) => {
1717
store.logs.push(arg);
18+
if (store.logs.length > 100) {
19+
store.logs.splice(0, store.logs.length - 100);
20+
}
1821
});
1922
_ipcRenderer.send('logs-ready', true);
2023
}

src/action/nav.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class NavAction {
113113
}
114114

115115
goCLI() {
116-
// this._store.route = 'CLI';
116+
this._store.route = 'CLI';
117117
}
118118

119119
goCreateChannel() {

src/component/list.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ export class List extends Component {
5353
render() {
5454
return (
5555
<ListView
56+
ref={component => (this.list = component)}
5657
dataSource={this.dataSource}
5758
renderHeader={this.props.renderHeader}
58-
renderRow={this.props.renderItem}
59+
renderRow={data => {
60+
this.props.scrollToEnd
61+
? setTimeout(() => this.list._scrollViewRef.scrollToEnd(), 50)
62+
: null;
63+
return this.props.renderItem(data);
64+
}}
5965
enableEmptySections={true}
6066
/>
6167
);
@@ -66,6 +72,7 @@ List.propTypes = {
6672
data: PropTypes.array.isRequired,
6773
renderHeader: PropTypes.func,
6874
renderItem: PropTypes.func.isRequired,
75+
scrollToEnd: PropTypes.bool,
6976
};
7077

7178
//

src/component/style.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const color = {
3030
notifyLight: 'rgba(255,255,255,0.5)',
3131
seedBorder: 'rgba(151,151,151,0.26)',
3232
seedBackground: 'rgba(130,129,129,0.09)',
33+
cliBackground: '#171D2C',
3334
};
3435

3536
export const font = {

src/view/cli.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from 'react';
2+
import { StyleSheet } from 'react-native';
3+
import { observer } from 'mobx-react';
4+
import PropTypes from 'prop-types';
5+
import Background from '../component/background';
6+
import { Header, Title } from '../component/header';
7+
import Text from '../component/text';
8+
import { List, ListContent } from '../component/list';
9+
import { Button, BackButton } from '../component/button';
10+
import { color, font } from '../component/style';
11+
12+
//
13+
// CLI View
14+
//
15+
16+
const CLIView = ({ store, nav }) => (
17+
<Background color={color.blackDark}>
18+
<Header separator>
19+
<BackButton onPress={() => nav.goSettings()} />
20+
<Title title="Logs" />
21+
<Button disabled onPress={() => {}} />
22+
</Header>
23+
<Background color={color.cliBackground}>
24+
<ListContent>
25+
<List
26+
data={store.logs.slice()}
27+
renderItem={text => <LogItem text={text} />}
28+
scrollToEnd={true}
29+
/>
30+
</ListContent>
31+
</Background>
32+
</Background>
33+
);
34+
35+
CLIView.propTypes = {
36+
store: PropTypes.object.isRequired,
37+
nav: PropTypes.object.isRequired,
38+
};
39+
40+
const iStyles = StyleSheet.create({
41+
text: {
42+
textAlign: 'left',
43+
fontSize: font.sizeS,
44+
},
45+
});
46+
47+
const LogItem = ({ text }) => <Text style={iStyles.text}>{text}</Text>;
48+
49+
LogItem.propTypes = {
50+
text: PropTypes.string,
51+
};
52+
53+
export default observer(CLIView);

src/view/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import Setting from './setting';
3030
import SettingUnit from './setting-unit';
3131
import SettingFiat from './setting-fiat';
3232
import Notification from './notification';
33+
import CLI from './cli';
3334
import TransactionDetail from './transaction-detail';
3435
import {
3536
nav,
@@ -85,6 +86,7 @@ class MainView extends Component {
8586
<SettingFiat store={store} nav={nav} setting={setting} />
8687
)}
8788
{route === 'Notifications' && <Notification store={store} nav={nav} />}
89+
{route === 'CLI' && <CLI store={store} nav={nav} />}
8890
{route === 'Pay' && (
8991
<Payment store={store} payment={payment} nav={nav} />
9092
)}

src/view/setting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const SettingView = ({ store, nav }) => {
5656
arrow
5757
/>
5858
<SettingHeader name="ADVANCED" style={styles.advanced} />
59-
<SettingItem name="CLI" onSelect={() => nav.goCLI()} arrow />
59+
<SettingItem name="Logs" onSelect={() => nav.goCLI()} arrow />
6060
</MainContent>
6161
</Background>
6262
);

stories/screen.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Transaction from '../src/view/transaction';
1919
import Setting from '../src/view/setting';
2020
import SettingUnit from '../src/view/setting-unit';
2121
import SettingFiat from '../src/view/setting-fiat';
22+
import CLI from '../src/view/cli';
2223
import Notification from '../src/view/notification';
2324
import TransactionDetail from '../src/view/transaction-detail';
2425
import Channel from '../src/view/channel';
@@ -111,6 +112,7 @@ storiesOf('Screens', module)
111112
<SettingFiat store={store} nav={nav} setting={setting} />
112113
))
113114
.add('Notifications', () => <Notification store={store} nav={nav} />)
115+
.add('CLI', () => <CLI store={store} nav={nav} />)
114116
.add('Transactions', () => (
115117
<Transaction store={store} transaction={transaction} nav={nav} />
116118
))
@@ -244,3 +246,27 @@ store.seedMnemonic = [
244246
'quit',
245247
'cashew',
246248
];
249+
store.logs = [
250+
'[14:00:24.995] [info] Using lnd in path lnd',
251+
'Checking for update',
252+
'[14:00:25.047] [info] lnd: 2018-06-28 14:00:25.039 [WRN] LTND: open /home/valentine/.config/lightning-app/lnd/lnd.conf: no such file or directory',
253+
'2018-06-28 14:00:25.039 [INF] LTND: Version 0.4.2-beta commit=884c51dfdc85284ba8d063c4547d2b5665eba010',
254+
'2018-06-28 14:00:25.039 [INF] LTND: Active chain: Bitcoin (network=testnet)',
255+
'2018-06-28 14:00:25.039 [INF] CHDB: Checking for schema update: latest_version=1, db_version=1',
256+
'[14:00:25.170] [info] lnd: 2018-06-28 14:00:25.055 [INF] RPCS: password RPC server listening on 127.0.0.1:10009',
257+
'2018-06-28 14:00:25.055 [INF] RPCS: password gRPC proxy started at 127.0.0.1:8080',
258+
'2018-06-28 14:00:25.055 [INF] LTND: Waiting for wallet encryption password. Use `lncli create` to create a wallet, `lncli unlock` to unlock an existing wallet, or `lncli changepassword` to change the password of an existing wallet and unlock it.',
259+
'[14:00:25.541] [info] Loaded initial state',
260+
'[14:00:25.557] [info] GRPC unlockerReady',
261+
'Found version 0.2.0-prealpha.9 (url: Lightning-linux-x86_64v0.2.0-prealpha.9.AppImage)',
262+
'Downloading update from Lightning-linux-x86_64v0.2.0-prealpha.9.AppImage',
263+
'No cached update available',
264+
'File has 2893 changed blocks',
265+
'Full: 106,265.24 KB, To download: 59,575.39 KB (56%)',
266+
'Differential download: https://github.com/lightninglabs/lightning-app/releases/download/v0.2.0-prealpha.9/Lightning-linux-x86_64v0.2.0-prealpha.9.AppImage',
267+
'Redirect to https://github-production-release-asset-2e65be.s3.amazonaws.com/76898197/428914b4-7561-11e8-8826-08fde1bd29aa',
268+
'[14:00:33.730] [info] lnd: 2018-06-28 14:00:33.730 [INF] LNWL: Opened wallet',
269+
'[14:00:33.731] [info] lnd: 2018-06-28 14:00:33.730 [INF] LTND: Primary chain is set to: bitcoin',
270+
'[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',
271+
'[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',
272+
];

test/unit/action/log.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Store } from '../../../src/store';
2+
import { EventEmitter } from 'events';
23
import * as log from '../../../src/action/log';
34
import LogAction from '../../../src/action/log';
45

@@ -38,6 +39,28 @@ describe('Action Logs Unit Tests', () => {
3839
});
3940
});
4041

42+
describe('constructor', () => {
43+
let ipcRendererStub;
44+
45+
beforeEach(() => {
46+
store = new Store();
47+
ipcRendererStub = new EventEmitter();
48+
ipcRendererStub.send = sinon.stub();
49+
new LogAction(store, ipcRendererStub);
50+
});
51+
52+
describe('constructor()', () => {
53+
it('should keep logs trimmed to 100 and keep the tail of the logs', () => {
54+
for (var i = 0; i < 101; i++) {
55+
ipcRendererStub.emit('logs', 'some-event', i.toString());
56+
}
57+
expect(store.logs.length, 'to equal', 100);
58+
expect(store.logs[0], 'to equal', '1');
59+
expect(store.logs[99], 'to equal', '100');
60+
});
61+
});
62+
});
63+
4164
describe('with constructor', () => {
4265
beforeEach(() => {
4366
store = new Store();

test/unit/action/nav.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe('Action Nav Unit Tests', () => {
200200
});
201201
});
202202

203-
describe.skip('goCLI()', () => {
203+
describe('goCLI()', () => {
204204
it('should set correct route', () => {
205205
nav.goCLI();
206206
expect(store.route, 'to equal', 'CLI');

0 commit comments

Comments
 (0)