Skip to content

Commit

Permalink
Log HTTP requests with TRACE log level
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Dec 6, 2024
1 parent e3285d8 commit 8d74cd0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ psql postgres://localhost:54321/bemidb -c \
| `--database` | `BEMIDB_DATABASE` | `bemidb` | Database name |
| `--storage-type` | `BEMIDB_STORAGE_TYPE` | `LOCAL` | Storage type: `LOCAL` or `S3` |
| `--storage-path` | `BEMIDB_STORAGE_PATH` | `iceberg` | Path to the storage folder |
| `--log-level` | `BEMIDB_LOG_LEVEL` | `INFO` | Log level: `DEBUG`, `INFO`, `WARN`, or `ERROR` |
| `--log-level` | `BEMIDB_LOG_LEVEL` | `INFO` | Log level: `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE` |
| `--init-sql ` | `BEMIDB_INIT_SQL` | `./init.sql` | Path to the initialization SQL file |
| `--user` | `BEMIDB_USER` | | Database user. Allows any if empty |
| `--password` | `BEMIDB_PASSWORD` | | Database password. Allows any if empty |
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION="0.18.0"
VERSION="0.19.0"

# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
Expand Down
2 changes: 1 addition & 1 deletion src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func registerFlags() {
flag.StringVar(&_password, "password", os.Getenv(ENV_PASSWORD), "Database password. Default: \""+DEFAULT_PASSWORD+"\"")
flag.StringVar(&_config.StoragePath, "storage-path", os.Getenv(ENV_STORAGE_PATH), "Path to the storage folder. Default: \""+DEFAULT_STORAGE_PATH+"\"")
flag.StringVar(&_config.InitSqlFilepath, "init-sql", os.Getenv(ENV_INIT_SQL_FILEPATH), "Path to the initialization SQL file. Default: \""+DEFAULT_INIT_SQL_FILEPATH+"\"")
flag.StringVar(&_config.LogLevel, "log-level", os.Getenv(ENV_LOG_LEVEL), "Log level: \"DEBUG\", \"INFO\", \"WARN\", \"ERROR\". Default: \""+DEFAULT_LOG_LEVEL+"\"")
flag.StringVar(&_config.LogLevel, "log-level", os.Getenv(ENV_LOG_LEVEL), "Log level: \"ERROR\", \"WARN\", \"INFO\", \"DEBUG\", \"TRACE\". Default: \""+DEFAULT_LOG_LEVEL+"\"")
flag.StringVar(&_config.StorageType, "storage-type", os.Getenv(ENV_STORAGE_TYPE), "Storage type: \"LOCAL\", \"S3\". Default: \""+DEFAULT_DB_STORAGE_TYPE+"\"")
flag.StringVar(&_config.Pg.SchemaPrefix, "pg-schema-prefix", os.Getenv(ENV_PG_SCHEMA_PREFIX), "(Optional) Prefix for PostgreSQL schema names")
flag.StringVar(&_config.Pg.SyncInterval, "pg-sync-interval", os.Getenv(ENV_PG_SYNC_INTERVAL), "(Optional) Interval between syncs. Valid units: \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\"")
Expand Down
6 changes: 5 additions & 1 deletion src/duckdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ func NewDuckdb(config *Config) *Duckdb {
"region": config.Aws.Region,
"s3Bucket": "s3://" + config.Aws.S3Bucket,
}))
LogDebug(config, "Querying DuckDB:", query)
PanicIfError(err)

if config.LogLevel == LOG_LEVEL_TRACE {
_, err = db.ExecContext(ctx, "SET enable_http_logging=true")
PanicIfError(err)
}
}

return &Duckdb{
Expand Down
8 changes: 5 additions & 3 deletions src/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
type LogLevel string

const (
LOG_LEVEL_TRACE = "TRACE"
LOG_LEVEL_DEBUG = "DEBUG"
LOG_LEVEL_WARN = "WARN"
LOG_LEVEL_INFO = "INFO"
LOG_LEVEL_ERROR = "ERROR"
)

var LOG_LEVELS = []string{
LOG_LEVEL_TRACE,
LOG_LEVEL_DEBUG,
LOG_LEVEL_WARN,
LOG_LEVEL_INFO,
Expand All @@ -25,19 +27,19 @@ func LogError(config *Config, message ...interface{}) {
}

func LogWarn(config *Config, message ...interface{}) {
if config.LogLevel == LOG_LEVEL_WARN || config.LogLevel == LOG_LEVEL_INFO || config.LogLevel == LOG_LEVEL_DEBUG {
if config.LogLevel != LOG_LEVEL_ERROR {
log.Println(append([]interface{}{"[WARN]"}, message...)...)
}
}

func LogInfo(config *Config, message ...interface{}) {
if config.LogLevel == LOG_LEVEL_INFO || config.LogLevel == LOG_LEVEL_DEBUG {
if config.LogLevel != LOG_LEVEL_ERROR && config.LogLevel != LOG_LEVEL_WARN {
log.Println(append([]interface{}{"[INFO]"}, message...)...)
}
}

func LogDebug(config *Config, message ...interface{}) {
if config.LogLevel == LOG_LEVEL_DEBUG {
if config.LogLevel != LOG_LEVEL_ERROR && config.LogLevel != LOG_LEVEL_WARN && config.LogLevel != LOG_LEVEL_INFO {
log.Println(append([]interface{}{"[DEBUG]"}, message...)...)
}
}
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

const VERSION = "0.18.0"
const VERSION = "0.19.0"

func main() {
config := LoadConfig()
Expand Down

0 comments on commit 8d74cd0

Please sign in to comment.