2020-08-30 17:12:15 +02:00
|
|
|
<template>
|
2020-12-16 12:16:43 +01:00
|
|
|
<view-base
|
2021-02-19 18:52:54 +01:00
|
|
|
:queries="queries" @queries-response="onQueriesResponse"
|
2020-12-16 12:16:43 +01:00
|
|
|
ref="view" skeleton="card-info-skeleton"
|
|
|
|
>
|
2020-08-30 17:12:15 +02:00
|
|
|
<!-- INFO CARD -->
|
2020-12-16 12:16:43 +01:00
|
|
|
<card :title="description" icon="info-circle">
|
2020-11-03 19:10:30 +01:00
|
|
|
<b-row
|
|
|
|
v-for="(value, prop) in info" :key="prop"
|
|
|
|
no-gutters class="row-line"
|
|
|
|
>
|
2020-12-16 12:16:43 +01:00
|
|
|
<b-col md="3" xl="2">
|
2020-11-03 19:10:30 +01:00
|
|
|
<strong>{{ $t('logs_' + prop) }}</strong>
|
|
|
|
</b-col>
|
2020-12-16 12:16:43 +01:00
|
|
|
|
2020-11-03 19:10:30 +01:00
|
|
|
<b-col>
|
|
|
|
<span v-if="prop.endsWith('_at')">{{ value | readableDate }}</span>
|
2020-12-16 12:16:43 +01:00
|
|
|
|
2020-11-03 19:10:30 +01:00
|
|
|
<div v-else-if="prop === 'suboperations'">
|
|
|
|
<div v-for="operation in value" :key="operation.name">
|
|
|
|
<icon v-if="!operation.success" iname="times" class="text-danger" />
|
|
|
|
<b-link :to="{ name: 'tool-log', params: { name: operation.name } }">
|
|
|
|
{{ operation.description }}
|
|
|
|
</b-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-12-16 12:16:43 +01:00
|
|
|
|
2020-11-03 19:10:30 +01:00
|
|
|
<span v-else>{{ value }}</span>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
2020-12-16 12:16:43 +01:00
|
|
|
</card>
|
2020-08-30 17:12:15 +02:00
|
|
|
|
2020-12-16 12:16:43 +01:00
|
|
|
<div v-if="info.error" class="alert alert-danger my-5">
|
2021-01-19 18:16:00 +01:00
|
|
|
<icon iname="exclamation-circle" /> <span v-html="$t('operation_failed_explanation')" />
|
2020-12-16 12:16:43 +01:00
|
|
|
</div>
|
2020-08-30 17:12:15 +02:00
|
|
|
|
|
|
|
<!-- LOGS CARD -->
|
2020-12-16 12:16:43 +01:00
|
|
|
<card :title="$t('logs')" icon="file-text" no-body>
|
|
|
|
<template #header-buttons>
|
|
|
|
<b-button @click="shareLogs" variant="success">
|
|
|
|
<icon iname="cloud-upload" /> {{ $t('logs_share_with_yunopaste') }}
|
|
|
|
</b-button>
|
2020-08-30 17:12:15 +02:00
|
|
|
</template>
|
2020-11-25 16:20:59 +01:00
|
|
|
|
2020-08-30 17:12:15 +02:00
|
|
|
<b-button
|
|
|
|
v-if="moreLogsAvailable"
|
2020-11-25 16:20:59 +01:00
|
|
|
variant="white" class="w-100 rounded-0"
|
2021-01-19 18:16:00 +01:00
|
|
|
@click="$refs.view.fetchQueries()"
|
2020-08-30 17:12:15 +02:00
|
|
|
>
|
|
|
|
<icon iname="plus" /> {{ $t('logs_more') }}
|
|
|
|
</b-button>
|
2020-11-25 16:20:59 +01:00
|
|
|
|
2020-12-16 12:16:43 +01:00
|
|
|
<pre class="log"><code v-html="logs" /></pre>
|
2020-11-25 16:20:59 +01:00
|
|
|
|
|
|
|
<b-button @click="shareLogs" variant="success" class="w-100 rounded-0">
|
|
|
|
<icon iname="cloud-upload" /> {{ $t('logs_share_with_yunopaste') }}
|
|
|
|
</b-button>
|
2020-12-16 12:16:43 +01:00
|
|
|
</card>
|
|
|
|
</view-base>
|
2020-08-30 17:12:15 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-10-12 17:36:47 +02:00
|
|
|
import api from '@/api'
|
2021-01-19 18:16:00 +01:00
|
|
|
import { objectToParams, escapeHtml } from '@/helpers/commons'
|
2020-11-03 16:27:30 +01:00
|
|
|
import { readableDate } from '@/helpers/filters/date'
|
2020-08-30 17:12:15 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ToolLog',
|
|
|
|
|
|
|
|
props: {
|
2020-12-16 12:16:43 +01:00
|
|
|
name: { type: String, required: true }
|
2020-08-30 17:12:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
// Log data
|
2020-12-16 12:16:43 +01:00
|
|
|
description: undefined,
|
2020-11-03 19:10:30 +01:00
|
|
|
info: {},
|
2020-12-16 12:16:43 +01:00
|
|
|
logs: undefined,
|
2020-08-30 17:12:15 +02:00
|
|
|
// Logs line display
|
2020-11-03 19:10:30 +01:00
|
|
|
numberOfLines: 25,
|
2020-08-30 17:12:15 +02:00
|
|
|
moreLogsAvailable: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-12-16 12:16:43 +01:00
|
|
|
computed: {
|
|
|
|
queries () {
|
2020-09-10 19:10:37 +02:00
|
|
|
const queryString = objectToParams({
|
2020-08-30 17:12:15 +02:00
|
|
|
filter_irrelevant: '',
|
2020-11-03 19:10:30 +01:00
|
|
|
with_suboperations: '',
|
2020-08-30 17:12:15 +02:00
|
|
|
number: this.numberOfLines
|
2020-09-10 19:10:37 +02:00
|
|
|
})
|
2021-02-19 18:52:54 +01:00
|
|
|
return [['GET', `logs/${this.name}?${queryString}`]]
|
2020-12-16 12:16:43 +01:00
|
|
|
}
|
|
|
|
},
|
2020-08-30 17:12:15 +02:00
|
|
|
|
2020-12-16 12:16:43 +01:00
|
|
|
methods: {
|
2021-02-19 18:52:54 +01:00
|
|
|
onQueriesResponse (log) {
|
2020-12-16 12:16:43 +01:00
|
|
|
if (log.logs.length === this.numberOfLines) {
|
|
|
|
this.moreLogsAvailable = true
|
|
|
|
this.numberOfLines *= 10
|
|
|
|
} else {
|
|
|
|
this.moreLogsAvailable = false
|
|
|
|
}
|
|
|
|
this.description = log.description
|
|
|
|
|
|
|
|
const levels = ['ERROR', 'WARNING', 'SUCCESS', 'INFO']
|
|
|
|
this.logs = log.logs.map(line => {
|
2021-01-19 18:16:00 +01:00
|
|
|
const escaped = escapeHtml(line)
|
2020-12-16 12:16:43 +01:00
|
|
|
for (const level of levels) {
|
|
|
|
if (line.includes(level + ' -')) {
|
|
|
|
return `<span class="alert-${level === 'ERROR'
|
|
|
|
? 'danger'
|
2021-01-19 18:16:00 +01:00
|
|
|
: level.toLowerCase()}">${escaped}</span>`
|
2020-08-30 17:12:15 +02:00
|
|
|
}
|
2020-12-16 12:16:43 +01:00
|
|
|
}
|
2021-01-19 18:16:00 +01:00
|
|
|
return escaped
|
2020-12-16 12:16:43 +01:00
|
|
|
}).join('\n')
|
|
|
|
// eslint-disable-next-line
|
|
|
|
const { started_at, ended_at, error, success, suboperations } = log.metadata
|
|
|
|
const info = { path: log.log_path, started_at, ended_at }
|
|
|
|
if (!success) info.error = error
|
|
|
|
if (suboperations && suboperations.length) info.suboperations = suboperations
|
|
|
|
this.info = info
|
2020-08-30 17:12:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
shareLogs () {
|
2021-02-19 18:52:54 +01:00
|
|
|
api.get(`logs/${this.name}?share`, null, { websocket: true }).then(({ url }) => {
|
2020-08-30 17:12:15 +02:00
|
|
|
window.open(url, '_blank')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-12-16 12:16:43 +01:00
|
|
|
filters: { readableDate }
|
2020-08-30 17:12:15 +02:00
|
|
|
}
|
|
|
|
</script>
|