08ea5fbe98
添加用户管理视图、API和状态管理文件
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
export enum LogLevel {
|
|
INFO = 'INFO',
|
|
WARN = 'WARN',
|
|
ERROR = 'ERROR',
|
|
DEBUG = 'DEBUG',
|
|
SUCCESS = 'SUCCESS',
|
|
FAILURE = 'FAILURE'
|
|
}
|
|
|
|
export interface TestLog {
|
|
testName: string;
|
|
status: string;
|
|
startTime: string;
|
|
endTime: string;
|
|
duration: number;
|
|
steps: Array<{
|
|
name: string;
|
|
status: string;
|
|
duration: number;
|
|
}>;
|
|
}
|
|
|
|
export class TestLogger {
|
|
private prefix: string
|
|
private logs: Array<{ level: LogLevel; message: string; timestamp: string; test?: string }> = []
|
|
private testLogs: TestLog[] = []
|
|
private currentTest: TestLog | null = null
|
|
|
|
constructor(prefix: string = 'Test') {
|
|
this.prefix = prefix
|
|
}
|
|
|
|
info(message: string, ...args: any[]) {
|
|
console.log(`[${this.prefix}] INFO:`, message, ...args)
|
|
this.logs.push({ level: LogLevel.INFO, message: JSON.stringify({ message, args }), timestamp: new Date().toISOString() })
|
|
}
|
|
|
|
warn(message: string, ...args: any[]) {
|
|
console.warn(`[${this.prefix}] WARN:`, message, ...args)
|
|
this.logs.push({ level: LogLevel.WARN, message: JSON.stringify({ message, args }), timestamp: new Date().toISOString() })
|
|
}
|
|
|
|
error(message: string, ...args: any[]) {
|
|
console.error(`[${this.prefix}] ERROR:`, message, ...args)
|
|
this.logs.push({ level: LogLevel.ERROR, message: JSON.stringify({ message, args }), timestamp: new Date().toISOString() })
|
|
}
|
|
|
|
debug(message: string, ...args: any[]) {
|
|
console.debug(`[${this.prefix}] DEBUG:`, message, ...args)
|
|
this.logs.push({ level: LogLevel.DEBUG, message: JSON.stringify({ message, args }), timestamp: new Date().toISOString() })
|
|
}
|
|
|
|
step(stepName: string) {
|
|
console.log(`[${this.prefix}] STEP: ${stepName}`)
|
|
}
|
|
|
|
success(message: string, ...args: any[]) {
|
|
console.log(`[${this.prefix}] ✅ SUCCESS:`, message, ...args)
|
|
this.logs.push({ level: LogLevel.SUCCESS, message: JSON.stringify({ message, args }), timestamp: new Date().toISOString() })
|
|
}
|
|
|
|
failure(message: string, ...args: any[]) {
|
|
console.error(`[${this.prefix}] ❌ FAILURE:`, message, ...args)
|
|
this.logs.push({ level: LogLevel.FAILURE, message: JSON.stringify({ message, args }), timestamp: new Date().toISOString() })
|
|
}
|
|
|
|
startStep(stepName: string) {
|
|
console.log(`[${this.prefix}] START STEP: ${stepName}`)
|
|
}
|
|
|
|
endStep(stepName: string, status: string, error?: Error) {
|
|
console.log(`[${this.prefix}] END STEP: ${stepName} - ${status}`)
|
|
}
|
|
|
|
getAllTestLogs(): TestLog[] {
|
|
return this.testLogs
|
|
}
|
|
|
|
getLogsByLevel(level: LogLevel): Array<{ level: LogLevel; message: string; timestamp: string; test?: string }> {
|
|
return this.logs.filter(log => log.level === level)
|
|
}
|
|
}
|
|
|
|
export const testLogger = new TestLogger('E2E')
|
|
|
|
export default TestLogger
|