Added log search
This commit is contained in:
parent
c138047be5
commit
b69a951b05
|
@ -1,8 +1,36 @@
|
||||||
|
import { logError } from '../../lib/logger'
|
||||||
import prisma from '../../prisma'
|
import prisma from '../../prisma'
|
||||||
|
|
||||||
export async function logs() {
|
export async function logs(parent, { search, dateIn, dateOut, limit }) {
|
||||||
return await prisma.log.findMany({
|
if (!dateOut) dateOut = new Date()
|
||||||
orderBy: { timestamp: 'desc' },
|
|
||||||
take: 500
|
try {
|
||||||
})
|
const logs = await prisma.log.findMany({
|
||||||
|
where: {
|
||||||
|
timestamp: {
|
||||||
|
gte: new Date(dateIn),
|
||||||
|
lte: new Date(dateOut)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
orderBy: { timestamp: 'desc' },
|
||||||
|
take: search ? undefined : limit
|
||||||
|
})
|
||||||
|
|
||||||
|
if (search) search = search.trim().toLowerCase()
|
||||||
|
|
||||||
|
return search
|
||||||
|
? logs
|
||||||
|
.filter(
|
||||||
|
log =>
|
||||||
|
log.message.toLowerCase().includes(search) ||
|
||||||
|
log.tags.some(tag => tag.toLowerCase().includes(search))
|
||||||
|
)
|
||||||
|
.slice(0, limit)
|
||||||
|
: logs
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message)
|
||||||
|
throw new Error(
|
||||||
|
'Não foi possível recuperar os logs com a entrada especificada.'
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,14 @@ const typeDefs = gql`
|
||||||
@cacheControl(maxAge: 10, scope: PRIVATE)
|
@cacheControl(maxAge: 10, scope: PRIVATE)
|
||||||
|
|
||||||
"Application Logs"
|
"Application Logs"
|
||||||
logs: [Log]!
|
logs(
|
||||||
|
search: String = ""
|
||||||
|
dateIn: String!
|
||||||
|
dateOut: String
|
||||||
|
limit: Int = 200
|
||||||
|
): [Log]!
|
||||||
@auth(roles: ["superAdmin"])
|
@auth(roles: ["superAdmin"])
|
||||||
@cacheControl(maxAge: 5, scope: PRIVATE)
|
@cacheControl(maxAge: 2, scope: PRIVATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
|
|
|
@ -27,13 +27,15 @@
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</template>
|
</template>
|
||||||
</v-tooltip>
|
</v-tooltip>
|
||||||
|
<v-spacer />
|
||||||
|
|
||||||
|
<v-checkbox v-model="polling" label="Atualizar automaticamente" />
|
||||||
</v-toolbar>
|
</v-toolbar>
|
||||||
|
|
||||||
<v-data-table
|
<v-data-table
|
||||||
:loading="$apollo.queries.logs.loading"
|
:loading="$apollo.queries.logs.loading"
|
||||||
:items="items"
|
:items="items"
|
||||||
:headers="headers"
|
:headers="headers"
|
||||||
:search="search"
|
|
||||||
calculate-widths
|
calculate-widths
|
||||||
:footer-props="{
|
:footer-props="{
|
||||||
itemsPerPageOptions: [10, 15, 20, 40, 60, 80, 100]
|
itemsPerPageOptions: [10, 15, 20, 40, 60, 80, 100]
|
||||||
|
@ -83,22 +85,41 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import { format } from 'date-fns'
|
import { format, subDays } from 'date-fns'
|
||||||
|
|
||||||
import VueJsonPretty from 'vue-json-pretty'
|
import VueJsonPretty from 'vue-json-pretty'
|
||||||
|
|
||||||
import 'vue-json-pretty/lib/styles.css'
|
import 'vue-json-pretty/lib/styles.css'
|
||||||
|
|
||||||
|
const LOGS_QUERY = gql`
|
||||||
|
query($search: String, $dateIn: String!, $dateOut: String, $limit: Int) {
|
||||||
|
logs(search: $search, dateIn: $dateIn, dateOut: $dateOut, limit: $limit) {
|
||||||
|
id
|
||||||
|
timestamp
|
||||||
|
level
|
||||||
|
tags
|
||||||
|
message
|
||||||
|
data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { VueJsonPretty },
|
components: { VueJsonPretty },
|
||||||
data: () => ({
|
data: () => ({
|
||||||
search: '',
|
|
||||||
showLow: true,
|
showLow: true,
|
||||||
showInfo: true,
|
showInfo: true,
|
||||||
showWarning: true,
|
showWarning: true,
|
||||||
showError: true,
|
showError: true,
|
||||||
showSuccess: true,
|
showSuccess: true,
|
||||||
|
|
||||||
|
search: '',
|
||||||
|
dateIn: new Date(),
|
||||||
|
dateOut: null,
|
||||||
|
limit: 100,
|
||||||
|
|
||||||
|
polling: false,
|
||||||
|
|
||||||
headers: [
|
headers: [
|
||||||
{
|
{
|
||||||
text: 'Timestamp',
|
text: 'Timestamp',
|
||||||
|
@ -135,21 +156,27 @@ export default {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
polling() {
|
||||||
|
if (this.polling) this.$apollo.queries.logs.startPolling(5000)
|
||||||
|
else this.$apollo.queries.logs.stopPolling()
|
||||||
|
}
|
||||||
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
logs: {
|
logs: {
|
||||||
query: gql`
|
query: LOGS_QUERY,
|
||||||
query {
|
variables() {
|
||||||
logs {
|
return {
|
||||||
id
|
search: this.search,
|
||||||
timestamp
|
dateIn: this.dateIn,
|
||||||
level
|
dateOut: this.dateOut,
|
||||||
tags
|
limit: this.limit
|
||||||
message
|
|
||||||
data
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
beforeMount() {
|
||||||
|
this.dateIn = subDays(new Date(), 5).toISOString().substr(0, 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user