ever-brain / packages /api /src /utils /logger.ts
abrez โ€Ž
hello to knowiki
a5d1c1b
Raw History Blame Contribute Delete
1.93 kB
export function formatTimestamp(): string {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
return `[${hours}:${minutes}:${seconds}]`;
}
export const logger = {
info(tag: string, message: string): void {
console.log(`${formatTimestamp()} โ„น๏ธ [${tag}] ${message}`);
},
success(tag: string, message: string): void {
console.log(`${formatTimestamp()} โœ… [${tag}] ${message}`);
},
target(repo: string, branch: string): void {
console.log(`${formatTimestamp()} ๐ŸŽฏ [Target] Parsed repo: ${repo} (Branch: ${branch})`);
},
tree(fileCount: number, durationMs: number, skippedCount = 0): void {
console.log(
`${formatTimestamp()} ๐ŸŒณ [Tree Discovery] ${fileCount} files discovered in ${durationMs}ms (${skippedCount} ignored/binary skipped)`
);
},
raw(path: string, status: number, sizeBytes: number, durationMs: number): void {
const sizeKb = (sizeBytes / 1024).toFixed(1);
console.log(
`${formatTimestamp()} ๐Ÿ“– [Raw Stream] ${path} -> ${status} OK (${sizeKb} KB, ${durationMs}ms)`
);
},
search(query: string, matchesCount: number, durationMs: number): void {
console.log(
`${formatTimestamp()} ๐Ÿ” [Search] Query '${query}' -> ${matchesCount} matches in ${durationMs}ms`
);
},
rateLimit(remaining: number, limit: number): void {
const level = remaining < 10 ? 'โš ๏ธ' : '๐Ÿ“Š';
console.log(`${formatTimestamp()} ${level} [GitHub API] Rate limit remaining: ${remaining}/${limit}`);
},
warn(tag: string, message: string): void {
console.warn(`${formatTimestamp()} โš ๏ธ [${tag}] ${message}`);
},
error(tag: string, message: string, error?: unknown): void {
console.error(`${formatTimestamp()} โŒ [${tag}] ${message}`, error ? error : '');
},
};