constLOG_TAG1='Tag1';constLOG_TAG2='Tag2';//SetverbositylevelforcustomtagscastDebugLogger.loggerLevelByTags={[LOG_TAG1]:cast.framework.LoggerLevel.WARNING,[LOG_TAG2]:cast.framework.LoggerLevel.DEBUG,};castDebugLogger.debug(LOG_TAG1,'debug log from tag1');castDebugLogger.info(LOG_TAG1,'info log from tag1');castDebugLogger.warn(LOG_TAG1,'warn log from tag1');castDebugLogger.error(LOG_TAG1,'error log from tag1');castDebugLogger.debug(LOG_TAG2,'debug log from tag2');castDebugLogger.info(LOG_TAG2,'info log from tag2');castDebugLogger.warn(LOG_TAG2,'warn log from tag2');castDebugLogger.error(LOG_TAG2,'error log from tag2');//exampleoutputs://[Tag1][WARN]warnlogfromtag1//[Tag1][ERROR]errorlogfromtag1//[Tag2][DEBUG]debuglogfromtag2//[Tag2][INFO]infologfromtag2//[Tag2][WARN]warnlogfromtag2//[Tag2][ERROR]errorlogfromtag2
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThe CastDebugLogger API enables developers to debug their Web Receiver app alongside the Command and Control (CaC) tool for capturing logs, requiring Cast device registration and firmware version 1.44 or above.\u003c/p\u003e\n"],["\u003cp\u003eInitialization involves including specific scripts for the Web Receiver SDK and the Cast Debug Logger, creating a CastDebugLogger object, enabling it within the 'READY' event listener, and ensuring \u003ccode\u003esetEnabled\u003c/code\u003e is set to false for production.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can log player events using the \u003ccode\u003eloggerLevelByEvents\u003c/code\u003e config, specifying event types and categories for logging with different verbosity levels like INFO or DEBUG.\u003c/p\u003e\n"],["\u003cp\u003eCustom log messages with custom tags are supported using methods like \u003ccode\u003eerror\u003c/code\u003e, \u003ccode\u003ewarn\u003c/code\u003e, \u003ccode\u003einfo\u003c/code\u003e, and \u003ccode\u003edebug\u003c/code\u003e, with the ability to control message visibility through the \u003ccode\u003eloggerLevelByTags\u003c/code\u003e configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe debug overlay, toggled with \u003ccode\u003eshowDebugLogs\u003c/code\u003e and cleared with \u003ccode\u003eclearDebugLogs\u003c/code\u003e, displays log messages and is activated after enabling the CastDebugLogger.\u003c/p\u003e\n"]]],["The CastDebugLogger API allows debugging Web Receiver apps. To use it, include the debug script after the Web Receiver SDK script and instantiate `CastDebugLogger`. Enable it with `setEnabled(true)` to display a \"DEBUG MODE\" overlay. Log player events using `loggerLevelByEvents` and custom messages with `error`, `warn`, `info`, or `debug` methods, assigning custom tags. Set tag-specific log levels with `loggerLevelByTags`. Manage the overlay using `showDebugLogs` and `clearDebugLogs`. Remember to register your device and change setEnabled to **false** for production.\n"],null,["The Web Receiver SDK provides the CastDebugLogger API for developers to easily\ndebug their Web Receiver app and a companion\n[Command and Control (CaC) Tool](/cast/docs/debugging/cac_tool) to capture\nlogs.\n| **Note:** To use the CastDebugLogger API, you must [register your Cast device](/cast/docs/registration) on the [Google Cast SDK Developer Console](https://cast.google.com/publish) and use a firmware version of **1.44** or above.\n\nInitialization\n\nTo use the **CastDebugLogger API**, include the following script in your\nWeb Receiver app right after the Web Receiver SDK script: \n\n \u003c!-- Web Receiver SDK --\u003e\n \u003cscript src=\"//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js\"\u003e\u003c/script\u003e\n \u003c!-- Cast Debug Logger --\u003e\n \u003cscript src=\"//www.gstatic.com/cast/sdk/libs/devtools/debug_layer/caf_receiver_logger.js\"\u003e\u003c/script\u003e\n\nCreate the `CastDebugLogger` object and enable the logger: \n\n const castDebugLogger = cast.debug.CastDebugLogger.getInstance();\n\n const context = cast.framework.CastReceiverContext.getInstance();\n\n context.addEventListener(cast.framework.system.EventType.READY, () =\u003e {\n if (!castDebugLogger.debugOverlayElement_) {\n // Enable debug logger and show a 'DEBUG MODE' overlay at top left corner.\n castDebugLogger.setEnabled(true);\n }\n });\n\n| **Warning:** Make sure to change `setEnabled` to **false** for a production receiver.\n\nWhen the debug logger is enabled, an overlay displaying **DEBUG MODE** will\nshow on the receiver.\n\nLog Player Events\n\nUsing `CastDebugLogger` you can easily log player events that are fired by\nthe Web Receiver SDK and use different logger levels to log the event data.\nThe `loggerLevelByEvents` config takes [`cast.framework.events.EventType`](/cast/docs/reference/caf_receiver/cast.framework.events#.EventType)\nand [`cast.framework.events.category`](/cast/docs/reference/caf_receiver/cast.framework.events.category)\nto specify the events to be logged.\n\nFor example, if you want to know when the player `CORE` events are triggered\nor a `mediaStatus` change is broadcasted, use the following config to log the\nevents: \n\n castDebugLogger.loggerLevelByEvents = {\n 'cast.framework.events.category.CORE': cast.framework.LoggerLevel.INFO,\n 'cast.framework.events.EventType.MEDIA_STATUS': cast.framework.LoggerLevel.DEBUG\n }\n\nLog Custom Messages with Custom Tags\n\nThe CastDebugLogger API allows you to create log messages that appear on\nthe Web Receiver debug overlay with different colors. Use the following log methods,\nlisted in order from highest to lowest priority:\n\n- `castDebugLogger.error(custom_tag, message);`\n- `castDebugLogger.warn(custom_tag, message);`\n- `castDebugLogger.info(custom_tag, message);`\n- `castDebugLogger.debug(custom_tag, message);`\n\nFor each log method, the first parameter should be a **custom tag** and\nthe second parameter is the **log message**.\nThe tag can be any string that you find helpful.\n\nHere is an example of how to use the debug logger in the `LOAD` interceptor. \n\n const LOG_TAG = 'MyReceiverApp';\n\n playerManager.setMessageInterceptor(\n cast.framework.messages.MessageType.LOAD,\n request =\u003e {\n castDebugLogger.debug(LOG_TAG, 'Intercepting LOAD request');\n\n return new Promise((resolve, reject) =\u003e {\n fetchMediaAsset(request.media.contentId).then(\n data =\u003e {\n let item = data[request.media.contentId];\n if (!item) {\n castDebugLogger.error(LOG_TAG, 'Content not found');\n\n reject();\n } else {\n request.media.contentUrl = item.stream.hls;\n castDebugLogger.info(LOG_TAG,\n 'Playable URL:', request.media.contentUrl);\n\n resolve(request);\n }\n }\n );\n });\n }\n );\n\nYou can control which messages appear on the debug overlay by setting the log\nlevel in `loggerLevelByTags` for each custom tag. For example, enabling a\ncustom tag with log level `cast.framework.LoggerLevel.DEBUG` would display\nall messages added with error, warn, info, and debug log messages. Another\nexample is that enabling a custom tag with `WARNING` level would only display\nerror and warn log messages.\n\nThe `loggerLevelByTags` config is optional. If a custom tag is not configured\nfor its logger level, all log messages will display on the debug overlay. \n\n const LOG_TAG1 = 'Tag1';\n const LOG_TAG2 = 'Tag2';\n\n // Set verbosity level for custom tags\n castDebugLogger.loggerLevelByTags = {\n [LOG_TAG1]: cast.framework.LoggerLevel.WARNING,\n [LOG_TAG2]: cast.framework.LoggerLevel.DEBUG,\n };\n castDebugLogger.debug(LOG_TAG1, 'debug log from tag1');\n castDebugLogger.info(LOG_TAG1, 'info log from tag1');\n castDebugLogger.warn(LOG_TAG1, 'warn log from tag1');\n castDebugLogger.error(LOG_TAG1, 'error log from tag1');\n\n castDebugLogger.debug(LOG_TAG2, 'debug log from tag2');\n castDebugLogger.info(LOG_TAG2, 'info log from tag2');\n castDebugLogger.warn(LOG_TAG2, 'warn log from tag2');\n castDebugLogger.error(LOG_TAG2, 'error log from tag2');\n\n // example outputs:\n // [Tag1] [WARN] warn log from tag1\n // [Tag1] [ERROR] error log from tag1\n // [Tag2] [DEBUG] debug log from tag2\n // [Tag2] [INFO] info log from tag2\n // [Tag2] [WARN] warn log from tag2\n // [Tag2] [ERROR] error log from tag2\n\nDebug Overlay\n\nThe Cast Debug Logger provides a **debug overlay** on the Web Receiver to show\nyour custom log messages. Use `showDebugLogs` to toggle the debug overlay\nand `clearDebugLogs` to clear log messages on the overlay.\n\nReminder: use `showDebugLogs` and `clearDebugLogs` after castDebugLogger is\nenabled. \n\n const context = cast.framework.CastReceiverContext.getInstance();\n\n context.addEventListener(cast.framework.system.EventType.READY, () =\u003e {\n if (!castDebugLogger.debugOverlayElement_) {\n // Enable debug logger and show a 'DEBUG MODE' overlay at top left corner.\n castDebugLogger.setEnabled(true);\n // Show debug overlay\n castDebugLogger.showDebugLogs(true);\n // Clear log messages on debug overlay\n castDebugLogger.clearDebugLogs();\n }\n });"]]