2024-12-17 17:00:24 +03:00
|
|
|
import React, { ChangeEvent, FormEvent, useCallback, useEffect, useState } from 'react';
|
2024-12-17 15:55:15 +03:00
|
|
|
import type { LogFile } from '@jellyfin/sdk/lib/generated-client/models/log-file';
|
|
|
|
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
|
|
|
import { getSystemApi } from '@jellyfin/sdk/lib/utils/api/system-api';
|
|
|
|
import LogItem from 'components/dashboard/logs/LogItem';
|
|
|
|
import Loading from 'components/loading/LoadingComponent';
|
|
|
|
import Page from 'components/Page';
|
|
|
|
import { useApi } from 'hooks/useApi';
|
|
|
|
import globalize from 'lib/globalize';
|
2024-12-17 17:00:24 +03:00
|
|
|
import { Alert, Box, Button, FormControlLabel, Stack, Switch, TextField, Typography } from '@mui/material';
|
|
|
|
import { Form } from 'react-router-dom';
|
2024-12-17 15:55:15 +03:00
|
|
|
|
|
|
|
const Logs = () => {
|
|
|
|
const { api } = useApi();
|
|
|
|
const [ logs, setLogs ] = useState<LogFile[]>([]);
|
2024-12-17 17:00:24 +03:00
|
|
|
const [ logsLoading, setLogsLoading ] = useState<boolean>(true);
|
|
|
|
const [ configLoading, setConfigLoading ] = useState<boolean>(true);
|
|
|
|
const [ logWarningMessageChecked, setLogWarningMessageChecked ] = useState<boolean>(false);
|
|
|
|
const [ slowResponseTime, setSlowResponseTime ] = useState<string>('');
|
|
|
|
const [ submitted, setSubmitted ] = useState<boolean>(false);
|
|
|
|
|
|
|
|
const setLogWarningMessage = useCallback((_: ChangeEvent<HTMLInputElement>, checked: boolean) => {
|
|
|
|
setLogWarningMessageChecked(checked);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onResponseTimeChange = useCallback((event: ChangeEvent<HTMLTextAreaElement>) => {
|
|
|
|
setSlowResponseTime(event.target.value);
|
|
|
|
}, []);
|
2024-12-17 15:55:15 +03:00
|
|
|
|
|
|
|
const loadLogs = useCallback(() => {
|
|
|
|
if (!api) return;
|
|
|
|
|
|
|
|
return getSystemApi(api)
|
|
|
|
.getServerLogs()
|
|
|
|
.then(({ data }) => {
|
|
|
|
setLogs(data);
|
|
|
|
});
|
|
|
|
}, [api]);
|
|
|
|
|
|
|
|
const onSubmit = useCallback((e: FormEvent<HTMLFormElement>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
if (!api) return;
|
|
|
|
|
|
|
|
getConfigurationApi(api)
|
|
|
|
.getConfiguration()
|
|
|
|
.then(({ data: config }) => {
|
2024-12-17 17:00:24 +03:00
|
|
|
config.EnableSlowResponseWarning = logWarningMessageChecked;
|
|
|
|
config.SlowResponseThresholdMs = parseInt(slowResponseTime, 10);
|
2024-12-17 15:55:15 +03:00
|
|
|
getConfigurationApi(api)
|
|
|
|
.updateConfiguration({ serverConfiguration: config })
|
2024-12-17 17:00:24 +03:00
|
|
|
.then(() => setSubmitted(true))
|
2024-12-17 15:55:15 +03:00
|
|
|
.catch(err => {
|
|
|
|
console.error('[logs] failed to update configuration data', err);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error('[logs] failed to get configuration data', err);
|
|
|
|
});
|
2024-12-17 17:00:24 +03:00
|
|
|
}, [api, logWarningMessageChecked, slowResponseTime]);
|
2024-12-17 15:55:15 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!api) return;
|
|
|
|
|
|
|
|
loadLogs()?.then(() => {
|
2024-12-17 17:00:24 +03:00
|
|
|
setLogsLoading(false);
|
2024-12-17 15:55:15 +03:00
|
|
|
}).catch(err => {
|
|
|
|
console.error('[logs] An error occurred while fetching logs', err);
|
|
|
|
});
|
|
|
|
|
|
|
|
getConfigurationApi(api)
|
|
|
|
.getConfiguration()
|
|
|
|
.then(({ data: config }) => {
|
|
|
|
if (config.EnableSlowResponseWarning) {
|
2024-12-17 17:00:24 +03:00
|
|
|
setLogWarningMessageChecked(config.EnableSlowResponseWarning);
|
2024-12-17 15:55:15 +03:00
|
|
|
}
|
|
|
|
if (config.SlowResponseThresholdMs != null) {
|
2024-12-17 17:00:24 +03:00
|
|
|
setSlowResponseTime(String(config.SlowResponseThresholdMs));
|
2024-12-17 15:55:15 +03:00
|
|
|
}
|
2024-12-17 17:00:24 +03:00
|
|
|
setConfigLoading(false);
|
2024-12-17 15:55:15 +03:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error('[logs] An error occurred while fetching system config', err);
|
|
|
|
});
|
2024-12-17 17:00:24 +03:00
|
|
|
}, [logsLoading, configLoading, api, loadLogs]);
|
2024-12-17 15:55:15 +03:00
|
|
|
|
2024-12-17 17:00:24 +03:00
|
|
|
if (logsLoading || configLoading) {
|
2024-12-17 15:55:15 +03:00
|
|
|
return <Loading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page
|
|
|
|
id='logPage'
|
|
|
|
title={globalize.translate('TabLogs')}
|
|
|
|
className='mainAnimatedPage type-interior'
|
|
|
|
>
|
2024-12-17 17:00:24 +03:00
|
|
|
<Box className='content-primary'>
|
|
|
|
<Form className='logsForm' method='POST' onSubmit={onSubmit}>
|
|
|
|
<Stack spacing={3}>
|
|
|
|
<Typography variant='h1'>
|
|
|
|
{globalize.translate('TabLogs')}
|
|
|
|
</Typography>
|
|
|
|
|
|
|
|
{submitted && (
|
|
|
|
<Alert severity='success'>
|
|
|
|
{globalize.translate('SettingsSaved')}
|
|
|
|
</Alert>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<FormControlLabel
|
|
|
|
control={
|
|
|
|
<Switch
|
|
|
|
checked={logWarningMessageChecked}
|
|
|
|
onChange={setLogWarningMessage}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={globalize.translate('LabelSlowResponseEnabled')}
|
2024-12-17 15:55:15 +03:00
|
|
|
/>
|
|
|
|
|
2024-12-17 17:00:24 +03:00
|
|
|
<TextField
|
|
|
|
fullWidth
|
|
|
|
type='number'
|
|
|
|
label={globalize.translate('LabelSlowResponseTime')}
|
|
|
|
value={slowResponseTime}
|
|
|
|
onChange={onResponseTimeChange}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
type='submit'
|
|
|
|
size='large'
|
|
|
|
>
|
|
|
|
{globalize.translate('Save')}
|
|
|
|
</Button>
|
|
|
|
</Stack>
|
|
|
|
</Form>
|
2024-12-17 15:55:15 +03:00
|
|
|
<div className='serverLogs readOnlyContent'>
|
|
|
|
<div className='paperList'>
|
|
|
|
{logs.map(log => {
|
|
|
|
return <LogItem
|
|
|
|
key={log.Name}
|
|
|
|
logFile={log}
|
|
|
|
/>;
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-12-17 17:00:24 +03:00
|
|
|
</Box>
|
2024-12-17 15:55:15 +03:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Logs;
|