Logging
Dartantic provides logging support using the Dart logging
package. This allows
you to see detailed information about internal operations, including LLM
requests/responses, tool execution, and provider operations.
Enabling Logging
To enable logging for Dartantic operations, configure the logging package:
import 'package:dartantic_ai/dartantic_ai.dart';
import 'package:logging/logging.dart';
void main() async {
// Configure logging to see dartantic_ai internal operations
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}');
});
final agent = Agent('openai');
final result = await agent.run('Hello world!');
print(result.output);
}
Filtering Dartantic Logs Only
To filter Dartantic logs specifically:
import 'package:logging/logging.dart';
void main() async {
// Configure logging for dartantic_ai specifically
hierarchicalLoggingEnabled = true;
final dartanticLogger = Logger('dartantic_ai');
dartanticLogger.level = Level.ALL;
dartanticLogger.onRecord.listen((record) {
print('[dartantic_ai] ${record.level.name}: ${record.message}');
});
// Your agent code here...
}
This is particularly useful for debugging tool execution, understanding provider behavior, or troubleshooting unexpected responses.
If you want to see more details, check out logging.dart.