refactor: replace console.log with structured logger calls

Replace raw `console.log`/`console.error` calls across CLI, API
handlers, and module files with structured logger functions (`step`,
`done`, `warn`, `fail`) from the shared logger library.

This improves log consistency, readability, and makes it easier to
control output formatting and log levels from a single place.
This commit is contained in:
2026-04-12 21:44:00 -04:00
parent dd7c54d913
commit e87bd05fa4
25 changed files with 218 additions and 189 deletions
+10 -9
View File
@@ -5,6 +5,7 @@
import { query } from '@zen/core/database';
import { getPostsConfig } from './config.js';
import { done, info, step } from '../../shared/lib/logger.js';
async function tableExists(tableName) {
const result = await query(
@@ -23,7 +24,7 @@ async function createPostsCategoryTable() {
const exists = await tableExists(tableName);
if (exists) {
console.log(`- Table already exists: ${tableName}`);
info(`Table already exists: ${tableName}`);
return { created: false, tableName };
}
@@ -42,7 +43,7 @@ async function createPostsCategoryTable() {
await query(`CREATE INDEX idx_zen_posts_category_post_type ON zen_posts_category(post_type)`);
await query(`CREATE INDEX idx_zen_posts_category_is_active ON zen_posts_category(is_active)`);
console.log(`Created table: ${tableName}`);
done(`Created table: ${tableName}`);
return { created: true, tableName };
}
@@ -51,7 +52,7 @@ async function createPostsTable() {
const exists = await tableExists(tableName);
if (exists) {
console.log(`- Table already exists: ${tableName}`);
info(`Table already exists: ${tableName}`);
return { created: false, tableName };
}
@@ -73,7 +74,7 @@ async function createPostsTable() {
await query(`CREATE INDEX idx_zen_posts_category_id ON zen_posts(category_id)`);
await query(`CREATE INDEX idx_zen_posts_data_gin ON zen_posts USING GIN (data)`);
console.log(`Created table: ${tableName}`);
done(`Created table: ${tableName}`);
return { created: true, tableName };
}
@@ -82,7 +83,7 @@ async function createPostsRelationsTable() {
const exists = await tableExists(tableName);
if (exists) {
console.log(`- Table already exists: ${tableName}`);
info(`Table already exists: ${tableName}`);
return { created: false, tableName };
}
@@ -100,7 +101,7 @@ async function createPostsRelationsTable() {
await query(`CREATE INDEX idx_zen_posts_relations_post_id ON zen_posts_relations(post_id)`);
await query(`CREATE INDEX idx_zen_posts_relations_related ON zen_posts_relations(related_post_id)`);
console.log(`Created table: ${tableName}`);
done(`Created table: ${tableName}`);
return { created: true, tableName };
}
@@ -119,18 +120,18 @@ export async function createTables() {
// zen_posts_category must always be created before zen_posts
// because zen_posts has a FK reference to it
console.log('\n--- Posts Categories ---');
step('Posts Categories');
const catResult = await createPostsCategoryTable();
if (catResult.created) created.push(catResult.tableName);
else skipped.push(catResult.tableName);
console.log('\n--- Posts ---');
step('Posts');
const postResult = await createPostsTable();
if (postResult.created) created.push(postResult.tableName);
else skipped.push(postResult.tableName);
if (needsRelations) {
console.log('\n--- Posts Relations ---');
step('Posts Relations');
const relResult = await createPostsRelationsTable();
if (relResult.created) created.push(relResult.tableName);
else skipped.push(relResult.tableName);