-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogger.ts
More file actions
71 lines (60 loc) · 1.66 KB
/
Copy pathlogger.ts
File metadata and controls
71 lines (60 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import fs from 'fs';
import path from 'path';
const LOG_DIR = path.join(process.cwd(), 'logs');
// Ensure logs directory exists
if (!fs.existsSync(LOG_DIR)) {
fs.mkdirSync(LOG_DIR, { recursive: true });
}
interface LogEntry {
timestamp: string;
type: 'prompt' | 'response' | 'data' | 'error' | 'system';
content: string;
metadata?: Record<string, any>;
}
export function logToFile(entry: LogEntry) {
const today = new Date().toISOString().split('T')[0];
const logFile = path.join(LOG_DIR, `chat_${today}.txt`);
const logLine = `[${entry.timestamp}] ${entry.type.toUpperCase()}: ${entry.content}\n`;
const metadata = entry.metadata ? ` Metadata: ${JSON.stringify(entry.metadata)}\n` : '';
fs.appendFileSync(logFile, logLine + metadata);
}
export function logPrompt(content: string, metadata?: Record<string, any>) {
logToFile({
timestamp: new Date().toISOString(),
type: 'prompt',
content,
metadata,
});
}
export function logResponse(content: string, metadata?: Record<string, any>) {
logToFile({
timestamp: new Date().toISOString(),
type: 'response',
content,
metadata,
});
}
export function logData(content: string, metadata?: Record<string, any>) {
logToFile({
timestamp: new Date().toISOString(),
type: 'data',
content,
metadata,
});
}
export function logError(content: string, metadata?: Record<string, any>) {
logToFile({
timestamp: new Date().toISOString(),
type: 'error',
content,
metadata,
});
}
export function logSystem(content: string, metadata?: Record<string, any>) {
logToFile({
timestamp: new Date().toISOString(),
type: 'system',
content,
metadata,
});
}