Skip to main content

Overview

The LogType enum specifies where Zvec’s log messages should be written. Choose between console output for development or file-based logging for production.

Enum Values

CONSOLE

LogType.CONSOLE = 0
Output logs to standard output/error (terminal or IDE console). Best for:
  • Development and debugging
  • Interactive sessions (Jupyter notebooks, REPL)
  • Docker containers with log aggregation
  • Serverless environments (logs captured by platform)
Behavior:
  • Logs appear in real-time in your terminal
  • DEBUG/INFO → stdout
  • WARN/ERROR/FATAL → stderr
  • No log rotation (handled by system)

FILE

LogType.FILE = 1
Write logs to persistent files on disk with automatic rotation. Best for:
  • Production deployments
  • Long-running services
  • Applications requiring audit trails
  • Systems without centralized logging
Behavior:
  • Logs written to specified directory
  • Automatic file rotation based on size
  • Old logs cleaned up after retention period
  • Configurable file naming and size limits

Configuration Options

When using LogType.FILE, these additional parameters control file behavior:
log_dir
str
default:"\"./logs\""
Directory for log files. Must exist (not created automatically).
log_basename
str
default:"\"zvec.log\""
Base name for log files. Rotated files get numbered suffixes (e.g., zvec.log.1).
log_file_size
int
default:"2048"
Maximum size per log file in MB before rotation.
log_overdue_days
int
default:"7"
Days to retain rotated log files before deletion.

Usage Examples

Console Logging (Development)

import zvec
from zvec import LogType, LogLevel

# Simple console logging
zvec.init(
    log_type=LogType.CONSOLE,
    log_level=LogLevel.INFO
)

# Logs appear in terminal
collection = zvec.create_and_open(...)
# Output: [INFO] Collection opened: ./my_collection

File Logging (Production)

import zvec
from zvec import LogType, LogLevel
import os

# Ensure log directory exists
os.makedirs("/var/log/myapp", exist_ok=True)

# Configure file-based logging
zvec.init(
    log_type=LogType.FILE,
    log_level=LogLevel.WARN,
    log_dir="/var/log/myapp",
    log_basename="zvec.log",
    log_file_size=4096,      # 4GB per file
    log_overdue_days=30      # Keep for 30 days
)

# Logs written to /var/log/myapp/zvec.log
collection = zvec.create_and_open(...)

File Rotation Behavior

# Log files with rotation:
/var/log/myapp/zvec.log        # Current active log
/var/log/myapp/zvec.log.1      # Previous rotation
/var/log/myapp/zvec.log.2      # Older rotation
/var/log/myapp/zvec.log.3      # Oldest (deleted after retention period)

Use Case Recommendations

zvec.init(
    log_type=LogType.CONSOLE,
    log_level=LogLevel.DEBUG  # See everything
)
Why: Immediate feedback in terminal, no file management needed.

Important Notes

Directory Must Exist: When using LogType.FILE, ensure the log_dir exists before initializing Zvec. The directory is not created automatically.
import os
os.makedirs("/var/log/myapp", exist_ok=True)
zvec.init(log_type=LogType.FILE, log_dir="/var/log/myapp")
File Permissions: The process running Zvec must have write permissions to the log directory.
Log Aggregation: In production, consider using LogType.CONSOLE with a log aggregation service (e.g., ELK, Splunk, CloudWatch) instead of managing files directly.

See Also

Build docs developers (and LLMs) love