new: [app:live_logs] Added filters for API queries only

This commit is contained in:
Sami Mokaddem 2024-07-03 12:43:20 +02:00
parent fb32b59abe
commit 34869497a1
4 changed files with 37 additions and 2 deletions

View file

@ -9,6 +9,7 @@ from urllib.parse import parse_qs
VERBOSE_MODE = False VERBOSE_MODE = False
APIQUERY_MODE = False
NOTIFICATION_COUNT = 1 NOTIFICATION_COUNT = 1
@ -17,6 +18,11 @@ def set_verbose_mode(enabled: bool):
VERBOSE_MODE = enabled VERBOSE_MODE = enabled
def set_apiquery_mode(enabled: bool):
global APIQUERY_MODE
APIQUERY_MODE = enabled
def get_notifications() -> list[dict]: def get_notifications() -> list[dict]:
return list(db.NOTIFICATION_MESSAGES) return list(db.NOTIFICATION_MESSAGES)
@ -148,6 +154,8 @@ def is_accepted_notification(notification) -> bool:
return False return False
if VERBOSE_MODE: if VERBOSE_MODE:
return True return True
if APIQUERY_MODE and not notification['is_api_request']:
return False
if '@' not in notification['user']: # Ignore message from system if '@' not in notification['user']: # Ignore message from system
return False return False

View file

@ -112,6 +112,10 @@ async def get_diagnostic(sid):
async def toggle_verbose_mode(sid, payload): async def toggle_verbose_mode(sid, payload):
return notification_model.set_verbose_mode(payload['verbose']) return notification_model.set_verbose_mode(payload['verbose'])
@sio.event
async def toggle_apiquery_mode(sid, payload):
return notification_model.set_apiquery_mode(payload['apiquery'])
@sio.on('*') @sio.on('*')
async def any_event(event, sid, data={}): async def any_event(event, sid, data={}):
logger.info('>> Unhandled event %s', event) logger.info('>> Unhandled event %s', event)

View file

@ -1,16 +1,21 @@
<script setup> <script setup>
import { ref, watch } from "vue" import { ref, watch } from "vue"
import { notifications, userCount, notificationCounter, notificationAPICounter, toggleVerboseMode } from "@/socket"; import { notifications, userCount, notificationCounter, notificationAPICounter, toggleVerboseMode, toggleApiQueryMode } from "@/socket";
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faSignal, faCloud, faCog, faUser, faCircle } from '@fortawesome/free-solid-svg-icons' import { faSignal, faCloud, faCog, faUser, faCircle } from '@fortawesome/free-solid-svg-icons'
const verbose = ref(false) const verbose = ref(false)
const api_query = ref(false)
watch(verbose, (newValue) => { watch(verbose, (newValue) => {
toggleVerboseMode(newValue == true) toggleVerboseMode(newValue == true)
}) })
watch(api_query, (newValue) => {
toggleApiQueryMode(newValue == true)
})
function getClassFromResponseCode(response_code) { function getClassFromResponseCode(response_code) {
if (String(response_code).startsWith('2')) { if (String(response_code).startsWith('2')) {
return 'text-green-500' return 'text-green-500'
@ -53,10 +58,17 @@
</span> </span>
<span class="flex items-center"> <span class="flex items-center">
<label class="mr-1 flex items-center cursor-pointer"> <label class="mr-1 flex items-center cursor-pointer">
<input type="checkbox" class="toggle toggle-success [--fallback-su:#22c55e] mr-1" :checked="verbose" @change="verbose = !verbose"/> <input type="checkbox" class="toggle toggle-warning [--fallback-su:#22c55e] mr-1" :checked="verbose" @change="verbose = !verbose"/>
Verbose Verbose
</label> </label>
</span> </span>
<span class="flex items-center">
<label class="mr-1 flex items-center cursor-pointer">
<input type="checkbox" class="toggle toggle-success [--fallback-su:#22c55e] mr-1" :checked="api_query" @change="api_query = !api_query"/>
<FontAwesomeIcon :icon="faCog" size="sm" :mask="faCloud" transform="shrink-7 left-1" class="mr-1"></FontAwesomeIcon>
API Queries
</label>
</span>
</div> </div>
<table class="bg-white dark:bg-slate-800 rounded-lg shadow-xl w-full"> <table class="bg-white dark:bg-slate-800 rounded-lg shadow-xl w-full">

View file

@ -81,6 +81,10 @@ export function toggleVerboseMode(enabled) {
sendToggleVerboseMode(enabled) sendToggleVerboseMode(enabled)
} }
export function toggleApiQueryMode(enabled) {
sendToggleApiQueryMode(enabled)
}
export const debouncedGetProgress = debounce(getProgress, 200, {leading: true}) export const debouncedGetProgress = debounce(getProgress, 200, {leading: true})
export const debouncedGetDiangostic = debounce(getDiangostic, 1000, {leading: true}) export const debouncedGetDiangostic = debounce(getDiangostic, 1000, {leading: true})
@ -151,6 +155,13 @@ function sendToggleVerboseMode(enabled) {
socket.emit("toggle_verbose_mode", payload, () => {}) socket.emit("toggle_verbose_mode", payload, () => {})
} }
function sendToggleApiQueryMode(enabled) {
const payload = {
apiquery: enabled
}
socket.emit("toggle_apiquery_mode", payload, () => {})
}
/* Event listener */ /* Event listener */
socket.on("connect", () => { socket.on("connect", () => {