For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/guides/advanced-features/server-monitor/logger.md.
  • 简体中文
  • 日志事件

    日志事件是由 Modern.js 分发的,类型为 log 的事件。

    内置事件

    基于服务端运行逻辑,Modern.js 在内部提供了以下日志事件:

    阶段消息Level
    RENDER_HTMLApp Render To HTMLerror
    RENDER_STREAMAn error occurs during streaming SSRerror
    RENDER_SHELLAn error occurs during streaming render shellerror

    内置 Monitor

    在 Modern.js 中,日志事件由 LoggerMonitor 处理,它会将日志输出到控制台。

    Info

    内置的 LoggerMonitor 依赖了 rslog 库。

    例如在项目中有意的抛出一个错误:

    routes/page.tsx
    import './index.css';
    
    const Index = () => <div className="container-box">{a}</div>;
    
    export default Index;

    如果运行正常,可以在控制台看到如下输出:

    > Local:    http://localhost:8080/
    > press h + enter to show shortcuts
    
    error   SSR Error - App Prerender, error = ReferenceError: a is not defined
        at Index (/somepath/page.tsx:3:1)