Commit ae0e6f9d authored by Amaury Martiny's avatar Amaury Martiny
Browse files

Make debug work across packages

parent 4ee1b308
......@@ -49,6 +49,7 @@
"start": "npm-run-all -l -p start-*",
"start-electron": "cd packages/fether-electron && yarn start",
"start-hoc": "cd packages/light-hoc && yarn start",
"start-parity-electron": "cd packages/parity-electron && yarn start",
"start-react": "cd packages/fether-react && yarn start",
"start-ui": "cd packages/fether-ui && yarn start",
"test": "lerna run test --parallel"
......
......@@ -37,6 +37,7 @@ function createWindow () {
// Set options for @parity/electron
parityElectron({
cli,
logger: namespace => log => Pino({ name: namespace }).info(log),
parityChannel: parity.channel
});
......
......@@ -53,7 +53,7 @@ class AccountsList extends Component {
history.push('/tokens', { address });
})
.catch(err =>
debug('AccountsList')(`Error while selecting account, ${err.message}.`)
logger()('AccountsList')(`Error while selecting account, ${err.message}.`)
);
};
......
......@@ -12,7 +12,7 @@ import store from 'store';
import Debug from '../utils/debug';
import LS_PREFIX from './utils/lsPrefix';
const debug = Debug('sendStore');
const debug = logger()('sendStore');
const electron = isElectron() ? window.require('electron') : null;
const LS_KEY = `${LS_PREFIX}::secureToken`;
......@@ -31,7 +31,7 @@ class ParityStore {
}
if (!electron) {
debug(
logger()(
'Not in Electron, ParityStore will only have limited capabilities.'
);
return;
......
......@@ -15,7 +15,7 @@ import Debug from '../utils/debug';
import parityStore from './parityStore';
import tokensStore from './tokensStore';
const debug = Debug('sendStore');
const debug = logger()('sendStore');
const DEFAULT_GAS = new BigNumber(21000); // Default gas amount to show
const GAS_MULT_FACTOR = 1.33; // Since estimateGas is not always accurate, we add a 33% factor for buffer.
......@@ -111,7 +111,7 @@ class SendStore {
this.txForErc20.options
);
debug(
logger()(
'Sending tx.',
this.tokenAddress === 'ETH' ? this.txForEth : this.txForErc20
);
......@@ -125,7 +125,7 @@ class SendStore {
.catch(reject);
}
this.setTxStatus(txStatus);
debug('Tx status updated.', txStatus);
logger()('Tx status updated.', txStatus);
});
});
};
......
......@@ -11,8 +11,8 @@ import fs from 'fs';
import { promisify } from 'util';
import retry from 'async-retry';
import debug from './utils/debug';
import { defaultParityPath, getParityPath } from './getParityPath';
import logger from './utils/logger';
import parityChannel from './utils/parityChannel';
const checksum = promisify(cs.file);
......@@ -70,7 +70,7 @@ export const fetchParity = (mainWindow, onProgress) => {
return retry(
async (_, attempt) => {
if (attempt > 1) {
debug('main')('Retrying.');
logger()('@parity/electron:main')('Retrying.');
}
// Delete any old Parity if it exists
......@@ -78,7 +78,7 @@ export const fetchParity = (mainWindow, onProgress) => {
// Fetch the metadata of the correct version of parity
const metadataUrl = `${VANITY_URL}?version=${parityChannel()}&os=${getOs()}&architecture=${getArch()}`;
debug('main')(`Downloading from ${metadataUrl}.`);
logger()('@parity/electron:main')(`Downloading from ${metadataUrl}.`);
const { data } = await axios.get(metadataUrl);
// Get the binary's url
......
......@@ -9,7 +9,7 @@ import fs from 'fs';
import promiseAny from 'promise-any';
import { promisify } from 'util';
import debug from './utils/debug';
import logger from './utils/logger';
const fsStat = promisify(fs.stat);
......@@ -96,10 +96,12 @@ export const getParityPath = async () => {
try {
const path = await doesParityExist();
parityPath = path; // Save the final result in module variable
debug('main')(`Parity found on machine, can be run with "${path}".`);
logger()('@parity/electron:main')(
`Parity found on machine, can be run with "${path}".`
);
return path;
} catch (err) {
debug('main')(`Parity not found on machine.`);
logger()('@parity/electron:main')(`Parity not found on machine.`);
throw err;
}
};
......@@ -4,6 +4,7 @@
// SPDX-License-Identifier: BSD-3-Clause
import { setCli } from './utils/cli';
import { setLogger } from './utils/logger';
import { setParityChannel } from './utils/parityChannel';
export * from './getParityPath';
......@@ -18,6 +19,10 @@ export default opts => {
setCli(opts.cli);
}
if (opts.logger) {
setLogger(opts.logger);
}
if (opts.parityChannel) {
setParityChannel(opts.parityChannel);
}
......
......@@ -7,7 +7,7 @@ import axios from 'axios';
import retry from 'async-retry';
import { cli } from './utils/cli';
import debug from './utils/debug';
import logger from './utils/logger';
// Try to ping these hosts
const hostsToPing = ['http://127.0.0.1:8545', 'http://127.0.0.1:8546'];
......@@ -31,7 +31,7 @@ export const isParityRunning = async () => {
async (_, attempt) => {
const host = hostsToPing[attempt - 1]; // Attempt starts with 1
await axios.get(host);
debug('main')(
logger()('@parity/electron:main')(
`Another instance of parity is already running on ${host}, skip running local instance.`
);
},
......
......@@ -9,10 +9,10 @@ import { spawn } from 'child_process';
import { promisify } from 'util';
import { cli, parityArgv } from './utils/cli';
import debug from './utils/debug';
import { getParityPath } from './getParityPath';
import { isParityRunning } from './isParityRunning';
import logCommand from './utils/logCommand';
import logger from './utils/logger';
const fsChmod = promisify(fs.chmod);
......@@ -52,14 +52,14 @@ export const runParity = async onParityError => {
// Run an instance of parity with the correct args
const args = [...parityArgv(), '--light'];
parity = spawn(parityPath, args);
debug('main')(logCommand(parityPath, args));
logger()('@parity/electron:main')(logCommand(parityPath, args));
// Save in memory the last line of the log file, for handling error
const callback = data => {
if (data && data.length) {
logLastLine = data.toString();
}
debug('parity')(data.toString());
logger()('@parity/parity')(data.toString());
};
parity.stdout.on('data', callback);
parity.stderr.on('data', callback);
......@@ -80,7 +80,7 @@ export const runParity = async onParityError => {
logLastLine &&
catchableErrors.some(error => logLastLine.includes(error))
) {
debug('main')(
logger()('@parity/electron:main')(
'Another instance of parity is running, closing local instance.'
);
return;
......@@ -97,7 +97,7 @@ export const runParity = async onParityError => {
export const killParity = () => {
if (parity) {
debug('Stopping parity.');
logger()('Stopping parity.');
parity.kill();
parity = null;
}
......
......@@ -5,22 +5,24 @@
import { spawn } from 'child_process';
import debug from './utils/debug';
import { getParityPath } from './getParityPath';
import logCommand from './utils/logCommand';
import logger from './utils/logger';
/**
* Launch a parity instance to get a secure token.
*/
export const signerNewToken = () =>
new Promise(async (resolve, reject) => {
debug('main')('Requesting new token.');
logger()('@parity/electron:main')('Requesting new token.');
const parityPath = await getParityPath();
// Generate a new token
const paritySigner = spawn(parityPath, ['signer', 'new-token']);
debug('main')(logCommand(parityPath, ['signer', 'new-token']));
logger()('@parity/electron:main')(
logCommand(parityPath, ['signer', 'new-token'])
);
// Listen to the output of the previous command
paritySigner.stdout.on('data', data => {
......@@ -34,7 +36,7 @@ export const signerNewToken = () =>
if (match) {
const token = match[0];
paritySigner.kill(); // We don't need the signer anymore
debug('main')('Successfully extracted token.');
logger()('@parity/electron:main')('Successfully extracted token.');
resolve(token);
}
});
......
......@@ -5,6 +5,10 @@
import debug from 'debug';
import { name } from '../../package.json';
let logger = debug;
export default namespace => debug(`${name}:${namespace}`);
export const setLogger = _logger => {
logger = _logger;
};
export default () => logger;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment