feat(logging): add logging for regular expression updates and creation actions

This commit is contained in:
Sam Chau
2026-01-02 23:35:04 +10:30
parent 9948782cc2
commit 897cfa6b06
2 changed files with 38 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
import type { PCDCache } from '../../cache.ts';
import { writeOperation, type OperationLayer } from '../../writer.ts';
import type { RegularExpressionTableRow } from './types.ts';
import { logger } from '$logger/logger.ts';
export interface UpdateRegularExpressionInput {
name: string;
@@ -97,6 +98,33 @@ export async function update(options: UpdateRegularExpressionOptions) {
queries.push(linkTag);
}
// Log what's being changed (before the write)
const changes: Record<string, { from: unknown; to: unknown }> = {};
if (current.name !== input.name) {
changes.name = { from: current.name, to: input.name };
}
if (current.pattern !== input.pattern) {
changes.pattern = { from: current.pattern, to: input.pattern };
}
if (current.description !== input.description) {
changes.description = { from: current.description, to: input.description };
}
if (current.regex101_id !== input.regex101Id) {
changes.regex101Id = { from: current.regex101_id, to: input.regex101Id };
}
if (tagsToAdd.length > 0 || tagsToRemove.length > 0) {
changes.tags = { from: currentTagNames, to: input.tags };
}
await logger.info(`Save regular expression "${input.name}"`, {
source: 'RegularExpression',
meta: {
id: current.id,
changes
}
});
// Write the operation with metadata
// Include previousName if this is a rename
const isRename = input.name !== current.name;

View File

@@ -4,6 +4,7 @@ import { pcdManager } from '$pcd/pcd.ts';
import { canWriteToBase } from '$pcd/writer.ts';
import * as regularExpressionQueries from '$pcd/queries/regularExpressions/index.ts';
import type { OperationLayer } from '$pcd/writer.ts';
import { logger } from '$logger/logger.ts';
export const load: ServerLoad = ({ params, url }) => {
const { databaseId } = params;
@@ -80,6 +81,15 @@ export const actions: Actions = {
const layerFromForm = formData.get('layer');
const layer = (layerFromForm as OperationLayer) || 'user';
await logger.debug('Create action received', {
source: 'RegularExpressionCreate',
meta: {
regexName: name,
layerFromForm,
layerUsed: layer
}
});
// Validate
if (!name?.trim()) {
return fail(400, { error: 'Name is required' });