Skip to content

Commit 7fa4102

Browse files
authored
Merge pull request #60 from oslabs-beta/drew/process-logs-alerts
Drew/process logs alerts
2 parents d343f30 + 8d10be9 commit 7fa4102

File tree

3 files changed

+60
-35
lines changed

3 files changed

+60
-35
lines changed

src/components/display/ProcessLogsTable.tsx

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { useEffect, useState } from "react";
2-
import { useDispatch } from "react-redux";
3-
import { buildOptionsObj } from "../helper/processLogHelper";
4-
import { getLogs } from "../helper/commands";
5-
import * as actions from "../../redux/actions/actions";
6-
import "./ProcessLogsCard";
1+
import React, { useEffect, useState } from 'react';
2+
import { useDispatch } from 'react-redux';
3+
import { buildOptionsObj } from '../helper/processLogHelper';
4+
import { getLogs } from '../helper/commands';
5+
import * as actions from '../../redux/actions/actions';
6+
import './ProcessLogsCard';
77

88
import store from "../../renderer/store";
99
import { DataGrid } from "@mui/x-data-grid";
@@ -25,7 +25,7 @@ const ProcessLogsTable = () => {
2525

2626
// grab clicked container
2727
const urlString = window.location.href;
28-
const containerID = urlString.split("/");
28+
const containerID = urlString.split('/');
2929
const id = containerID[containerID.length - 1];
3030

3131
// access runningList from state - store has issue with runningList, ignore until updated
@@ -36,7 +36,7 @@ const ProcessLogsTable = () => {
3636
const [rows, setRows] = useState([]);
3737

3838
const [csvData, setCsvData] = useState([
39-
["container", "type", "time", "message"],
39+
['container', 'type', 'time', 'message'],
4040
]);
4141

4242
const [logs, setLogs] = useState({ stdout: [], stderr: [] });
@@ -63,10 +63,10 @@ const ProcessLogsTable = () => {
6363
};
6464

6565
const columns = [
66-
{ field: "container", headerName: "Container", width: 150 },
67-
{ field: "type", headerName: "Log Type", width: 120 },
68-
{ field: "time", headerName: "Timestamp", width: 200 },
69-
{ field: "message", headerName: "Message", width: 550 },
66+
{ field: 'container', headerName: 'Container', width: 150 },
67+
{ field: 'type', headerName: 'Log Type', width: 120 },
68+
{ field: 'time', headerName: 'Timestamp', width: 200 },
69+
{ field: 'message', headerName: 'Message', width: 550 },
7070
];
7171

7272
const createContainerCheckboxes = (currId: string) => {
@@ -142,12 +142,12 @@ const ProcessLogsTable = () => {
142142
);
143143
newRows.push({
144144
container: currCont.Name,
145-
type: "stdout",
146-
time: log["timeStamp"],
147-
message: log["logMsg"],
145+
type: 'stdout',
146+
time: log['timeStamp'],
147+
message: log['logMsg'],
148148
id: Math.random() * 100,
149149
});
150-
newCSV.push([currCont.Name, "stdout", log["timeStamp"], log["logMsg"]]);
150+
newCSV.push([currCont.Name, 'stdout', log['timeStamp'], log['logMsg']]);
151151
});
152152

153153
stderr.forEach((log, index) => {
@@ -156,16 +156,16 @@ const ProcessLogsTable = () => {
156156
);
157157
newRows.push({
158158
container: currCont.Name,
159-
type: "stderr",
160-
time: log["timeStamp"],
161-
message: log["logMsg"],
159+
type: 'stderr',
160+
time: log['timeStamp'],
161+
message: log['logMsg'],
162162
id: parseInt(`stderr ${index}`),
163163
});
164-
newCSV.push([currCont.Name, "stderr", log["timeStamp"], log["logMsg"]]);
164+
newCSV.push([currCont.Name, 'stderr', log['timeStamp'], log['logMsg']]);
165165
});
166166

167167
setRows(newRows as keyof typeof setRows);
168-
setCsvData([["container", "type", "time", "message"], ...newCSV]);
168+
setCsvData([['container', 'type', 'time', 'message'], ...newCSV]);
169169
}
170170
};
171171

@@ -174,30 +174,54 @@ const ProcessLogsTable = () => {
174174
<div className="settings-container">
175175
<form>
176176
<h1 style={{ margin: 10 }}>Container Process Logs</h1>
177-
177+
<h3>
178+
<a
179+
style={{ margin: 5 }}
180+
target="_blank"
181+
rel="noreferrer"
182+
href="https://docs.docker.com/engine/reference/commandline/logs/"
183+
>
184+
Click here
185+
</a>{''}
186+
for more information on logs
187+
</h3>
188+
<br></br>
178189
<input
179190
style={{ margin: 5 }}
180191
type="radio"
181192
id="sinceInput"
182193
name="logOption"
183194
/>
184-
<label style={{ margin: 5 }} htmlFor="sinceInput">
195+
<label
196+
style={{ margin: 5 }}
197+
htmlFor="sinceInput"
198+
>
185199
Since
186200
</label>
187-
<input type="text" id="sinceText" />
201+
<input
202+
type="text"
203+
id="sinceText"
204+
/>
188205
<br></br>
189206
<input
190207
style={{ margin: 5 }}
191208
type="radio"
192209
id="tailInput"
193210
name="logOption"
194211
/>
195-
<label style={{ margin: 5 }} htmlFor="tailInput">
212+
<label
213+
style={{ margin: 5 }}
214+
htmlFor="tailInput"
215+
>
196216
Tail
197217
</label>
198-
<input style={{ marginLeft: 14 }} type="text" id="tailText" />
218+
<input
219+
style={{ marginLeft: 14 }}
220+
type="text"
221+
id="tailText"
222+
/>
199223

200-
<FormGroup style={{ display: "flex", flexDirection: "row" }}>
224+
<FormGroup style={{ display: 'flex', flexDirection: 'row' }}>
201225
{containerSelectors} {/** Checkboxes for running containers */}
202226
</FormGroup>
203227
<Button
@@ -226,9 +250,9 @@ const ProcessLogsTable = () => {
226250
>
227251
<CSVLink
228252
style={{
229-
textDecoration: "none",
230-
color: "white",
231-
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
253+
textDecoration: 'none',
254+
color: 'white',
255+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
232256
}}
233257
data={csvData}
234258
>
@@ -239,16 +263,16 @@ const ProcessLogsTable = () => {
239263

240264
<div
241265
className="process-logs-container"
242-
style={{ height: 660, width: "100%" }}
266+
style={{ height: 660, width: '100%' }}
243267
>
244268
<DataGrid
245269
key="DataGrid"
246270
rows={rows}
247271
columns={columns}
248-
getRowHeight={() => "auto"}
272+
getRowHeight={() => 'auto'}
249273
initialState={{
250274
sorting: {
251-
sortModel: [{ field: "time", sort: "desc" }], // default sorts table by time
275+
sortModel: [{ field: 'time', sort: 'desc' }], // default sorts table by time
252276
},
253277
}}
254278
/>

src/components/helper/commands.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ export const getLogs = async (optionsObj, getContainerLogsDispatcher) => {
675675
// build inputCommandString to get logs from command line
676676
let inputCommandString = 'docker logs --timestamps ';
677677
if (optionsObj.since) {
678-
inputCommandString += `--since ${optionsObj.since} `;
678+
inputCommandString += `--since ${optionsObj.since} `;
679679
}
680680
optionsObj.tail
681681
? (inputCommandString += `--tail ${optionsObj.tail} `)
@@ -684,6 +684,7 @@ export const getLogs = async (optionsObj, getContainerLogsDispatcher) => {
684684

685685
window.nodeMethod.runExec(inputCommandString, (error: child_process.ExecException | null, stdout: string, stderr: string) => {
686686
if (error) {
687+
alert(`Please enter a valid rfc3339 date, Unix timestamp, or Go duration string.`);
687688
console.error(`exec error: ${error}`);
688689
return;
689690
}

src/components/tabs/ProcessLogs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const ProcessLogs = (props) => {
3131
return (
3232
<div className='renderContainers'>
3333
<div className='header'>
34-
<h1 className='tabTitle'>Procsess Logs</h1>
34+
<h1 className='tabTitle'>Process Logs</h1>
3535
</div>
3636

3737
<h3>Running Containers: {props.runningList.length}</h3>

0 commit comments

Comments
 (0)