Address ESlint console statements
This commit is contained in:
+5
-3
@@ -2,6 +2,8 @@
|
||||
* Content caching utilities for improved performance
|
||||
*/
|
||||
|
||||
import { logger } from "./logger";
|
||||
|
||||
// In-memory cache for blog posts
|
||||
const blogPostCache = new Map<string, CacheEntry<unknown>>();
|
||||
const blogListCache = new Map<string, CacheEntry<unknown[]>>();
|
||||
@@ -243,9 +245,9 @@ export async function warmCache<T>(
|
||||
cacheBlogPost(postWithSlug.slug, post);
|
||||
});
|
||||
|
||||
console.log("Cache warmed up successfully");
|
||||
logger.info("Cache warmed up successfully");
|
||||
} catch (error) {
|
||||
console.error("Error warming up cache:", error);
|
||||
logger.error("Error warming up cache:", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +260,7 @@ export function isCacheHealthy(): boolean {
|
||||
clearExpiredCache();
|
||||
return blogPostCache.size < MAX_CACHE_SIZE;
|
||||
} catch (error) {
|
||||
console.error("Cache health check failed:", error);
|
||||
logger.error("Cache health check failed:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -3,6 +3,7 @@ import path from "path";
|
||||
import matter from "gray-matter";
|
||||
import { validateBlogPost, sanitizeBlogPost } from "./validation";
|
||||
import type { BlogPostFrontmatter } from "./validation";
|
||||
import { logger } from "./logger";
|
||||
|
||||
/**
|
||||
* Content processing utilities for blog posts
|
||||
@@ -73,7 +74,7 @@ export function getBlogPostFiles(): string[] {
|
||||
(file) => file.endsWith(".md") || file.endsWith(".mdx"),
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error reading blog content directory:", error);
|
||||
logger.error("Error reading blog content directory:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -92,7 +93,7 @@ export function parseBlogPost(filePath: string): BlogPost | null {
|
||||
|
||||
const validationResult = validateBlogPost(data);
|
||||
if (!validationResult.isValid) {
|
||||
console.error(
|
||||
logger.error(
|
||||
`Validation errors for ${filePath}:`,
|
||||
validationResult.errors,
|
||||
);
|
||||
@@ -111,7 +112,7 @@ export function parseBlogPost(filePath: string): BlogPost | null {
|
||||
lastModified: fs.statSync(fullPath).mtime,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Error parsing blog post file ${filePath}:`, error);
|
||||
logger.error(`Error parsing blog post file ${filePath}:`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/* eslint-disable no-console */
|
||||
/**
|
||||
* Minimal logger wrapper.
|
||||
*
|
||||
* - Centralizes logging so we can swap implementations later (e.g. pino/sentry).
|
||||
* - Avoids sprinkling `console.*` throughout app code.
|
||||
*/
|
||||
|
||||
type LoggerArgs = unknown[];
|
||||
|
||||
const isProd = process.env.NODE_ENV === "production";
|
||||
|
||||
export const logger = {
|
||||
debug: (...args: LoggerArgs) => {
|
||||
if (!isProd) console.debug(...args);
|
||||
},
|
||||
info: (...args: LoggerArgs) => {
|
||||
console.info(...args);
|
||||
},
|
||||
warn: (...args: LoggerArgs) => {
|
||||
console.warn(...args);
|
||||
},
|
||||
error: (...args: LoggerArgs) => {
|
||||
console.error(...args);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user