Files
Shahin Saadati e705f84906 Add Kotlin snippet for DebugLoggingPlugin (#2105)
* Add Kotlin snippet for DebugLoggingPlugin

The Kotlin logging page covered LoggingPlugin's console output but not
DebugLoggingPlugin, available since adk-kotlin 0.6.0, which records the same
activity in full to a YAML file instead of truncated console summaries. Both
plugins override the same twelve callbacks, so the difference really is only
fidelity and destination.

Transcluded from the existing LoggingExamples.kt rather than written inline,
matching the rest of the page and keeping it in the compile regression suite --
the file is already registered in files_to_test.txt.

The sample passes includeSystemInstruction = false, since the plugin's KDoc
cautions that it writes raw prompts, tool arguments and session state to disk.
Verified against the upstream test that the flag records has_system_instruction
in place of the instruction text rather than dropping the field, and the
comment names that field so it can be found in the output.

outputPath is left at its default rather than passed explicitly; the default
filename is given in the prose instead, so the snippet does not imply the
parameter is required.

Page badge left at Kotlin v0.1.0: the other snippets on the page have worked
since then, so the version requirement for this one is noted in the prose.

* docs: add Kotlin version support tag to debug logging documentation
2026-08-18 10:01:42 -07:00

50 lines
1.8 KiB
Kotlin

/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.adk.kt.examples.observability
import com.google.adk.kt.agents.LlmAgent
import com.google.adk.kt.apps.App
import com.google.adk.kt.plugins.DebugLoggingPlugin
import com.google.adk.kt.plugins.LoggingPlugin
import com.google.adk.kt.runners.InMemoryRunner
import com.google.adk.kt.telemetry.TelemetryConfig
/** Examples for logging setup in ADK Kotlin. */
suspend fun loggingExamples(agent: LlmAgent) {
// --8<-- [start:capture_content]
// Enable full prompt and response logging
TelemetryConfig.captureMessageContent = true
// --8<-- [end:capture_content]
// --8<-- [start:logging_plugin]
// Use the LoggingPlugin for structured activity logging to the console
val runner =
InMemoryRunner(
App(appName = agent.name, rootAgent = agent, plugins = listOf(LoggingPlugin())),
)
// --8<-- [end:logging_plugin]
// --8<-- [start:debug_logging_plugin]
// includeSystemInstruction = false logs has_system_instruction, not the instruction text
val debugPlugin = DebugLoggingPlugin(includeSystemInstruction = false)
val debugRunner =
InMemoryRunner(
App(appName = agent.name, rootAgent = agent, plugins = listOf(debugPlugin)),
)
// --8<-- [end:debug_logging_plugin]
}