feat(#27): Set up consola logger, make use of log levels in backend and frontend

This commit is contained in:
2025-12-24 10:26:22 +01:00
parent 805c66bc4f
commit 7f7852a66a
36 changed files with 312 additions and 141 deletions

View File

@@ -1,14 +1,16 @@
import type { ApplicationFormDto, PagedApplicationFormDto, FormElementDto } from '~~/.api-client'
import { useApplicationFormApi } from './useApplicationFormApi'
import { useLogger } from '../useLogger'
export function useApplicationForm() {
const applicationFormApi = useApplicationFormApi()
const logger = useLogger().withTag('applicationForm')
async function createApplicationForm(applicationFormDto: ApplicationFormDto): Promise<ApplicationFormDto> {
try {
return await applicationFormApi.createApplicationForm(applicationFormDto)
} catch (e: unknown) {
console.error('Failed creating application form:', e)
logger.error('Failed creating application form:', e)
return Promise.reject(e)
}
}
@@ -17,7 +19,7 @@ export function useApplicationForm() {
try {
return await applicationFormApi.getAllApplicationForms(organizationId)
} catch (e: unknown) {
console.error('Failed retrieving application forms:', e, JSON.stringify(e))
logger.error('Failed retrieving application forms:', e)
return Promise.reject(e)
}
}
@@ -26,7 +28,7 @@ export function useApplicationForm() {
try {
return await applicationFormApi.getApplicationFormById(id)
} catch (e: unknown) {
console.error(`Failed retrieving application form with ID ${id}:`, e)
logger.error(`Failed retrieving application form with ID ${id}:`, e)
return Promise.reject(e)
}
}
@@ -39,11 +41,11 @@ export function useApplicationForm() {
return Promise.reject(new Error('ID or application form DTO missing'))
}
console.log('Updating application form with ID:', id, applicationFormDto)
logger.debug('Updating application form with ID:', id, applicationFormDto)
try {
return await applicationFormApi.updateApplicationForm(id, applicationFormDto)
} catch (e: unknown) {
console.error(`Failed updating application form with ID ${id}:`, e)
logger.error(`Failed updating application form with ID ${id}:`, e)
return Promise.reject(e)
}
}
@@ -52,7 +54,7 @@ export function useApplicationForm() {
try {
return await applicationFormApi.deleteApplicationFormById(id)
} catch (e: unknown) {
console.error(`Failed deleting application form with ID ${id}:`, e)
logger.error(`Failed deleting application form with ID ${id}:`, e)
return Promise.reject(e)
}
}
@@ -65,7 +67,7 @@ export function useApplicationForm() {
try {
return await applicationFormApi.submitApplicationForm(id)
} catch (e: unknown) {
console.error(`Failed submitting application form with ID ${id}:`, e)
logger.error(`Failed submitting application form with ID ${id}:`, e)
return Promise.reject(e)
}
}
@@ -88,7 +90,7 @@ export function useApplicationForm() {
position
)
} catch (e: unknown) {
console.error(`Failed adding form element to subsection ${subsectionId}:`, e)
logger.error(`Failed adding form element to subsection ${subsectionId}:`, e)
return Promise.reject(e)
}
}

View File

@@ -1,10 +1,12 @@
import { type ApplicationFormDto, type PagedApplicationFormDto, ResponseError } from '~~/.api-client'
import { useApplicationFormTemplateApi } from './useApplicationFormTemplateApi'
import { useLogger } from '../useLogger'
const currentApplicationForm: Ref<ApplicationFormDto | undefined> = ref()
export async function useApplicationFormTemplate() {
const applicationFormApi = await useApplicationFormTemplateApi()
const logger = useLogger().withTag('applicationFormTemplate')
async function createApplicationFormTemplate(applicationFormDto: ApplicationFormDto): Promise<ApplicationFormDto> {
try {
@@ -12,9 +14,9 @@ export async function useApplicationFormTemplate() {
return currentApplicationForm.value
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error('Failed creating application form:', e.response)
logger.error('Failed creating application form:', e.response)
} else {
console.error('Failed creating application form:', e)
logger.error('Failed creating application form:', e)
}
return Promise.reject(e)
}
@@ -25,9 +27,9 @@ export async function useApplicationFormTemplate() {
return await applicationFormApi.getAllApplicationFormTemplates()
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error('Failed retrieving application forms:', e.response)
logger.error('Failed retrieving application forms:', e.response)
} else {
console.error('Failed retrieving application forms:', e)
logger.error('Failed retrieving application forms:', e)
}
return Promise.reject(e)
}
@@ -38,9 +40,9 @@ export async function useApplicationFormTemplate() {
return await applicationFormApi.getApplicationFormTemplateById(id)
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error(`Failed retrieving application form with ID ${id}:`, e.response)
logger.error(`Failed retrieving application form with ID ${id}:`, e.response)
} else {
console.error(`Failed retrieving application form with ID ${id}:`, e)
logger.error(`Failed retrieving application form with ID ${id}:`, e)
}
return Promise.reject(e)
}
@@ -59,9 +61,9 @@ export async function useApplicationFormTemplate() {
return currentApplicationForm.value
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error(`Failed updating application form with ID ${id}:`, e.response)
logger.error(`Failed updating application form with ID ${id}:`, e.response)
} else {
console.error(`Failed updating application form with ID ${id}:`, e)
logger.error(`Failed updating application form with ID ${id}:`, e)
}
return Promise.reject(e)
}
@@ -72,9 +74,9 @@ export async function useApplicationFormTemplate() {
return await applicationFormApi.deleteApplicationFormTemplateById(id)
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error(`Failed deleting application form with ID ${id}:`, e.response)
logger.error(`Failed deleting application form with ID ${id}:`, e.response)
} else {
console.error(`Failed deleting application form with ID ${id}:`, e)
logger.error(`Failed deleting application form with ID ${id}:`, e)
}
return Promise.reject(e)
}

View File

@@ -1,14 +1,16 @@
import type { ApplicationFormVersionDto, ApplicationFormVersionListItemDto, ApplicationFormDto } from '~~/.api-client'
import { useApplicationFormVersionApi } from '~/composables'
import { useLogger } from '../useLogger'
export function useApplicationFormVersion() {
const versionApi = useApplicationFormVersionApi()
const logger = useLogger().withTag('applicationFormVersion')
async function getVersions(applicationFormId: string): Promise<ApplicationFormVersionListItemDto[]> {
try {
return await versionApi.getVersions(applicationFormId)
} catch (e: unknown) {
console.error(`Failed retrieving versions for application form ${applicationFormId}:`, e)
logger.error(`Failed retrieving versions for application form ${applicationFormId}:`, e)
return Promise.reject(e)
}
}
@@ -17,7 +19,7 @@ export function useApplicationFormVersion() {
try {
return await versionApi.getVersion(applicationFormId, versionNumber)
} catch (e: unknown) {
console.error(`Failed retrieving version ${versionNumber} for application form ${applicationFormId}:`, e)
logger.error(`Failed retrieving version ${versionNumber} for application form ${applicationFormId}:`, e)
return Promise.reject(e)
}
}
@@ -30,7 +32,7 @@ export function useApplicationFormVersion() {
try {
return await versionApi.restoreVersion(applicationFormId, versionNumber)
} catch (e: unknown) {
console.error(`Failed restoring version ${versionNumber} for application form ${applicationFormId}:`, e)
logger.error(`Failed restoring version ${versionNumber} for application form ${applicationFormId}:`, e)
return Promise.reject(e)
}
}

View File

@@ -1,6 +1,7 @@
import type { CreateCommentDto, CommentDto } from '~~/.api-client'
import { useCommentStore } from '~~/stores/useCommentStore'
import { useUserStore } from '~~/stores/useUserStore'
import { useLogger } from '../useLogger'
export function useCommentTextarea(applicationFormId: string) {
const commentStore = useCommentStore()
@@ -11,6 +12,8 @@ export function useCommentTextarea(applicationFormId: string) {
const currentEditedComment = ref<CommentDto | null>(null)
const commentTextAreaValue = ref('')
const toast = useToast()
const { t: $t } = useI18n()
const logger = useLogger().withTag('commentTextarea')
async function submitComment(formElementId: string) {
const newCommentDto: CreateCommentDto = {
@@ -19,10 +22,10 @@ export function useCommentTextarea(applicationFormId: string) {
try {
await createComment(applicationFormId, formElementId, newCommentDto)
commentTextAreaValue.value = ''
toast.add({ title: 'Comment created successfully', color: 'success' })
toast.add({ title: $t('comments.created'), color: 'success' })
} catch (e) {
toast.add({ title: 'Error creating comment', color: 'error' })
console.error('Error creating comment:', e)
toast.add({ title: $t('comments.createError'), color: 'error' })
logger.error('Error creating comment:', e)
}
}
@@ -34,10 +37,10 @@ export function useCommentTextarea(applicationFormId: string) {
commentTextAreaValue.value = ''
currentEditedComment.value = null
isEditingComment.value = false
toast.add({ title: 'Comment updated successfully', color: 'success' })
toast.add({ title: $t('comments.updated'), color: 'success' })
} catch (e) {
toast.add({ title: 'Error updating comment', color: 'error' })
console.error('Error updating comment:', e)
toast.add({ title: $t('comments.updateError'), color: 'error' })
logger.error('Error updating comment:', e)
}
}

View File

@@ -2,6 +2,8 @@ import type { NotificationDto } from '~~/.api-client'
import { useUserStore } from '~~/stores/useUserStore'
export const useNotification = () => {
const logger = useLogger().withTag('notification')
const {
getNotifications,
getUnreadNotifications,
@@ -22,7 +24,7 @@ export const useNotification = () => {
const fetchNotifications = async (page: number = 0, size: number = 20) => {
if (!organizationId.value) {
console.warn('No organization selected')
logger.warn('No organization selected')
return
}
isLoading.value = true
@@ -31,7 +33,7 @@ export const useNotification = () => {
notifications.value = response.content || []
return response
} catch (error) {
console.error('Failed to fetch notifications:', error)
logger.error('Failed to fetch notifications:', error)
throw error
} finally {
isLoading.value = false
@@ -40,7 +42,7 @@ export const useNotification = () => {
const fetchUnreadNotifications = async () => {
if (!organizationId.value) {
console.warn('No organization selected')
logger.warn('No organization selected')
return
}
try {
@@ -48,14 +50,14 @@ export const useNotification = () => {
unreadNotifications.value = response || []
return response
} catch (error) {
console.error('Failed to fetch unread notifications:', error)
logger.error('Failed to fetch unread notifications:', error)
throw error
}
}
const fetchUnreadCount = async () => {
if (!userId.value || !organizationId.value) {
console.warn('No user or organization selected')
logger.warn('No user or organization selected')
return
}
try {
@@ -63,14 +65,14 @@ export const useNotification = () => {
unreadCount.value = count || 0
return count
} catch (error) {
console.error('Failed to fetch unread count:', error)
logger.error('Failed to fetch unread count:', error)
throw error
}
}
const markAllAsRead = async () => {
if (!organizationId.value) {
console.warn('No organization selected')
logger.warn('No organization selected')
return
}
try {
@@ -79,14 +81,14 @@ export const useNotification = () => {
unreadNotifications.value = []
notifications.value = notifications.value.map((n) => ({ ...n, isRead: true }))
} catch (error) {
console.error('Failed to mark all as read:', error)
logger.error('Failed to mark all as read:', error)
throw error
}
}
const markAsRead = async (notificationId: string) => {
if (!organizationId.value) {
console.warn('No organization selected')
logger.warn('No organization selected')
return
}
try {
@@ -102,7 +104,7 @@ export const useNotification = () => {
unreadCount.value--
}
} catch (error) {
console.error('Failed to mark notification as read:', error)
logger.error('Failed to mark notification as read:', error)
throw error
}
}

View File

@@ -1,10 +1,13 @@
import { ComplianceStatus, type FormElementDto } from '~~/.api-client'
import { complianceCheckableElementTypes, complianceMap } from './complianceMap'
import type { FormElementId } from '~~/types/formElement'
import { useLogger } from './useLogger'
const formElementComplianceMap = ref(new Map<FormElementId, ComplianceStatus>())
export function useApplicationFormValidator() {
const logger = useLogger().withTag('validator')
function getHighestComplianceStatus(): ComplianceStatus {
const complianceStatusValues = Array.from(formElementComplianceMap.value.values())
const highestComplianceNumber = Math.max(
@@ -37,7 +40,7 @@ export function useApplicationFormValidator() {
formElement.options.forEach((option) => {
if (!option.value) {
console.log(`Value missing for ${formElement.type}`)
logger.debug(`Value missing for ${formElement.type}`)
return
}

View File

@@ -0,0 +1,5 @@
import type { ConsolaInstance } from 'consola'
export function useLogger(): ConsolaInstance {
return useNuxtApp().$logger
}

View File

@@ -1,8 +1,11 @@
import { useLogger } from './useLogger'
export const isServerAvailable = ref(true)
export const isChecking = ref(false)
export const lastCheckTime = ref<Date | null>(null)
export function useServerHealth() {
const logger = useLogger().withTag('serverHealth')
const checkInterval = ref<ReturnType<typeof setInterval> | null>(null)
const healthCheckUrl = '/api/actuator/health'
@@ -30,11 +33,11 @@ export function useServerHealth() {
isServerAvailable.value = response.ok
if (!wasAvailable && isServerAvailable.value) {
console.info('Server is back online')
logger.info('Server is back online')
}
if (wasAvailable && !isServerAvailable.value) {
console.warn('Server is no longer available')
logger.warn('Server is no longer available')
}
return isServerAvailable.value
@@ -43,7 +46,7 @@ export function useServerHealth() {
isServerAvailable.value = false
if (wasAvailable) {
console.warn('Server health check failed:', error)
logger.warn('Server health check failed:', error)
}
return false