@@ -10,6 +10,7 @@ import { MAX_LOG_LENGTH } from '../config';
1010let _store ;
1111let _ipc ;
1212let _printErrObj ;
13+ let _FS ;
1314
1415/**
1516 * Log an info event e.g. when something relevant but non-critical happens.
@@ -49,6 +50,29 @@ export function error(...args) {
4950 _ipc && _ipc . send ( 'log-error' , null , args ) ;
5051}
5152
53+ /**
54+ * Gets the location of the LND log file as a string.
55+ * @param {string } network The network the user's on
56+ * @return {string }
57+ */
58+ export function getLogPath ( network ) {
59+ const lndDir = _FS . DocumentDirectoryPath ;
60+ return `${ lndDir } /logs/bitcoin/${ network } /lnd.log` ;
61+ }
62+
63+ /**
64+ * Retrieves the entire LND log file as a string.
65+ * @return {Promise }
66+ */
67+ export function getLogs ( ) {
68+ if ( ! _FS ) {
69+ return Promise . reject (
70+ 'Cannot get logs when no filesystem is available in action/log.js'
71+ ) ;
72+ }
73+ return _FS . readFile ( getLogPath ( _store . network ) , 'utf8' ) ;
74+ }
75+
5276function pushLogs ( message ) {
5377 if ( ! _store ) return ;
5478 _store . logs += '\n' + message . replace ( / \s + $ / , '' ) ;
@@ -59,10 +83,11 @@ function pushLogs(message) {
5983}
6084
6185class LogAction {
62- constructor ( store , ipc , printErrObj = true ) {
86+ constructor ( store , ipc , printErrObj = true , FS ) {
6387 _store = store ;
6488 _ipc = ipc ;
6589 _printErrObj = printErrObj ;
90+ _FS = FS ;
6691 _ipc . listen ( 'logs' , ( event , message ) => pushLogs ( message ) ) ;
6792 _ipc . send ( 'logs-ready' , null , true ) ;
6893 }
0 commit comments