Merge pull request #13 from ApTx2012/feat/backend
Sync source to CNB / Sync Git ref (push) Skipped
Axolotl desktop CI / guardrails (push) Canceled after 0s
Axolotl desktop CI / desktop (macos-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (ubuntu-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (windows-latest) (push) Canceled after 0s
Axolotl desktop CI / website (push) Canceled after 0s
Repository checks / typos (push) Canceled after 0s
Repository checks / tombi (push) Canceled after 0s
Rust checks / shear (push) Canceled after 0s
Sync source to CNB / Sync Git ref (push) Skipped
Axolotl desktop CI / guardrails (push) Canceled after 0s
Axolotl desktop CI / desktop (macos-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (ubuntu-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (windows-latest) (push) Canceled after 0s
Axolotl desktop CI / website (push) Canceled after 0s
Repository checks / typos (push) Canceled after 0s
Repository checks / tombi (push) Canceled after 0s
Rust checks / shear (push) Canceled after 0s
feat: 导出启动器日志
This commit is contained in:
14 files changed
+831
-2
No files matched your search
@@ -0,0 +1,192 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { DownloadIcon, FolderOpenIcon, XIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Combobox,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
injectPopupNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { exportLauncherLogs, highlightInFolder } from '@/helpers/utils'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const popupNotificationManager = injectPopupNotificationManager()
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const exporting = ref(false)
|
||||||
|
const selectedRange = ref<'last30Minutes' | 'last2Hours' | 'all'>('last2Hours')
|
||||||
|
const selectedLevel = ref<'all' | 'debug' | 'info'>('all')
|
||||||
|
const includeSystemInfo = ref(true)
|
||||||
|
const includeInstanceLogs = ref(false)
|
||||||
|
const includeCrashAnalysis = ref(false)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.settings.logs.export.modal.title', defaultMessage: 'Export logs' },
|
||||||
|
description: {
|
||||||
|
id: 'app.settings.logs.export.modal.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose how much detail to include. Exported logs have access tokens, Minecraft tokens, and IP addresses replaced with placeholders.',
|
||||||
|
},
|
||||||
|
rangeLabel: { id: 'app.settings.logs.export.modal.range', defaultMessage: 'Time range' },
|
||||||
|
rangeLast30Minutes: {
|
||||||
|
id: 'app.settings.logs.export.modal.range.30-minutes',
|
||||||
|
defaultMessage: 'Last 30 minutes',
|
||||||
|
},
|
||||||
|
rangeLast2Hours: {
|
||||||
|
id: 'app.settings.logs.export.modal.range.2-hours',
|
||||||
|
defaultMessage: 'Last 2 hours',
|
||||||
|
},
|
||||||
|
rangeAll: { id: 'app.settings.logs.export.modal.range.all', defaultMessage: 'All sessions' },
|
||||||
|
levelLabel: { id: 'app.settings.logs.export.modal.level', defaultMessage: 'Log level' },
|
||||||
|
levelAll: { id: 'app.settings.logs.export.modal.level.all', defaultMessage: 'All levels' },
|
||||||
|
levelDebug: {
|
||||||
|
id: 'app.settings.logs.export.modal.level.debug',
|
||||||
|
defaultMessage: 'Debug and above',
|
||||||
|
},
|
||||||
|
levelInfo: { id: 'app.settings.logs.export.modal.level.info', defaultMessage: 'Info and above' },
|
||||||
|
extrasLabel: {
|
||||||
|
id: 'app.settings.logs.export.modal.extras',
|
||||||
|
defaultMessage: 'Additional information',
|
||||||
|
},
|
||||||
|
systemInfo: {
|
||||||
|
id: 'app.settings.logs.export.modal.system-info',
|
||||||
|
defaultMessage: 'System and environment summary',
|
||||||
|
},
|
||||||
|
instanceLogs: {
|
||||||
|
id: 'app.settings.logs.export.modal.instance-logs',
|
||||||
|
defaultMessage: 'Most recent instance log',
|
||||||
|
},
|
||||||
|
crashAnalysis: {
|
||||||
|
id: 'app.settings.logs.export.modal.crash-analysis',
|
||||||
|
defaultMessage: 'Crash analysis (when a crash is detected)',
|
||||||
|
},
|
||||||
|
cancel: { id: 'app.settings.logs.export.modal.cancel', defaultMessage: 'Cancel' },
|
||||||
|
confirm: { id: 'app.settings.logs.export.modal.confirm', defaultMessage: 'Export' },
|
||||||
|
exportedTitle: {
|
||||||
|
id: 'app.settings.logs.export.notification-title',
|
||||||
|
defaultMessage: 'Logs exported',
|
||||||
|
},
|
||||||
|
exportedText: {
|
||||||
|
id: 'app.settings.logs.export.notification-text',
|
||||||
|
defaultMessage: 'The log archive was saved to {path}',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const rangeOptions = computed(() => [
|
||||||
|
{ value: 'last30Minutes', label: formatMessage(messages.rangeLast30Minutes) },
|
||||||
|
{ value: 'last2Hours', label: formatMessage(messages.rangeLast2Hours) },
|
||||||
|
{ value: 'all', label: formatMessage(messages.rangeAll) },
|
||||||
|
])
|
||||||
|
|
||||||
|
const levelOptions = computed(() => [
|
||||||
|
{ value: 'all', label: formatMessage(messages.levelAll) },
|
||||||
|
{ value: 'debug', label: formatMessage(messages.levelDebug) },
|
||||||
|
{ value: 'info', label: formatMessage(messages.levelInfo) },
|
||||||
|
])
|
||||||
|
|
||||||
|
async function exportLogs() {
|
||||||
|
exporting.value = true
|
||||||
|
try {
|
||||||
|
const path = await exportLauncherLogs({
|
||||||
|
range: selectedRange.value,
|
||||||
|
level: selectedLevel.value,
|
||||||
|
includeSystemInfo: includeSystemInfo.value,
|
||||||
|
includeInstanceLogs: includeInstanceLogs.value,
|
||||||
|
includeCrashAnalysis: includeCrashAnalysis.value,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (path) {
|
||||||
|
modal.value?.hide()
|
||||||
|
popupNotificationManager.addPopupNotification({
|
||||||
|
title: formatMessage(messages.exportedTitle),
|
||||||
|
text: formatMessage(messages.exportedText, { path }),
|
||||||
|
type: 'success',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
label: formatMessage(commonMessages.openInFolderButton),
|
||||||
|
icon: FolderOpenIcon,
|
||||||
|
action: () => highlightInFolder(path).catch(handleError),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
exporting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
show: () => modal.value?.show(),
|
||||||
|
hide: () => modal.value?.hide(),
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal
|
||||||
|
ref="modal"
|
||||||
|
:header="formatMessage(messages.title)"
|
||||||
|
:closable="true"
|
||||||
|
:close-on-click-outside="true"
|
||||||
|
width="40rem"
|
||||||
|
scrollable
|
||||||
|
>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<p class="m-0">{{ formatMessage(messages.description) }}</p>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<span class="font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
formatMessage(messages.rangeLabel)
|
||||||
|
}}</span>
|
||||||
|
<Combobox
|
||||||
|
id="log-export-range"
|
||||||
|
v-model="selectedRange"
|
||||||
|
:name="formatMessage(messages.rangeLabel)"
|
||||||
|
:options="rangeOptions"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<span class="font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
formatMessage(messages.levelLabel)
|
||||||
|
}}</span>
|
||||||
|
<Combobox
|
||||||
|
id="log-export-level"
|
||||||
|
v-model="selectedLevel"
|
||||||
|
:name="formatMessage(messages.levelLabel)"
|
||||||
|
:options="levelOptions"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<span class="font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
formatMessage(messages.extrasLabel)
|
||||||
|
}}</span>
|
||||||
|
<Checkbox v-model="includeSystemInfo" :label="formatMessage(messages.systemInfo)" />
|
||||||
|
<Checkbox v-model="includeInstanceLogs" :label="formatMessage(messages.instanceLogs)" />
|
||||||
|
<Checkbox v-model="includeCrashAnalysis" :label="formatMessage(messages.crashAnalysis)" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<Button type="outlined" :disabled="exporting" @click="modal?.hide()"
|
||||||
|
><XIcon />
|
||||||
|
{{ formatMessage(messages.cancel) }}
|
||||||
|
</Button>
|
||||||
|
<Button type="colored" color="brand" :disabled="exporting" @click="exportLogs"
|
||||||
|
><DownloadIcon />
|
||||||
|
{{ formatMessage(messages.confirm) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { FolderOpenIcon, UploadIcon } from '@modrinth/assets'
|
||||||
|
import { Button, defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
import { showLauncherLogsFolder } from '@/helpers/utils'
|
||||||
|
|
||||||
|
import LogExportModal from './LogExportModal.vue'
|
||||||
|
import SettingsRow from './SettingsRow.vue'
|
||||||
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const exportModal = ref<InstanceType<typeof LogExportModal>>()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
exportTitle: { id: 'app.settings.logs.export.title', defaultMessage: 'Export logs' },
|
||||||
|
exportDescription: {
|
||||||
|
id: 'app.settings.logs.export.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Package launcher logs with an optional environment summary, instance log, and crash analysis.',
|
||||||
|
},
|
||||||
|
exportButton: { id: 'app.settings.logs.export.button', defaultMessage: 'Export logs…' },
|
||||||
|
openFolder: { id: 'app.settings.logs.open-folder', defaultMessage: 'Open logs folder' },
|
||||||
|
})
|
||||||
|
|
||||||
|
async function openLogsFolder() {
|
||||||
|
try {
|
||||||
|
await showLauncherLogsFolder()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<SettingsSection
|
||||||
|
:title="formatMessage(messages.exportTitle)"
|
||||||
|
:description="formatMessage(messages.exportDescription)"
|
||||||
|
title-id="settings-target-logs-export"
|
||||||
|
>
|
||||||
|
<SettingsRow stacked>
|
||||||
|
<template #label>
|
||||||
|
<span>{{ formatMessage(messages.exportTitle) }}</span>
|
||||||
|
</template>
|
||||||
|
<template #description>{{ formatMessage(messages.exportDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<Button type="colored" color="brand" @click="exportModal?.show()"
|
||||||
|
><UploadIcon />
|
||||||
|
{{ formatMessage(messages.exportButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button @click="openLogsFolder"
|
||||||
|
><FolderOpenIcon />
|
||||||
|
{{ formatMessage(messages.openFolder) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
|
<LogExportModal ref="exportModal" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -13,6 +13,7 @@ export type SettingsCategoryId =
|
|||||||
| 'updates'
|
| 'updates'
|
||||||
| 'about'
|
| 'about'
|
||||||
| 'feature-flags'
|
| 'feature-flags'
|
||||||
|
| 'logs'
|
||||||
|
|
||||||
export type SettingsGroupId = 'launcher' | 'game' | 'data-privacy' | 'support' | 'developer'
|
export type SettingsGroupId = 'launcher' | 'game' | 'data-privacy' | 'support' | 'developer'
|
||||||
|
|
||||||
@@ -116,6 +117,11 @@ export const settingsCategoryDefinitions: SettingsCategoryDefinition[] = [
|
|||||||
name: { id: 'app.settings.tabs.about', defaultMessage: 'About' },
|
name: { id: 'app.settings.tabs.about', defaultMessage: 'About' },
|
||||||
group: 'support',
|
group: 'support',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'logs',
|
||||||
|
name: { id: 'app.settings.tabs.logs', defaultMessage: 'Logs' },
|
||||||
|
group: 'support',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'feature-flags',
|
id: 'feature-flags',
|
||||||
name: {
|
name: {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
BotIcon,
|
BotIcon,
|
||||||
CoffeeIcon,
|
CoffeeIcon,
|
||||||
CpuIcon,
|
CpuIcon,
|
||||||
|
FileTextIcon,
|
||||||
GameIcon,
|
GameIcon,
|
||||||
GaugeIcon,
|
GaugeIcon,
|
||||||
InfoIcon,
|
InfoIcon,
|
||||||
@@ -78,6 +79,10 @@ const categoryContent: Record<SettingsCategoryId, Pick<SettingsCategory, 'icon'
|
|||||||
content: defineAsyncComponent(() => import('./UpdateSettings.vue')),
|
content: defineAsyncComponent(() => import('./UpdateSettings.vue')),
|
||||||
},
|
},
|
||||||
about: { icon: InfoIcon, content: defineAsyncComponent(() => import('./AboutSettings.vue')) },
|
about: { icon: InfoIcon, content: defineAsyncComponent(() => import('./AboutSettings.vue')) },
|
||||||
|
logs: {
|
||||||
|
icon: FileTextIcon,
|
||||||
|
content: defineAsyncComponent(() => import('./LogsSettings.vue')),
|
||||||
|
},
|
||||||
'feature-flags': {
|
'feature-flags': {
|
||||||
icon: ToggleRightIcon,
|
icon: ToggleRightIcon,
|
||||||
content: defineAsyncComponent(() => import('./FeatureFlagSettings.vue')),
|
content: defineAsyncComponent(() => import('./FeatureFlagSettings.vue')),
|
||||||
|
|||||||
@@ -384,6 +384,16 @@ export const settingsSearchEntries: SettingsSearchEntry[] = [
|
|||||||
categoryId: 'feature-flags',
|
categoryId: 'feature-flags',
|
||||||
label: message('settings.feature-flags.title', 'Feature flags'),
|
label: message('settings.feature-flags.title', 'Feature flags'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'logs-export',
|
||||||
|
categoryId: 'logs',
|
||||||
|
targetId: 'settings-target-logs-export',
|
||||||
|
label: message('app.settings.logs.export.title', 'Export logs'),
|
||||||
|
description: message(
|
||||||
|
'app.settings.logs.export.description',
|
||||||
|
'Package launcher logs with an optional environment summary, instance log, and crash analysis.',
|
||||||
|
),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export function validateSettingsSearchEntries(entries = settingsSearchEntries): string[] {
|
export function validateSettingsSearchEntries(entries = settingsSearchEntries): string[] {
|
||||||
|
|||||||
@@ -81,6 +81,38 @@ export async function exportErrorLogs(
|
|||||||
return await invoke('plugin:utils|export_error_logs', { outputPath, errorMessage })
|
return await invoke('plugin:utils|export_error_logs', { outputPath, errorMessage })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function exportLauncherLogs({
|
||||||
|
range = 'last2Hours',
|
||||||
|
level = 'all',
|
||||||
|
includeSystemInfo = true,
|
||||||
|
includeInstanceLogs = false,
|
||||||
|
includeCrashAnalysis = false,
|
||||||
|
fileNamePrefix = 'Starlight Launcher logs',
|
||||||
|
} = {}) {
|
||||||
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-')
|
||||||
|
const outputPath = await save({
|
||||||
|
defaultPath: `${fileNamePrefix} ${timestamp}.zip`,
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: 'ZIP archive',
|
||||||
|
extensions: ['zip'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!outputPath) return null
|
||||||
|
|
||||||
|
await invoke('plugin:utils|export_launcher_logs', {
|
||||||
|
outputPath,
|
||||||
|
range,
|
||||||
|
level,
|
||||||
|
includeSystemInfo,
|
||||||
|
includeInstanceLogs,
|
||||||
|
includeCrashAnalysis,
|
||||||
|
})
|
||||||
|
return outputPath
|
||||||
|
}
|
||||||
|
|
||||||
export async function createInstanceShortcut(instanceName, instanceId, options = {}) {
|
export async function createInstanceShortcut(instanceName, instanceId, options = {}) {
|
||||||
const outputPath = await save({
|
const outputPath = await save({
|
||||||
defaultPath: `Modrinth - ${instanceName}`,
|
defaultPath: `Modrinth - ${instanceName}`,
|
||||||
|
|||||||
@@ -11485,5 +11485,74 @@
|
|||||||
},
|
},
|
||||||
"app.remote-announcements.preview-action": {
|
"app.remote-announcements.preview-action": {
|
||||||
"message": "Visit website"
|
"message": "Visit website"
|
||||||
|
},
|
||||||
|
"app.settings.tabs.logs": {
|
||||||
|
"message": "Logs & diagnostics"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.title": {
|
||||||
|
"message": "Export logs"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.description": {
|
||||||
|
"message": "Package launcher logs with an optional environment summary, instance log, and crash analysis."
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.button": {
|
||||||
|
"message": "Export logs…"
|
||||||
|
},
|
||||||
|
"app.settings.logs.open-folder": {
|
||||||
|
"message": "Open logs folder"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.title": {
|
||||||
|
"message": "Export logs"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.description": {
|
||||||
|
"message": "Choose how much detail to include. Exported logs have access tokens, Minecraft tokens, and IP addresses replaced with placeholders."
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.range": {
|
||||||
|
"message": "Time range"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.range.30-minutes": {
|
||||||
|
"message": "Last 30 minutes"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.range.2-hours": {
|
||||||
|
"message": "Last 2 hours"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.range.all": {
|
||||||
|
"message": "All sessions"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.level": {
|
||||||
|
"message": "Log level"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.level.all": {
|
||||||
|
"message": "All levels"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.level.debug": {
|
||||||
|
"message": "Debug and above"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.level.info": {
|
||||||
|
"message": "Info and above"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.extras": {
|
||||||
|
"message": "Additional information"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.system-info": {
|
||||||
|
"message": "System and environment summary"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.instance-logs": {
|
||||||
|
"message": "Most recent instance log"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.crash-analysis": {
|
||||||
|
"message": "Crash analysis (when a crash is detected)"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.cancel": {
|
||||||
|
"message": "Cancel"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.modal.confirm": {
|
||||||
|
"message": "Export"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.notification-title": {
|
||||||
|
"message": "Logs exported"
|
||||||
|
},
|
||||||
|
"app.settings.logs.export.notification-text": {
|
||||||
|
"message": "The log archive was saved to {path}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11362,5 +11362,28 @@
|
|||||||
"app.settings.defaults.window-title.default-placeholder": { "message": "输入默认窗口标题..." },
|
"app.settings.defaults.window-title.default-placeholder": { "message": "输入默认窗口标题..." },
|
||||||
"app.action-bar.announcements": { "message": "公告" },
|
"app.action-bar.announcements": { "message": "公告" },
|
||||||
"app.remote-announcements.center-title": { "message": "公告" },
|
"app.remote-announcements.center-title": { "message": "公告" },
|
||||||
"app.remote-announcements.empty": { "message": "暂无公告" }
|
"app.remote-announcements.empty": { "message": "暂无公告" },
|
||||||
|
"app.settings.tabs.logs": { "message": "日志与诊断" },
|
||||||
|
"app.settings.logs.export.title": { "message": "导出日志" },
|
||||||
|
"app.settings.logs.export.description": { "message": "将启动器日志打包,可附带环境摘要、最近的实例日志与崩溃分析。" },
|
||||||
|
"app.settings.logs.export.button": { "message": "导出日志…" },
|
||||||
|
"app.settings.logs.open-folder": { "message": "打开日志文件夹" },
|
||||||
|
"app.settings.logs.export.modal.title": { "message": "导出日志" },
|
||||||
|
"app.settings.logs.export.modal.description": { "message": "选择要包含的详细程度。导出的日志会把访问令牌、Minecraft 令牌与 IP 地址替换为占位符。" },
|
||||||
|
"app.settings.logs.export.modal.range": { "message": "时间范围" },
|
||||||
|
"app.settings.logs.export.modal.range.30-minutes": { "message": "最近 30 分钟" },
|
||||||
|
"app.settings.logs.export.modal.range.2-hours": { "message": "最近 2 小时" },
|
||||||
|
"app.settings.logs.export.modal.range.all": { "message": "全部会话" },
|
||||||
|
"app.settings.logs.export.modal.level": { "message": "日志等级" },
|
||||||
|
"app.settings.logs.export.modal.level.all": { "message": "全部等级" },
|
||||||
|
"app.settings.logs.export.modal.level.debug": { "message": "DEBUG 及以上" },
|
||||||
|
"app.settings.logs.export.modal.level.info": { "message": "INFO 及以上" },
|
||||||
|
"app.settings.logs.export.modal.extras": { "message": "附加信息" },
|
||||||
|
"app.settings.logs.export.modal.system-info": { "message": "系统与环境摘要" },
|
||||||
|
"app.settings.logs.export.modal.instance-logs": { "message": "最近的实例日志" },
|
||||||
|
"app.settings.logs.export.modal.crash-analysis": { "message": "崩溃分析(检测到崩溃时)" },
|
||||||
|
"app.settings.logs.export.modal.cancel": { "message": "取消" },
|
||||||
|
"app.settings.logs.export.modal.confirm": { "message": "导出" },
|
||||||
|
"app.settings.logs.export.notification-title": { "message": "日志已导出" },
|
||||||
|
"app.settings.logs.export.notification-text": { "message": "日志压缩包已保存到 {path}" }
|
||||||
}
|
}
|
||||||
@@ -694,6 +694,7 @@ fn main() {
|
|||||||
"open_path",
|
"open_path",
|
||||||
"show_launcher_logs_folder",
|
"show_launcher_logs_folder",
|
||||||
"export_error_logs",
|
"export_error_logs",
|
||||||
|
"export_launcher_logs",
|
||||||
"show_app_db_backups_folder",
|
"show_app_db_backups_folder",
|
||||||
"progress_bars_list",
|
"progress_bars_list",
|
||||||
"get_opening_command",
|
"get_opening_command",
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub fn init<R: Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
|||||||
open_path,
|
open_path,
|
||||||
show_launcher_logs_folder,
|
show_launcher_logs_folder,
|
||||||
export_error_logs,
|
export_error_logs,
|
||||||
|
export_launcher_logs,
|
||||||
show_app_db_backups_folder,
|
show_app_db_backups_folder,
|
||||||
progress_bars_list,
|
progress_bars_list,
|
||||||
get_opening_command,
|
get_opening_command,
|
||||||
@@ -164,6 +165,312 @@ pub async fn export_error_logs(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Time window included in a launcher log export.
|
||||||
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub enum LogExportRange {
|
||||||
|
Last30Minutes,
|
||||||
|
Last2Hours,
|
||||||
|
All,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LogExportRange {
|
||||||
|
fn max_age(self) -> Option<std::time::Duration> {
|
||||||
|
match self {
|
||||||
|
Self::Last30Minutes => {
|
||||||
|
Some(std::time::Duration::from_secs(30 * 60))
|
||||||
|
}
|
||||||
|
Self::Last2Hours => {
|
||||||
|
Some(std::time::Duration::from_secs(2 * 60 * 60))
|
||||||
|
}
|
||||||
|
Self::All => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn label(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Last30Minutes => "last 30 minutes",
|
||||||
|
Self::Last2Hours => "last 2 hours",
|
||||||
|
Self::All => "all sessions",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Lowest level included in a launcher log export.
|
||||||
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub enum LogExportLevel {
|
||||||
|
All,
|
||||||
|
Debug,
|
||||||
|
Info,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LogExportLevel {
|
||||||
|
fn minimum(self) -> Option<&'static str> {
|
||||||
|
match self {
|
||||||
|
Self::All => None,
|
||||||
|
Self::Debug => Some("debug"),
|
||||||
|
Self::Info => Some("info"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn label(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::All => "all levels",
|
||||||
|
Self::Debug => "debug and above",
|
||||||
|
Self::Info => "info and above",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instance log tail included in an export, in bytes.
|
||||||
|
const LOG_EXPORT_INSTANCE_LOG_TAIL_BYTES: u64 = 512 * 1024;
|
||||||
|
|
||||||
|
/// Export launcher logs (filtered by time range and level) plus optional
|
||||||
|
/// system information, the most recent instance log, and a crash analysis
|
||||||
|
/// summary into a ZIP archive.
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn export_launcher_logs(
|
||||||
|
output_path: PathBuf,
|
||||||
|
range: LogExportRange,
|
||||||
|
level: LogExportLevel,
|
||||||
|
include_system_info: bool,
|
||||||
|
include_instance_logs: bool,
|
||||||
|
include_crash_analysis: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
// Censoring needs the app state (credentials, IPs). Without it an export
|
||||||
|
// would silently ship secrets, so fail rather than degrade.
|
||||||
|
let state = theseus::State::get().await?;
|
||||||
|
let archive = tokio::fs::File::create(&output_path).await?;
|
||||||
|
let mut writer = ZipFileWriter::with_tokio(archive);
|
||||||
|
|
||||||
|
let (exported_logs, skipped_logs) =
|
||||||
|
write_exported_logs(&mut writer, range, level, &state).await?;
|
||||||
|
|
||||||
|
let mut manifest = format!(
|
||||||
|
"Starlight Launcher log export\n\
|
||||||
|
Exported at: {}\n\
|
||||||
|
App version: {}\n\
|
||||||
|
Time range: {}\n\
|
||||||
|
Level filter: {}\n\
|
||||||
|
System information: {}\n\
|
||||||
|
Recent instance log: {}\n\
|
||||||
|
Crash analysis: {}\n\
|
||||||
|
Log files: {exported_logs}\n\n\
|
||||||
|
Access tokens, Minecraft tokens, and IP addresses are replaced with placeholders.\n",
|
||||||
|
chrono::Local::now().to_rfc3339(),
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
range.label(),
|
||||||
|
level.label(),
|
||||||
|
if include_system_info {
|
||||||
|
"included"
|
||||||
|
} else {
|
||||||
|
"omitted"
|
||||||
|
},
|
||||||
|
if include_instance_logs {
|
||||||
|
"included"
|
||||||
|
} else {
|
||||||
|
"omitted"
|
||||||
|
},
|
||||||
|
if include_crash_analysis {
|
||||||
|
"included"
|
||||||
|
} else {
|
||||||
|
"omitted"
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if !skipped_logs.is_empty() {
|
||||||
|
manifest.push_str("\nSkipped unreadable log files:\n");
|
||||||
|
for name in &skipped_logs {
|
||||||
|
manifest.push_str(&format!("- {name}\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
write_zip_entry(&mut writer, "manifest.txt", manifest.as_bytes()).await?;
|
||||||
|
|
||||||
|
if include_system_info {
|
||||||
|
let environment = build_environment_report();
|
||||||
|
let environment = censor_export_text(environment, &state).await?;
|
||||||
|
write_zip_entry(
|
||||||
|
&mut writer,
|
||||||
|
"system-information.txt",
|
||||||
|
environment.as_bytes(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let recent_instance = if include_instance_logs || include_crash_analysis {
|
||||||
|
newest_instance_log(&state).await
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
if include_instance_logs
|
||||||
|
&& let Some((instance_id, path)) = recent_instance.as_ref()
|
||||||
|
{
|
||||||
|
let tail = read_file_tail(path, LOG_EXPORT_INSTANCE_LOG_TAIL_BYTES)?;
|
||||||
|
let tail = censor_export_text(tail, &state).await?;
|
||||||
|
write_zip_entry(
|
||||||
|
&mut writer,
|
||||||
|
&format!("minecraft/{instance_id}/latest.log"),
|
||||||
|
tail.as_bytes(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if include_crash_analysis
|
||||||
|
&& let Some((instance_id, _)) = recent_instance.as_ref()
|
||||||
|
&& let Ok(analysis) = theseus::logs::analyze_crash(instance_id).await
|
||||||
|
&& (analysis.crashed || !analysis.findings.is_empty())
|
||||||
|
&& let Ok(report) = serde_json::to_vec_pretty(&analysis)
|
||||||
|
{
|
||||||
|
// The analysis carries raw log text and Windows event messages, so it
|
||||||
|
// goes through the same censoring as the exported logs.
|
||||||
|
let report = censor_export_text(
|
||||||
|
String::from_utf8_lossy(&report).into_owned(),
|
||||||
|
&state,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
write_zip_entry(
|
||||||
|
&mut writer,
|
||||||
|
&format!("minecraft/{instance_id}/crash-analysis.json"),
|
||||||
|
report.as_bytes(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.close().await.map_err(zip_error)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the matching launcher logs and reports how many were written plus
|
||||||
|
/// the names of any files that could not be read.
|
||||||
|
async fn write_exported_logs(
|
||||||
|
writer: &mut ZipFileWriter<tokio::fs::File>,
|
||||||
|
range: LogExportRange,
|
||||||
|
level: LogExportLevel,
|
||||||
|
state: &theseus::State,
|
||||||
|
) -> Result<(usize, Vec<String>)> {
|
||||||
|
let Some(directories) = DirectoryInfo::global_handle_if_ready() else {
|
||||||
|
return Ok((0, Vec::new()));
|
||||||
|
};
|
||||||
|
let Some(logs_dir) = directories.launcher_logs_dir() else {
|
||||||
|
return Ok((0, Vec::new()));
|
||||||
|
};
|
||||||
|
if !tokio::fs::try_exists(&logs_dir).await? {
|
||||||
|
return Ok((0, Vec::new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut entries = tokio::fs::read_dir(&logs_dir).await?;
|
||||||
|
let mut paths = Vec::new();
|
||||||
|
while let Some(entry) = entries.next_entry().await? {
|
||||||
|
let path = entry.path();
|
||||||
|
let is_session_log =
|
||||||
|
path.file_name().and_then(|name| name.to_str()).is_some_and(
|
||||||
|
|name| name.starts_with("session_") && name.ends_with(".log"),
|
||||||
|
);
|
||||||
|
if is_session_log && entry.file_type().await?.is_file() {
|
||||||
|
paths.push(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
paths.sort();
|
||||||
|
|
||||||
|
let mut exported = 0;
|
||||||
|
let mut skipped = Vec::new();
|
||||||
|
for path in paths {
|
||||||
|
let file_name = path
|
||||||
|
.file_name()
|
||||||
|
.map(|name| name.to_string_lossy().into_owned())
|
||||||
|
.unwrap_or_else(|| "session.log".to_string());
|
||||||
|
|
||||||
|
// A single unreadable file must not lose the whole report.
|
||||||
|
let Ok(contents) = tokio::fs::read(&path).await else {
|
||||||
|
skipped.push(file_name);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let filtered = theseus::filter_log_contents(
|
||||||
|
&contents,
|
||||||
|
range.max_age(),
|
||||||
|
level.minimum(),
|
||||||
|
);
|
||||||
|
let text = String::from_utf8_lossy(&filtered).into_owned();
|
||||||
|
let censored = censor_export_text(text, state).await?;
|
||||||
|
write_zip_entry(
|
||||||
|
writer,
|
||||||
|
&format!("launcher_logs/{file_name}"),
|
||||||
|
censored.as_bytes(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
exported += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((exported, skipped))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Replaces credentials and IP addresses with placeholders. Censoring failures
|
||||||
|
/// propagate so an export never ships unredacted content.
|
||||||
|
async fn censor_export_text(
|
||||||
|
text: String,
|
||||||
|
state: &theseus::State,
|
||||||
|
) -> Result<String> {
|
||||||
|
Ok(theseus::install::censor_shared_text(text, state).await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_environment_report() -> String {
|
||||||
|
format!(
|
||||||
|
"Starlight Launcher environment\n\
|
||||||
|
App version: {}\n\
|
||||||
|
Operating system: {}\n\
|
||||||
|
Architecture: {}\n",
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
std::env::consts::OS,
|
||||||
|
std::env::consts::ARCH,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The instance whose log was written most recently, if any.
|
||||||
|
async fn newest_instance_log(
|
||||||
|
state: &theseus::State,
|
||||||
|
) -> Option<(String, PathBuf)> {
|
||||||
|
let instances_dir = state.directories.instances_dir();
|
||||||
|
let mut entries = tokio::fs::read_dir(&instances_dir).await.ok()?;
|
||||||
|
let mut newest: Option<(std::time::SystemTime, String, PathBuf)> = None;
|
||||||
|
|
||||||
|
while let Some(entry) = entries.next_entry().await.ok()? {
|
||||||
|
if !entry.file_type().await.ok()?.is_dir() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let log_path = entry.path().join("logs").join("latest.log");
|
||||||
|
let Ok(metadata) = tokio::fs::metadata(&log_path).await else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let Ok(modified) = metadata.modified() else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let is_newer = newest
|
||||||
|
.as_ref()
|
||||||
|
.is_none_or(|(newest_modified, ..)| modified > *newest_modified);
|
||||||
|
if is_newer {
|
||||||
|
let id = entry.file_name().to_string_lossy().into_owned();
|
||||||
|
newest = Some((modified, id, log_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newest.map(|(_, id, path)| (id, path))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_file_tail(path: &Path, max_bytes: u64) -> Result<String> {
|
||||||
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
|
||||||
|
let mut file = std::fs::File::open(path)?;
|
||||||
|
let length = file.metadata()?.len();
|
||||||
|
if length > max_bytes {
|
||||||
|
file.seek(SeekFrom::Start(length - max_bytes))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut contents = Vec::new();
|
||||||
|
file.read_to_end(&mut contents)?;
|
||||||
|
Ok(String::from_utf8_lossy(&contents).into_owned())
|
||||||
|
}
|
||||||
|
|
||||||
async fn write_zip_file(
|
async fn write_zip_file(
|
||||||
writer: &mut ZipFileWriter<tokio::fs::File>,
|
writer: &mut ZipFileWriter<tokio::fs::File>,
|
||||||
filename: &str,
|
filename: &str,
|
||||||
|
|||||||
@@ -670,7 +670,7 @@ fn read_file_tail(path: &Path, max_bytes: u64) -> crate::Result<String> {
|
|||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn censor_support_text(
|
pub(crate) async fn censor_support_text(
|
||||||
mut text: String,
|
mut text: String,
|
||||||
state: &State,
|
state: &State,
|
||||||
) -> crate::Result<String> {
|
) -> crate::Result<String> {
|
||||||
|
|||||||
@@ -41,3 +41,12 @@ pub use runner::{
|
|||||||
retry_job, retry_job_as_new, skip_missing_content_and_resume_job,
|
retry_job, retry_job_as_new, skip_missing_content_and_resume_job,
|
||||||
update_managed_curseforge_modpack, upgrade_unmanaged_instance,
|
update_managed_curseforge_modpack, upgrade_unmanaged_instance,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Replaces credentials and IP addresses in text the user may share publicly
|
||||||
|
/// (support reports, exported logs) with placeholders.
|
||||||
|
pub async fn censor_shared_text(
|
||||||
|
text: String,
|
||||||
|
state: &crate::State,
|
||||||
|
) -> crate::Result<String> {
|
||||||
|
diagnostics::censor_support_text(text, state).await
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ pub use event::{
|
|||||||
EventState, LoadingBar, LoadingBarType, emit::emit_loading,
|
EventState, LoadingBar, LoadingBarType, emit::emit_loading,
|
||||||
emit::init_loading,
|
emit::init_loading,
|
||||||
};
|
};
|
||||||
|
pub use logger::filter_log_contents;
|
||||||
pub use logger::start_logger;
|
pub use logger::start_logger;
|
||||||
pub use state::db::{
|
pub use state::db::{
|
||||||
backup_current_app_db_for_update, beta_database_exists,
|
backup_current_app_db_for_update, beta_database_exists,
|
||||||
|
|||||||
@@ -240,6 +240,114 @@ fn launcher_log_is_expired(
|
|||||||
now.duration_since(created).is_ok_and(|age| age > max_age)
|
now.duration_since(created).is_ok_and(|age| age > max_age)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ordinal for the levels the launcher writes, ordered from most to least
|
||||||
|
/// verbose. Unknown tokens are ignored so unrecognized lines are never pruned.
|
||||||
|
fn log_level_ordinal(token: &str) -> Option<u8> {
|
||||||
|
match token {
|
||||||
|
"TRACE" => Some(0),
|
||||||
|
"DEBUG" => Some(1),
|
||||||
|
"INFO" => Some(2),
|
||||||
|
"WARN" => Some(3),
|
||||||
|
"ERROR" => Some(4),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_level_minimum_ordinal(level: &str) -> Option<u8> {
|
||||||
|
match level {
|
||||||
|
"trace" => Some(0),
|
||||||
|
"debug" => Some(1),
|
||||||
|
"info" => Some(2),
|
||||||
|
"warn" => Some(3),
|
||||||
|
"error" => Some(4),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How a log line relates to the surrounding entries.
|
||||||
|
enum LogEntryHeader {
|
||||||
|
/// Timestamp and level parsed: the entry can be filtered.
|
||||||
|
Classified(chrono::DateTime<chrono::FixedOffset>, u8),
|
||||||
|
/// Timestamp parsed but the level is unknown: keep it rather than
|
||||||
|
/// dropping content this logic does not understand.
|
||||||
|
Unclassified,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reads the timestamp and level of an entry line. Continuation lines of a
|
||||||
|
/// multi-line message carry no prefix and return `None`, so callers keep them
|
||||||
|
/// grouped with the entry they belong to.
|
||||||
|
fn parse_log_entry_header(line: &str) -> Option<LogEntryHeader> {
|
||||||
|
let (timestamp, rest) = line.split_once(char::is_whitespace)?;
|
||||||
|
let timestamp = chrono::DateTime::parse_from_rfc3339(timestamp).ok()?;
|
||||||
|
let level = rest.trim_start().split_whitespace().next()?;
|
||||||
|
Some(match log_level_ordinal(level) {
|
||||||
|
Some(ordinal) => LogEntryHeader::Classified(timestamp, ordinal),
|
||||||
|
None => LogEntryHeader::Unclassified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keeps or drops whole log entries by a predicate over their timestamp and
|
||||||
|
/// level ordinal, returning `None` when nothing was dropped.
|
||||||
|
///
|
||||||
|
/// Multi-line messages are kept or dropped together with their header, the
|
||||||
|
/// bytes of kept lines are preserved exactly (no re-encoding), and entries
|
||||||
|
/// whose level cannot be classified are always kept.
|
||||||
|
fn filter_log_entries<F>(contents: &[u8], keep: F) -> Option<Vec<u8>>
|
||||||
|
where
|
||||||
|
F: Fn(chrono::DateTime<chrono::FixedOffset>, u8) -> bool,
|
||||||
|
{
|
||||||
|
let mut kept = Vec::with_capacity(contents.len());
|
||||||
|
let mut changed = false;
|
||||||
|
let mut keep_entry = true;
|
||||||
|
|
||||||
|
for line in contents.split_inclusive(|byte| *byte == b'\n') {
|
||||||
|
match parse_log_entry_header(&String::from_utf8_lossy(line)) {
|
||||||
|
Some(LogEntryHeader::Classified(timestamp, ordinal)) => {
|
||||||
|
keep_entry = keep(timestamp, ordinal);
|
||||||
|
}
|
||||||
|
Some(LogEntryHeader::Unclassified) => keep_entry = true,
|
||||||
|
// Continuation line: it follows the decision of its entry.
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if keep_entry {
|
||||||
|
kept.extend_from_slice(line);
|
||||||
|
} else {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
changed.then_some(kept)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Filters launcher log bytes for an export: entries older than `max_age` and
|
||||||
|
/// entries below `min_level` are removed. Pass `None` for either bound to keep
|
||||||
|
/// everything on that axis. Multi-line messages stay intact.
|
||||||
|
pub fn filter_log_contents(
|
||||||
|
contents: &[u8],
|
||||||
|
max_age: Option<std::time::Duration>,
|
||||||
|
min_level: Option<&str>,
|
||||||
|
) -> Vec<u8> {
|
||||||
|
let now = chrono::Local::now().fixed_offset();
|
||||||
|
let minimum = min_level.and_then(log_level_minimum_ordinal);
|
||||||
|
|
||||||
|
filter_log_entries(contents, |timestamp, ordinal| {
|
||||||
|
if let Some(minimum) = minimum
|
||||||
|
&& ordinal < minimum
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if let Some(max_age) = max_age {
|
||||||
|
let age = (now - timestamp).to_std().unwrap_or_default();
|
||||||
|
if age > max_age {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| contents.to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
struct LogEventWriter {
|
struct LogEventWriter {
|
||||||
writer: RotatingLogWriter,
|
writer: RotatingLogWriter,
|
||||||
buffer: Vec<u8>,
|
buffer: Vec<u8>,
|
||||||
|
|||||||
Reference in new issue
Block a user