logger
选项为编译期间的 React Compiler 事件提供自定义日志记录。
¥The logger
option provides custom logging for React Compiler events during compilation.
{
logger: {
logEvent(filename, event) {
console.log(`[Compiler] ${event.kind}: ${filename}`);
}
}
}
参考
¥Reference
logger
配置自定义日志记录以跟踪编译器行为和调试问题。
¥Configures custom logging to track compiler behavior and debug issues.
类型
¥Type
{
logEvent: (filename: string | null, event: LoggerEvent) => void;
} | null
默认值
¥Default value
null
方法
¥Methods
-
logEvent
:针对每个编译器事件调用,并附带文件名和事件详情¥**
logEvent
**: Called for each compiler event with the filename and event details
事件类型
¥Event types
-
CompileSuccess
:函数成功编译¥**
CompileSuccess
**: Function successfully compiled -
CompileError
:由于错误而跳过的函数¥**
CompileError
**: Function skipped due to errors -
CompileDiagnostic
:非致命诊断信息¥**
CompileDiagnostic
**: Non-fatal diagnostic information -
CompileSkip
:由于其他原因而跳过的函数¥**
CompileSkip
**: Function skipped for other reasons -
PipelineError
:意外的编译错误¥**
PipelineError
**: Unexpected compilation error -
Timing
:性能时序信息¥**
Timing
**: Performance timing information
注意事项
¥Caveats
-
事件结构可能会在不同版本之间发生变化
¥Event structure may change between versions
-
大型代码库会生成大量日志条目
¥Large codebases generate many log entries
用法
¥Usage
基本日志记录
¥Basic logging
跟踪编译成功和失败:
¥Track compilation success and failures:
{
logger: {
logEvent(filename, event) {
switch (event.kind) {
case 'CompileSuccess': {
console.log(`✅ Compiled: ${filename}`);
break;
}
case 'CompileError': {
console.log(`❌ Skipped: ${filename}`);
break;
}
default: {}
}
}
}
}
详细的错误日志
¥Detailed error logging
获取有关编译失败的具体信息:
¥Get specific information about compilation failures:
{
logger: {
logEvent(filename, event) {
if (event.kind === 'CompileError') {
console.error(`\nCompilation failed: ${filename}`);
console.error(`Reason: ${event.detail.reason}`);
if (event.detail.description) {
console.error(`Details: ${event.detail.description}`);
}
if (event.detail.loc) {
const { line, column } = event.detail.loc.start;
console.error(`Location: Line ${line}, Column ${column}`);
}
if (event.detail.suggestions) {
console.error('Suggestions:', event.detail.suggestions);
}
}
}
}
}