[Feature] Added RFC for Q cli logger - #1405
Conversation
|
I would find it very useful to dump my full This dumps all my chat logs to a directory when I use I'm also wondering if this proposal should be coupled with this persistent conversations RFC. They seem to have similar intent, logging conversations to a file. |
|
Yes...currently, apart from tool usage, it is persisting all this data to a local storage that it uses to support the output of this command. For second part, yes, it is saving it currently in json format and can be retrieved by user. I am still waiting for a wider review and gather feedback around how can we store the response field with a compact summary of each prompt in the log files that is readable by Q in case it wants to improvise itself for that task. Regarding the persistent conversation RFC, I do see the value in combining them. Will wait on how these things turn out soon. |
|
Closing this after an offline discussion. Conversation serialization (
|
- Zip: kiro-cli-chat-x86_64-pc-windows-msvc.zip → kiro-cli.zip
- MSI: kiro-cli-{version}-{arch}.msi → kiro-cli.msi
- Clean old MSIs from latest/ before uploading
Target triple and version are already in the S3 path and Lambda
payload — no need to duplicate in filenames.
Summary
This RFC proposes adding a logging feature to the Amazon Q CLI tool that will record user prompts, commands, responses, and related metadata in a structured format. The feature will be opt-in, enabled via a command-line flag or in-session command, and will provide users with commands to view, filter, and manage their interaction logs.
Motivation
Users of the Amazon Q CLI tool often need to:
Currently, there is no built-in way to record and review these interactions, forcing users to manually copy and paste important information or lose their history entirely when closing the terminal. This feature addresses this gap by providing a structured, searchable log of all interactions that users can easily access and manage.
The expected outcomes are:
Guide-level explanation
Enabling Logging
There are two ways to enable logging for a Q CLI session:
1. At Startup
Use the
--enable-loggingflag when starting the tool:2. During a Session
Enable logging during an active session using the
/log enablecommand:Similarly, you can disable logging during a session:
When logging is enabled, a new log file is created for the current session in the standard system log location for your operating system:
~/Library/Logs/AmazonQ/~/.local/share/amazon-q/logs/%LOCALAPPDATA%\Amazon\Q\Logs\Viewing Logs
Once logging is enabled, you can view your logs using the
/logcommand within the Q CLI:This displays the 10 most recent log entries in the current session. Each entry includes:
Log Command Options
The
/logcommand supports several options:Example Usage
Here's an example of enabling logging and using the log commands:
Start Q CLI with logging enabled:
Use Q CLI normally:
View your recent interactions:
View only user prompts:
Enable logging mid-session:
Impact on Codebase Maintenance
The logging feature is designed with maintainability in mind:
This design makes the feature easy to maintain and extend in the future, with minimal impact on the core Q CLI functionality.
Reference-level explanation
Architecture
The Q CLI Logging Feature consists of four main components:
Component Interfaces
LogManager
LogEntry
LogCommandHandler
Data Storage
Log File Format
Logs are stored in JSONL (JSON Lines) format, with each line containing a single JSON object representing a log entry:
{"id":"entry_001","timestamp":"2025-04-25T14:30:22Z","prompt":"How do I create an S3 bucket?","response_summary":"Provided steps to create an S3 bucket using AWS CLI and console","response_time_seconds":1.2,"context_files":[],"session_id":"a1b2c3d4","is_user_prompt":true} {"id":"entry_002","timestamp":"2025-04-25T14:35:45Z","prompt":"/log show","response_summary":"Displayed log entries","response_time_seconds":0.1,"context_files":[],"session_id":"a1b2c3d4","is_user_prompt":false}File Structure
The logging feature uses the following file structure:
Where
[log_directory]is the platform-specific log directory.Implementation Details
Enabling Logging
When the
--enable-loggingflag is provided at startup or the/log enablecommand is used during a session:LogManagerinitializes with the new session ID and creates the log directory if it doesn't existq_session_YYYY-MM-DD_HH-MM-SS_[session_id].logenabledflag inLogManageris set totrueSimilarly, when the
/log disablecommand is used:enabledflag inLogManageris set tofalseLogging Interactions
For each user interaction:
LogManager.log_interactionmethod is called with the prompt, response, response time, context files, and a flag indicating whether it's a user prompt or system commandLogEntryis created with a unique ID and the current timestampLogEntry.generate_summarymethodLog Truncation
When a log file exceeds 512MB:
LogManager.check_and_truncate_log_filemethod is calledCommand Handling
When a
/logcommand is entered:LogCommandHandleris called:handle_show_commandfor/log show(with optional--all,--desc, or--only-user-promptsflags)handle_tail_commandfor/log --tail Nhandle_head_commandfor/log --head Nhandle_delete_commandfor/log deletehandle_enable_commandfor/log enablehandle_disable_commandfor/log disableLogManager, applying filters likeonly_user_promptsif specifiedError Handling
The feature implements comprehensive error handling:
Log Directory Creation Failure
Log File Write Failure
Log File Read Failure
Log File Size Limit Exceeded
Invalid Command Arguments
Integration with Existing Codebase
The logging feature integrates with the existing Q CLI codebase by:
--enable-loggingflag to the command-line argument parser/logcommand handler with the existing command processing system, including the newenable,disable, and--only-user-promptsoptionsThis integration is designed to be minimally invasive, with the logging functionality contained in its own module and only interacting with the main codebase through well-defined interfaces.
Drawbacks
There are several potential drawbacks to implementing this feature:
Increased Complexity: Adding logging functionality increases the complexity of the codebase, which could make maintenance more challenging.
Disk Space Usage: Logs can consume significant disk space over time, especially for power users. While we implement truncation at 512MB, this could still be an issue for users with limited storage.
Performance Impact: Writing logs to disk for each interaction could potentially impact performance, especially on systems with slow storage.
Privacy Concerns: Storing user interactions could raise privacy concerns, as sensitive information might be inadvertently logged. This is mitigated by making logging opt-in and storing logs locally only.
Maintenance Burden: The feature will require ongoing maintenance to ensure compatibility with future changes to the Q CLI tool.
Cross-Platform Complexity: Implementing proper log storage across different operating systems adds complexity and potential for platform-specific bugs.
Rationale and alternatives
Why this design?
This design was chosen because it:
Balances Simplicity and Functionality: The design provides comprehensive logging capabilities while maintaining a simple user interface.
Follows Platform Conventions: By storing logs in standard system locations, the feature integrates well with existing system tools and user expectations.
Minimizes Resource Usage: The JSONL format and line-based truncation approach minimize disk space usage and processing overhead.
Preserves User Privacy: The opt-in approach and local-only storage respect user privacy while still providing the benefits of logging.
Supports Future Extensions: The modular design allows for easy addition of new features like log compression, advanced filtering, and analytics.
Alternatives Considered
1. Persistent Logging (Always Enabled)
Instead of opt-in logging, we could enable logging by default for all sessions.
Rationale for not choosing: This would raise privacy concerns and consume disk space unnecessarily for users who don't need logging.
2. Database Storage
Instead of flat files, we could store logs in a lightweight database like SQLite.
Rationale for not choosing: This would add a dependency on a database library and increase complexity without significant benefits for the current use cases.
3. Remote Logging
We could offer an option to sync logs to a remote storage service.
Rationale for not choosing: This would raise significant privacy concerns and add unnecessary complexity for what is primarily a local tool.
4. Log Rotation Instead of Truncation
Instead of truncating large log files, we could implement log rotation with multiple files.
Rationale for not choosing: While this would preserve more historical data, it would consume more disk space and add complexity to the log management system.
Impact of Not Doing This
If we don't implement this feature:
Unresolved questions
Command Syntax: Should we use
/logas the command prefix, or would another syntax be more consistent with existing commands?Log Retention Policy: Should we implement an automatic cleanup policy for older logs, or leave this to the user?
Response Summary Generation: What's the optimal approach for generating compact summaries of responses? Should we use a fixed character limit, extract the first few sentences, or use a more sophisticated approach?
Performance Impact: How significant is the performance impact of logging, especially on systems with slow storage? Do we need to implement buffering or asynchronous writes?
Cross-Session Queries: Should we support querying logs across multiple sessions, or keep the focus on the current session only?
Security Considerations: Should we implement any additional security measures for log files, such as encryption or redaction of sensitive information?
Future possibilities
There are several natural extensions to this feature that could be implemented in the future:
Log Compression: Automatically compress older log files to save disk space.
Advanced Filtering: Add support for filtering logs by date range, keywords, or other criteria.
Log Export: Allow users to export logs to different formats (CSV, PDF, etc.) for sharing or analysis.
Log Analytics: Implement basic analytics to show usage patterns, common queries, etc.
Cross-Session Queries: Add support for querying logs across multiple sessions.
Log Synchronization: Allow users to synchronize logs across multiple devices (with appropriate privacy controls).
Selective Logging: Allow users to mark certain interactions as private (not to be logged).
Log Annotations: Allow users to add notes or tags to log entries for easier reference.
Integration with Other Tools: Provide APIs or hooks for other tools to access and analyze logs.
Contextual Recall: Use logged interactions to improve the context and relevance of future responses.
These possibilities demonstrate the potential for the logging feature to evolve beyond simple record-keeping into a powerful tool for productivity, learning, and collaboration.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.