This directory contains examples demonstrating the logging capabilities of the Chroma Go V2 client.
First, ensure you have a Chroma instance running:
# Using Docker
docker run -p 8000:8000 chromadb/chroma:latest
# Or using the Makefile from the project root
make serverThen run the examples:
go run main.go- Production Logger: Uses zap's production configuration with JSON output
- Development Logger: Uses zap's development configuration with pretty printing
- Custom Logger Configuration: Shows how to configure a custom zap logger
WithDebug() Automatic Logger: DEPRECATED - Use WithLogger with debug-level logger instead- NoopLogger: Shows silent operation with no logging
- Custom Fields: Demonstrates adding persistent fields to all log messages
- Structured Logging: All logs use structured fields for better analysis
- Context Support: Logger supports context for distributed tracing
- Log Levels: Different log levels (Debug, Info, Warn, Error)
- Field Types: Various field types (String, Int, Bool, Error, Any)
- Logger Composition: Using
With()to create loggers with persistent fields
zapLogger, _ := zap.NewProduction()
logger := chromalogger.NewZapLogger(zapLogger)logger, _ := chromalogger.NewDevelopmentZapLogger()config := zap.NewProductionConfig()
config.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
config.Encoding = "json"
zapLogger, _ := config.Build()
logger := chromalogger.NewZapLogger(zapLogger)WithDebug() is deprecated. Use WithLogger() instead:
// DEPRECATED - Don't use this
// client, _ := chroma.NewHTTPClient(
// chroma.WithDebug(),
// )
// RECOMMENDED - Use this instead
logger, _ := chromalogger.NewDevelopmentZapLogger()
client, _ := chroma.NewHTTPClient(
chroma.WithLogger(logger), // Use logger with debug level
)CHROMA_URL: The URL of your Chroma instance (default:http://localhost:8000)
The examples will produce different types of log output:
- JSON format (production): Machine-readable structured logs
- Console format (development): Human-readable colored output
- Silent (noop): No output at all
- Development: Use development logger with
WithLogger()for debugging (WithDebug is deprecated) - Production: Use production logger with appropriate log level
- Testing: Use NoopLogger to disable logging during tests
- Monitoring: Use structured fields for log aggregation and analysis