permify icon indicating copy to clipboard operation
permify copied to clipboard

Implement `slog` Logging in Postgres

Open tolgaozen opened this issue 3 years ago • 1 comments

Description

The objective is to enhance our logging mechanism within the internal/storage/postgres directory of our codebase. We plan to use slog, a feature in the new version of Go, for detailed and efficient logging. This will significantly improve our debugging and monitoring capabilities for our Postgres datastore.

Suggested Implementation

  • Integrate slog for Advanced Logging: Adopt slog for logging in the internal/storage/postgres directory, capturing detailed log information at different levels (debug, info, warning, error).
  • Ensure Compatibility with Postgres: Validate that slog is compatible and works efficiently with our Postgres implementation.
  • Consistent Logging Standards: Develop and maintain consistent logging formats and practices.

Example Code with slog Integration

Below is an example showing how slog can be implemented in the internal/storage/postgres directory:

package postgres

// ... Other imports ...
import "path/to/slog"

// ... Existing code ...

// Begin a new read-only transaction with the specified isolation level.
var tx *sql.Tx
tx, err = r.database.DB.BeginTx(ctx, &r.txOptions)
if err != nil {
    slog.Error("Error starting transaction: ", err)
    // ... other error handling ...
    return nil, nil, err
}

slog.Debug("Transaction started")

// Rollback the transaction in case of any error.
defer utils.Rollback(tx)

// Build relationships query
// ... building query ...
slog.Info("Building relationships query")
// ... applying filters ...
slog.Debug("Applied tuples filter to query builder")
// ... more query modifications ...
slog.Debug("Applied snapshot query to query builder")

// ... Rest of your code ...

Goals

Contextual Logging: Implement detailed logging within the internal/storage/postgres directory. Enhanced Debugging: Enable better debugging and error tracing with clear, contextual log messages. Monitor Logging Impact: Assess the impact of logging on system performance and database interactions.

tolgaozen avatar Nov 14 '23 12:11 tolgaozen

Please assign to me!

sayfshaikh avatar Nov 14 '23 15:11 sayfshaikh