Skip to main content

A lightweight logging utility for dbt projects

Project description

dbt-logger

A logging utility that captures dbt command output and stores it in Snowflake for auditing and monitoring. Uses your existing dbt credentials - no additional configuration needed!

Installation

pip install dbt-logger

Quick Start

The simplest way - uses your existing dbt profiles.yml:

from dbt_logger import DbtLogger

# Automatically uses credentials from dbt profiles.yml
logger = DbtLogger(repo_name="my_analytics_project")

# Run dbt commands and log them
logger.run_command("dbt build")
logger.run_command("dbt run --select +sales_model")

That's it! Logs are automatically saved to [your_dbt_database].logging.dbt_logging

Configuration File (Optional)

Create dbt/dbt_logger.yml in your dbt project to configure logging destination:

# dbt/dbt_logger.yml

# Option 1: Custom schema in dbt database
schema: audit_logs

# Option 2: Completely separate database for logs
database: ADMIN_DB
schema: LOGGING
table_name: dbt_execution_logs

Precedence order:

  1. Parameters passed to DbtLogger() (highest)
  2. Settings in dbt/dbt_logger.yml
  3. Defaults: {dbt_database}.logging.dbt_logging (lowest)

Configuration Options

Use Specific dbt Profile/Target

# Use a specific profile and target from profiles.yml
logger = DbtLogger(
    repo_name="my_project",
    profile_name="my_profile",  # Optional: defaults to first profile
    target="prod"                # Optional: defaults to profile's default target
)

Override Logging Location in Code

# Override config file settings
logger = DbtLogger(
    repo_name="my_project",
    database="ADMIN_DB",
    schema="LOGGING",
    table_name="my_custom_logs"
)

Manual Connection Parameters (Advanced)

If you need to use different credentials than dbt:

from dbt_logger import DbtLogger, get_connection_params_from_env

# Option 1: From environment variables
connection_params = get_connection_params_from_env()

# Option 2: Manual dict
connection_params = {
    'account': 'your_account',
    'user': 'your_user',
    'password': 'your_password',
    'database': 'your_database',
    'warehouse': 'your_warehouse',
}

logger = DbtLogger(
    repo_name="my_project",
    connection_params=connection_params
)

How It Works

  1. Reads your dbt profiles.yml - Automatically finds and parses your dbt configuration
  2. Supports private key auth - Works with your existing DBT_USER, DBT_PVK_PATH, DBT_PVK_PASS env vars
  3. Creates logging infrastructure - Auto-creates schema and table on first run
  4. Captures everything - Runs dbt commands and logs all output in real-time
  5. Stores in Snowflake - Saves command history for auditing and monitoring

Logging Table Schema

-- Default location: [your_dbt_database].logging.dbt_logging
CREATE TABLE dbt_logging (
    repo_name STRING,      -- Your dbt project/repo name
    command STRING,        -- The dbt command executed
    stdout_log STRING,     -- Complete command output
    log_time TIMESTAMP_LTZ -- Execution timestamp
);

dbt profiles.yml Locations

The logger checks for profiles.yml in this order:

  1. $DBT_PROFILES_DIR/profiles.yml
  2. ./dbt/profiles/profiles.yml (current directory)
  3. ~/.dbt/profiles.yml (default dbt location)

Features

  • Zero Config - Uses your existing dbt credentials
  • Private Key Auth - Full support for private key authentication
  • Auto Setup - Creates schema and table automatically
  • Real-time Output - See command output live while logging
  • Flexible Storage - Default to dbt database or use separate logging database
  • Environment Variables - Resolves Jinja env_var() expressions from profiles.yml

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt_logger-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbt_logger-0.1.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file dbt_logger-0.1.0.tar.gz.

File metadata

  • Download URL: dbt_logger-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbt_logger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ef43c3097ccb20f9f98e0460c9c83a158fde9a52917ed944f2fc1125021810c
MD5 f2df14d4f3781b2a176e939cbc215955
BLAKE2b-256 71b1fa7fd46cc909d9e9ac9170115d380cb2b520fa46d7817d24936f171d9a56

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbt_logger-0.1.0.tar.gz:

Publisher: publish.yml on TristanSchwartz/dbt-logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbt_logger-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dbt_logger-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbt_logger-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb58901724f2c4bbb6ecb0a70268979af4a058e4f94150bbe1f8651fe918bbcd
MD5 78f35ff3021b77a9eb6f92764075b9cb
BLAKE2b-256 6d1e40d5fbeff84b739b2fe4a9ab596387d8fb6a22777f857260b88ddafb7db6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbt_logger-0.1.0-py3-none-any.whl:

Publisher: publish.yml on TristanSchwartz/dbt-logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page