Skip to content

Commit

Permalink
Add feature to view admin_audit log files
Browse files Browse the repository at this point in the history
Add a LogFileProvider class that identifies the available log files
It checks if the admin_audit app is enabled, and fetches it's logfile
path.

Additionally, add ability for user to select the file they want to
view. The "Download logs" button now downloads the currently selected
log file.

Tested by enabling and disabling the admin_audit app

TODO: Update the commands to also use the chosen logfile

Fixes: #318
Signed-off-by: Abijeet <abijeetpatro@gmail.com>
  • Loading branch information
Abijeet committed Mar 28, 2021
1 parent 0ab708a commit bc87408
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 53 deletions.
2 changes: 2 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
['name' => 'log#get', 'url' => '/get', 'verb' => 'GET'],
['name' => 'log#poll', 'url' => '/poll', 'verb' => 'GET'],
['name' => 'log#search', 'url' => '/search', 'verb' => 'GET'],
['name' => 'log#download', 'url' => '/download', 'verb' => 'GET'],
['name' => 'log#getSettings', 'url' => '/settings', 'verb' => 'GET'],
['name' => 'log#getLevels', 'url' => '/levels', 'verb' => 'GET'],
['name' => 'log#setLevels', 'url' => '/levels', 'verb' => 'PUT'],
['name' => 'log#setRelative', 'url' => '/relative', 'verb' => 'PUT'],
['name' => 'log#setLive', 'url' => '/live', 'verb' => 'PUT'],
['name' => 'log#setLogFile', 'url' => '/logFile', 'verb' => 'PUT']
]];
16 changes: 11 additions & 5 deletions build/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/main.js.map

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions js/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class App extends Component {
provider: null,
relative: true,
dateFormat: 'Y-m-d\TH:i:sO',
live: false
live: false,
availableLogFiles: []
};

constructor (props) {
Expand All @@ -43,11 +44,15 @@ export class App extends Component {
const relative = await this.logProvider.getRelative();
const dateFormat = await this.logProvider.getDateFormat();
const live = await this.logProvider.getLive();
const availableLogFiles = await this.logProvider.getAvailableLogFiles();
const logFile = await this.logProvider.getLogFile();
this.setState({
levels,
relative,
dateFormat,
live,
availableLogFiles,
logFile,
provider: this.logProvider
});
await this.logProvider.load();
Expand Down Expand Up @@ -76,7 +81,7 @@ export class App extends Component {
this.logProvider.load();
}

onLogFile = async (content) => {
onCustomLogFile = async (content) => {
const logFile = new LogFile(content);
logFile.on('entries', entries => {
if (this.state.provider === logFile) {
Expand Down Expand Up @@ -107,14 +112,22 @@ export class App extends Component {
this.saveLive(live);
};

async setLogFile (logFile) {
this.setState({logFile, loading: true});
await this.logProvider.setLogFile(logFile);
this.logProvider.reset();
this.logProvider.load();
this.setState({loading: false});
}

handlePaste = (event) => {
let data = event.clipboardData.getData('Text');
if (!data) {
data = event.clipboardData.getData('text/plain');
}
data = data.trim();
if (data.indexOf('{') !== -1 && data.indexOf('}')) {
this.onLogFile(data);
this.onCustomLogFile(data);
}
};

Expand Down Expand Up @@ -151,6 +164,7 @@ export class App extends Component {
isLoading={this.state.loading}>
<div className={styles.content}>
<LogTable
availableLogFiles={this.state.availableLogFiles}
inlineSettings={this.props.inlineSettings}
levels={this.state.levels}
setRelative={this.setRelative}
Expand All @@ -161,7 +175,9 @@ export class App extends Component {
hidden={this.state.entries.length - entries.length}
live={this.state.live}
setLive={this.setLive.bind(this)}
onLogFile={this.onLogFile}
logFile={this.state.logFile}
setLogFile={this.setLogFile.bind(this)}
onCustomLogFile={this.onCustomLogFile}
/>
</div>
</ReactScrolla>
Expand All @@ -172,7 +188,7 @@ export class App extends Component {
<div>
{!this.props.inlineSettings ?
<SideBar><LogUploader
onLogFile={this.onLogFile}/>
onCustomLogFile={this.onCustomLogFile}/>
<Separator/>
{filters}
<Settings>
Expand Down
6 changes: 5 additions & 1 deletion js/Components/LogTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,15 @@ export class LogTable extends Component {
{
this.state.showLevelSettings ?
<Settings
availableLogFiles={this.props.availableLogFiles}
setLevel={this.props.setLevel}
levels={this.props.levels}
live={this.props.live}
setLive={this.props.setLive}
onLogFile={this.props.onLogFile}
live={this.props.live}
setLogFile={this.props.setLogFile}
logFile={this.props.logFile}
onCustomLogFile={this.props.onCustomLogFile}
/> :
<div className="hidden"/>
}
Expand Down
2 changes: 1 addition & 1 deletion js/Components/LogUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class LogUploader extends Component {
this.setState({message: 'Invalid log file'});
return;
}
this.props.onLogFile(content);
this.props.onCustomLogFile(content);
};
reader.readAsText(file);
};
Expand Down
Loading

0 comments on commit bc87408

Please sign in to comment.