diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 1b49e1537..1989d4e98 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -99,11 +99,12 @@ export const commands = { export const PROCESS_LOGS = createRequestTypes('PROCESS_LOGS'); export const processLogs = { - request: (processName) => action(PROCESS_LOGS[REQUEST], {processName}), + request: (processName, limit) => action(PROCESS_LOGS[REQUEST], {processName, limit}), success: (processLogs, payload) => { return action(PROCESS_LOGS[SUCCESS], - { - processLogs: [ + { + ws: !!payload.ws, + processLogs: [ { process: payload.processName, timestamp: new Date().getTime(), diff --git a/embark-ui/src/components/Console.js b/embark-ui/src/components/Console.js index eb6574cfd..b8dd1592c 100644 --- a/embark-ui/src/components/Console.js +++ b/embark-ui/src/components/Console.js @@ -46,7 +46,7 @@ class Console extends Component { renderCommandsResult(){ const {commands} = this.props; return ( - this.state.selectedProcess === DEFAULT_PROCESS && + this.props.isEmbark() && commands.map((command, index) => { return ; }) @@ -57,8 +57,8 @@ class Console extends Component { const {processes} = this.props; return processes .sort((a, b) => { // ensure the "Embark" tab is displayed first - if (a.name === DEFAULT_PROCESS) return -1; - if (b.name === DEFAULT_PROCESS) return 1; + if (a.name === 'embark') return -1; + if (b.name === 'embark') return 1; return 0; }) .map(process => ( diff --git a/embark-ui/src/containers/HomeContainer.js b/embark-ui/src/containers/HomeContainer.js index f35668529..9c13b6b96 100644 --- a/embark-ui/src/containers/HomeContainer.js +++ b/embark-ui/src/containers/HomeContainer.js @@ -9,7 +9,8 @@ import Processes from '../components/Processes'; import Console from '../components/Console'; import {getProcesses, getCommands, getProcessLogs} from "../reducers/selectors"; -const EMBARK_PROCESS_NAME = 'Embark'; +const EMBARK_PROCESS_NAME = 'embark'; +const LOG_LIMIT = 50; class HomeContainer extends Component { constructor(props) { @@ -30,8 +31,8 @@ class HomeContainer extends Component { this.props.stopProcessLogs(this.state.activeProcess) } + this.props.fetchProcessLogs(processName, LOG_LIMIT); if (processName !== EMBARK_PROCESS_NAME) { - this.props.fetchProcessLogs(processName); this.props.listenToProcessLogs(processName); } diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index d07177d45..e90027508 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -1,6 +1,6 @@ import {combineReducers} from 'redux'; import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE, - FETCH_CREDENTIALS, UPDATE_BASE_ETHER} from "../actions"; + FETCH_CREDENTIALS, UPDATE_BASE_ETHER, PROCESS_LOGS} from "../actions"; const BN_FACTOR = 10000; const VOID_ADDRESS = '0x0000000000000000000000000000000000000000'; @@ -103,6 +103,12 @@ const filtrer = { }; function entities(state = entitiesDefaultState, action) { + if (action.type === PROCESS_LOGS[SUCCESS] && action.ws === true){ + const process = action.processLogs[0].process; + let processLogs = state.processLogs.filter(logs => logs.process === process).sort((a, b) => b.timestamp - a.timestamp)[0]; + processLogs.logs.push(action.processLogs[0].logs[0]); + return {...state}; + } if (action.type === FILES[SUCCESS]) { return {...state, files: action.files}; } diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index fea051dfe..650f6237f 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -241,7 +241,7 @@ export function *listenToProcessLogs(action) { return; } - yield put(actions.processLogs.success([processLog])); + yield put(actions.processLogs.success([processLog], {processName: action.processName, ws: true})); } } diff --git a/embark-ui/src/services/api.js b/embark-ui/src/services/api.js index d96fcf4d7..e79ee8e54 100644 --- a/embark-ui/src/services/api.js +++ b/embark-ui/src/services/api.js @@ -56,7 +56,7 @@ export function fetchProcesses() { } export function fetchProcessLogs(payload) { - return get(`/process-logs/${payload.processName}`, ...arguments); + return get(`/process-logs/${payload.processName}`, {params: payload, processName: payload.processName, credentials: payload.credentials}); } export function fetchContractLogs() { diff --git a/lib/core/logger.js b/lib/core/logger.js index d8ad9216e..85676bdbb 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -55,7 +55,7 @@ class Logger { } // if 'limit' is specified, get log lines from the end of the log file - if(limit && logs.length > limit){ + if(limit && limit > 0 && logs.length > limit){ logs.slice(limit * -1); } return logs; diff --git a/lib/modules/logger_api/index.js b/lib/modules/logger_api/index.js index 238fd7aba..703883d5e 100644 --- a/lib/modules/logger_api/index.js +++ b/lib/modules/logger_api/index.js @@ -11,7 +11,9 @@ class LoggerApi { 'get', '/embark-api/process-logs/embark', (req, res) => { - res.send(this.logger.parseLogFile(req.query.limit)); + let limit = parseInt(req.query.limit, 10); + if(!Number.isInteger(limit)) limit = 0; + res.send(this.logger.parseLogFile(limit)); } ); }