Skip to content

Logging

ElyOS uses its own logging system that can write to multiple targets simultaneously (console, file, database). Logs can be viewed in the built-in Log application.

import { logger } from '$lib/server/logging';
logger.debug('Detailed debug information', { extra: 'data' });
logger.info('General information');
logger.warn('Warning', { context: 'something' });
logger.error('An error occurred', { error: err });
logger.fatal('Critical error', { error: err });

The logger accepts structured data as a second parameter:

logger.info('User logged in', {
userId: user.id,
email: user.email,
ip: event.getClientAddress()
});
logger.error('Database error', {
operation: 'findUser',
userId: id,
error: error.message
});
import { command, getRequestEvent } from '$app/server';
import { logger } from '$lib/server/logging';
export const myAction = command(schema, async (input) => {
const { locals } = getRequestEvent();
logger.info('Action executed', {
action: 'myAction',
userId: locals.user?.id,
input
});
try {
// ... logic
return { success: true };
} catch (error) {
logger.error('Action failed', {
action: 'myAction',
error: error instanceof Error ? error.message : String(error)
});
return { success: false, error: 'Internal error' };
}
});

Logging is configured in the .env file:

VariableDefaultDescription
LOG_TARGETSconsoleComma-separated targets: console, file, database
LOG_LEVELerrorMinimum level: debug, info, warn, error, fatal
LOG_DIR./logsLog files directory (if file target active)
Terminál
LOG_TARGETS=console
LOG_LEVEL=debug
Terminál
LOG_TARGETS=console,database
LOG_LEVEL=info

The built-in Log application (src/apps/log/) displays logs saved to the database. Accessible only with admin permissions.

Logs are stored in the error_logs table when the database target is active.

Client-side JavaScript errors are automatically logged via the /api/log endpoint. This is configured in hooks.client.ts.