feat(logging): enhance logging for delay profile updates and write operations

This commit is contained in:
Sam Chau
2026-01-02 20:20:55 +10:30
parent 77a3375889
commit 77237b54ac
2 changed files with 60 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
import type { PCDCache } from '../../cache.ts';
import { writeOperation, type OperationLayer } from '../../writer.ts';
import type { PreferredProtocol, DelayProfileTableRow } from './types.ts';
import { logger } from '$logger/logger.ts';
export interface UpdateDelayProfileInput {
name: string;
@@ -113,6 +114,42 @@ export async function update(options: UpdateDelayProfileOptions) {
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.preferred_protocol !== input.preferredProtocol) {
changes.preferredProtocol = { from: current.preferred_protocol, to: input.preferredProtocol };
}
if (current.usenet_delay !== usenetDelay) {
changes.usenetDelay = { from: current.usenet_delay, to: usenetDelay };
}
if (current.torrent_delay !== torrentDelay) {
changes.torrentDelay = { from: current.torrent_delay, to: torrentDelay };
}
if (current.bypass_if_highest_quality !== input.bypassIfHighestQuality) {
changes.bypassIfHighestQuality = { from: current.bypass_if_highest_quality, to: input.bypassIfHighestQuality };
}
if (current.bypass_if_above_custom_format_score !== input.bypassIfAboveCfScore) {
changes.bypassIfAboveCfScore = { from: current.bypass_if_above_custom_format_score, to: input.bypassIfAboveCfScore };
}
if (current.minimum_custom_format_score !== minimumCfScore) {
changes.minimumCfScore = { from: current.minimum_custom_format_score, to: minimumCfScore };
}
if (tagsToAdd.length > 0 || tagsToRemove.length > 0) {
changes.tags = { from: currentTagNames, to: input.tags };
}
await logger.info(`Save delay profile "${input.name}"`, {
source: 'DelayProfile',
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

@@ -301,9 +301,30 @@ export async function writeOperation(options: WriteOptions): Promise<WriteResult
// Write the file
await Deno.writeTextFile(filepath, content);
await logger.info(`Wrote operation to ${layer} layer`, {
// Build descriptive message
const opType = metadata?.operation ?? 'write';
const entity = metadata?.entity?.replace(/_/g, ' ') ?? 'operation';
const entityName = metadata?.name ?? '';
const layerDir = layer === 'base' ? 'ops' : 'user_ops';
const message = `${opType.charAt(0).toUpperCase() + opType.slice(1)} ${entity} "${entityName}" in layer "${layerDir}"`;
await logger.info(message, {
source: 'PCDWriter',
meta: { databaseId, filepath, layer, description }
meta: {
database: {
id: databaseId,
name: instance.name,
layer
},
filename,
operation: metadata ? {
type: metadata.operation,
entity: metadata.entity,
name: metadata.name,
...(metadata.previousName && { previousName: metadata.previousName })
} : null,
queries: sqlStatements
}
});
// Recompile the cache immediately so the new operation is available