1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

Download logs section

This commit is contained in:
Adria Navarro 2023-07-10 13:57:27 +02:00
parent b64ea43d20
commit fd0018c1bc
4 changed files with 38 additions and 2 deletions

View file

@ -0,0 +1,17 @@
<script>
import { Layout, Body, Button } from "@budibase/bbui"
import { downloadStream } from "@budibase/frontend-core"
import { API } from "api"
async function download() {
downloadStream(await API.getServerLogs())
}
</script>
<Layout noPadding>
<Body>Download your latest logs to share with the Budibase team</Body>
<div class="download-button">
<Button cta on:click={download}>Download system logs</Button>
</div>
</Layout>

View file

@ -85,6 +85,13 @@ export const menu = derived([admin, auth], ([$admin, $auth]) => {
title: "Audit Logs",
href: "/builder/portal/account/auditLogs",
})
if (!$admin.cloud) {
accountSubPages.push({
title: "System Logs",
href: "/builder/portal/account/systemLogs",
})
}
}
if ($admin.cloud && $auth?.user?.accountPortalAccess) {
accountSubPages.push({

View file

@ -12,8 +12,17 @@ export function downloadText(filename, text) {
URL.revokeObjectURL(url)
}
export async function downloadStream(filename, streamResponse) {
export async function downloadStream(streamResponse) {
const blob = await streamResponse.blob()
const contentDisposition = streamResponse.headers.get("Content-Disposition")
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
contentDisposition
)
const filename = matches[1].replace(/['"]/g, "")
const resBlob = new Blob([blob])
const blobUrl = URL.createObjectURL(resBlob)

View file

@ -1,8 +1,11 @@
import { UserCtx } from "@budibase/types"
import { logging } from "@budibase/backend-core"
import { context, logging } from "@budibase/backend-core"
export async function getLogs(ctx: UserCtx) {
const logReadStream = logging.system.getLogReadStream()
const fileName = `${context.getTenantId()}-${Date.now()}.logs`
ctx.set("content-disposition", `attachment; filename=${fileName}`)
ctx.body = logReadStream
}