func logReqResp2Db(ctx context.Context, db *sql.DB, t *tracker, opts *Opts) error {
	var (
		rowsInserted int
		respHdr      interface{}
		respBody     interface{}
		reqHdr       interface{}
		reqBody      interface{}
	)
	reqHdr = nil
	if opts.Log2DB.Request.Header {
		reqHdr = strNil(t.request.header)
	}
	reqBody = nil
	if opts.Log2DB.Request.Body {
		reqBody = strNil(t.request.body)
	}
	respHdr = nil
	if opts.Log2DB.Response.Header {
		respHdr = strNil(t.response.header)
	}
	respBody = nil
	if opts.Log2DB.Response.Body {
		respBody = strNil(t.response.body)
	}
	durMS := t.duration / time.Millisecond
	tx, err := db.BeginTx(ctx, nil)
	if err != nil {
		return err
	}
	stmt, err := tx.PrepareContext(ctx, `select app.log_request (
		p_request_id => $1,
		p_client_id => $2,
		p_request_timestamp => $3,
		p_response_code => $4,
		p_response_timestamp => $5,
		p_duration_in_millis => $6,
		p_protocol => $7,
		p_protocol_major => $8,
		p_protocol_minor => $9,
		p_request_method => $10,
		p_scheme => $11,
		p_host => $12,
		p_port => $13,
		p_path => $14,
		p_remote_address => $15,
		p_request_content_length => $16,
		p_request_header => $17,
		p_request_body => $18,
		p_response_header => $19,
		p_response_body => $20)`)
	if err != nil {
		log.Error().Err(err).Msg("")
		return err
	}
	defer stmt.Close()
	rows, err := stmt.QueryContext(ctx,
		t.requestID,              
		t.clientID,               
		t.timeStarted,            
		t.responseCode,           
		t.timeFinished,           
		durMS,                    
		t.request.proto,          
		t.request.protoMajor,     
		t.request.protoMinor,     
		t.request.method,         
		t.request.scheme,         
		t.request.host,           
		t.request.port,           
		t.request.path,           
		t.request.remoteAddr,     
		t.request.contentLength,  
		reqHdr,                   
		reqBody,                  
		respHdr,                  
		respBody)                 
	if err != nil {
		log.Error().Err(err).Msg("")
		return err
	}
	defer rows.Close()
	for rows.Next() {
		if err := rows.Scan(&rowsInserted); err != nil {
			log.Error().Err(err).Msg("")
			return err
		}
	}
	err = rows.Err()
	if err != nil {
		log.Error().Err(err).Msg("")
		return err
	}
	err = tx.Commit()
	if err != nil {
		log.Error().Err(err).Msg("")
		return err
	}
	return nil
}
logReqResp2Db creates a record in the api.audit_log table
using a stored function
package httplog
import (
	"context"
	"database/sql"
	"time"
	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
)
func responseLogController(ctx context.Context, log zerolog.Logger, db *sql.DB, t *tracker, opts *Opts) error {
	if opts.Log2StdOut.Response.Enable {
		logResp2Stdout(log, t)
	}
	if opts.Log2DB.Enable {
		err := logReqResp2Db(ctx, db, t, opts)
		if err != nil {
			log.Error().Err(err).Msg("")
			return err
		}
	}
	return nil
}
func logResp2Stdout(log zerolog.Logger, t *tracker) {
	log.Debug().Msg("logResponse started")
	defer log.Debug().Msg("logResponse ended")
	log.Info().
		Str("request_id", t.requestID).
		Int("response_code", t.responseCode).
		Str("response_header", t.response.header).
		Str("response_body", t.response.body).
		Msg("Response Sent")
}