A logger for Go SQL database driver without modify existing *sql.DB stdlib usage.

SQLDB-Logger

Build Status Coverage Status Go Report Card Sonar Violations (long format) Sonar Tech Debt Sonar Quality Gate Documentation License

A logger for Go SQL database driver without modify existing *sql.DB stdlib usage.

shameless console output sample Colored console writer output above only for sample/development

FEATURES

  • Leveled, detailed and configurable logging.
  • Keep using (or re-use existing) *sql.DB as is.
  • Bring your own logger backend via simple log interface.
  • Trackable log output:
    • Every call has its own unique ID.
    • Prepared statement and execution will have same ID.
    • On execution/result error, it will include the query, arguments, params, and related IDs.

INSTALL

go get -u -v github.com/simukti/sqldb-logger

Version pinning using dependency manager such as Mod or Dep is highly recommended.

USAGE

As a start, Logger is just a simple interface:

type Logger interface {
	Log(ctx context.Context, level Level, msg string, data map[string]interface{})
}

There are 4 included basic implementation that uses well-known JSON structured logger for quickstart:

Note: those adapters does not use given context, you need to modify it and adjust with your needs. (example: add http request id/whatever value from context to query log when you call QueryerContext andExecerContext methods)

Then for that logger to works, you need to integrate with a compatible driver which will be used by *sql.DB.

INTEGRATE WITH EXISTING SQL DB DRIVER

Re-use from existing *sql.DB driver, this is the simplest way:

For example, from:

dsn := "username:passwd@tcp(mysqlserver:3306)/dbname?parseTime=true"
db, err := sql.Open("mysql", dsn) // db is *sql.DB
db.Ping() // to check connectivity and DSN correctness

To:

// import sqldblogger "github.com/simukti/sqldb-logger"
// import "github.com/simukti/sqldb-logger/logadapter/zerologadapter"
dsn := "username:passwd@tcp(mysqlserver:3306)/dbname?parseTime=true"
db, err := sql.Open("mysql", dsn) // db is *sql.DB
// handle err
loggerAdapter := zerologadapter.New(zerolog.New(os.Stdout))
db = sqldblogger.OpenDriver(dsn, db.Driver(), loggerAdapter/*, using_default_options*/) // db is STILL *sql.DB
db.Ping() // to check connectivity and DSN correctness

That's it, all *sql.DB interaction now logged.

INTEGRATE WITH SQL DRIVER STRUCT

It is also possible to integrate with following public empty struct driver directly:

MySQL (go-sql-driver/mysql)

db := sqldblogger.OpenDriver(dsn, &mysql.MySQLDriver{}, loggerAdapter /*, ...options */)

PostgreSQL (lib/pq)

db := sqldblogger.OpenDriver(dsn, &pq.Driver{}, loggerAdapter /*, ...options */) 

SQLite3 (mattn/go-sqlite3)

db := sqldblogger.OpenDriver(dsn, &sqlite3.SQLiteDriver{}, loggerAdapter /*, ...options */)

Following struct drivers maybe compatible:

SQL Server (denisenkom/go-mssqldb)

db := sqldblogger.OpenDriver(dsn, &mssql.Driver{}, loggerAdapter /*, ...options */)

Oracle (mattn/go-oci8)

db := sqldblogger.OpenDriver(dsn, oci8.OCI8Driver, loggerAdapter /*, ...options */)

LOGGER OPTIONS

When using sqldblogger.OpenDriver(dsn, driver, logger, opt...) without 4th variadic argument, it will use default options.

Here is sample of OpenDriver() using all available options and use non-default value:

db = sqldblogger.OpenDriver(
    dsn, 
    db.Driver(), 
    loggerAdapter,
    // AVAILABLE OPTIONS
    sqldblogger.WithErrorFieldname("sql_error"),                    // default: error
    sqldblogger.WithDurationFieldname("query_duration"),            // default: duration
    sqldblogger.WithTimeFieldname("log_time"),                      // default: time
    sqldblogger.WithSQLQueryFieldname("sql_query"),                 // default: query
    sqldblogger.WithSQLArgsFieldname("sql_args"),                   // default: args
    sqldblogger.WithMinimumLevel(sqldblogger.LevelTrace),           // default: LevelDebug
    sqldblogger.WithLogArguments(false),                            // default: true
    sqldblogger.WithDurationUnit(sqldblogger.DurationNanosecond),   // default: DurationMillisecond
    sqldblogger.WithTimeFormat(sqldblogger.TimeFormatRFC3339),      // default: TimeFormatUnix
    sqldblogger.WithLogDriverErrorSkip(true),                       // default: false
    sqldblogger.WithSQLQueryAsMessage(true),                        // default: false
    sqldblogger.WithUIDGenerator(sqldblogger.UIDGenerator),         // default: *defaultUID
    sqldblogger.WithConnectionIDFieldname("con_id"),                // default: conn_id
    sqldblogger.WithStatementIDFieldname("stm_id"),                 // default: stmt_id
    sqldblogger.WithTransactionIDFieldname("trx_id"),               // default: tx_id
    sqldblogger.WithWrapResult(false),                              // default: true
    sqldblogger.WithIncludeStartTime(true),                         // default: false
    sqldblogger.WithStartTimeFieldname("start_time"),               // default: start
    sqldblogger.WithPreparerLevel(sqldblogger.LevelDebug),          // default: LevelInfo
    sqldblogger.WithQueryerLevel(sqldblogger.LevelDebug),           // default: LevelInfo
    sqldblogger.WithExecerLevel(sqldblogger.LevelDebug),            // default: LevelInfo
)

Click here for options documentation.

MOTIVATION

I want to:

  • Keep using *sql.DB.
  • Have configurable output field.
  • Leverage structured logging.
  • Fetch and log context.Context value if needed.
  • Re-use pgx log interface.

I haven't found Go *sql.DB logger with that features, so why not created myself?

REFERENCES

CONTRIBUTE

If you found a bug, typo, wrong test, idea, help with existing issue, or anything constructive.

Don't hesitate to create an issue or pull request.

CREDITS

  • pgx for awesome PostgreSQL driver.

LICENSE

MIT

Owner
Sarjono Mukti Aji
Simple doesn't mean easy
Sarjono Mukti Aji
Comments
  • Bump github.com/stretchr/testify from 1.5.1 to 1.6.0

    Bump github.com/stretchr/testify from 1.5.1 to 1.6.0

    Bumps github.com/stretchr/testify from 1.5.1 to 1.6.0.

    Release notes

    Sourced from github.com/stretchr/testify's releases.

    v1.6.0

    Latest release of testify. This includes many fixes and enhancements. Please view the v1.6.0 milestone for a list of changes.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Bump github.com/sirupsen/logrus from 1.6.0 to 1.7.0

    Bump github.com/sirupsen/logrus from 1.6.0 to 1.7.0

    Bumps github.com/sirupsen/logrus from 1.6.0 to 1.7.0.

    Release notes

    Sourced from github.com/sirupsen/logrus's releases.

    Add new BufferPool and LogFunction APIs

    • a new buffer pool management API has been added
    • a set of <LogLevel>Fn() functions have been added
    • the dependency toward a windows terminal library has been removed
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Bump github.com/rs/zerolog from 1.19.0 to 1.20.0

    Bump github.com/rs/zerolog from 1.19.0 to 1.20.0

    Bumps github.com/rs/zerolog from 1.19.0 to 1.20.0.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Bump go.uber.org/zap from 1.15.0 to 1.16.0

    Bump go.uber.org/zap from 1.15.0 to 1.16.0

    Bumps go.uber.org/zap from 1.15.0 to 1.16.0.

    Release notes

    Sourced from go.uber.org/zap's releases.

    v1.16.0

    Bugfixes:

    • #828[]: Fix missing newline in IncreaseLevel error messages.
    • #835[]: Fix panic in JSON encoder when encoding times or durations without specifying a time or duration encoder.
    • #843[]: Honor CallerSkip when taking stack traces.
    • #862[]: Fix the default file permissions to use 0666 and rely on the umask instead.
    • #854[]: Encode <nil> for nil Stringer instead of a panic error log.

    Enhancements:

    • #629[]: Added zapcore.TimeEncoderOfLayout to easily create time encoders for custom layouts.
    • #697[]: Added support for a configurable delimiter in the console encoder.
    • #852[]: Optimize console encoder by pooling the underlying JSON encoder.
    • #844[]: Add ability to include the calling function as part of logs.
    • #843[]: Add StackSkip for including truncated stacks as a field.
    • #861[]: Add options to customize Fatal behaviour for better testability.

    Thanks to @SteelPhase, @tmshn, @lixingwang, @wyxloading, @moul, @segevfiner, @andy-retailnext and @jcorbin for their contributions to this release.

    #629: uber-go/zap#629 #697: uber-go/zap#697 #828: uber-go/zap#828 #835: uber-go/zap#835 #843: uber-go/zap#843 #844: uber-go/zap#844 #852: uber-go/zap#852 #854: uber-go/zap#854 #861: uber-go/zap#861 #862: uber-go/zap#862

    Changelog

    Sourced from go.uber.org/zap's changelog.

    1.16.0 (1 Sep 2020)

    Bugfixes:

    • #828[]: Fix missing newline in IncreaseLevel error messages.
    • #835[]: Fix panic in JSON encoder when encoding times or durations without specifying a time or duration encoder.
    • #843[]: Honor CallerSkip when taking stack traces.
    • #862[]: Fix the default file permissions to use 0666 and rely on the umask instead.
    • #854[]: Encode <nil> for nil Stringer instead of a panic error log.

    Enhancements:

    • #629[]: Added zapcore.TimeEncoderOfLayout to easily create time encoders for custom layouts.
    • #697[]: Added support for a configurable delimiter in the console encoder.
    • #852[]: Optimize console encoder by pooling the underlying JSON encoder.
    • #844[]: Add ability to include the calling function as part of logs.
    • #843[]: Add StackSkip for including truncated stacks as a field.
    • #861[]: Add options to customize Fatal behaviour for better testability.

    Thanks to @SteelPhase, @tmshn, @lixingwang, @wyxloading, @moul, @segevfiner, @andy-retailnext and @jcorbin for their contributions to this release.

    Commits
    • 404189c Prepare release v1.16.0 (#863)
    • d0a4b9e newFileSink: use normatve 0666 default perm to OpenFile (#862)
    • 217b2cb Add options to customize Fatal behaviour for better testability (#861)
    • be2be86 Update Stringer panic check to look like stdlib (#857)
    • 663c590 Show "<nil>" for nil Stringer. (#854)
    • 2657839 Honor CallerSkip when taking stack traces & add the StackSkip field (#843)
    • 2314926 Add New Function Log Entry (#844)
    • 639461d consoleEncoder: put cloned jsonEncoder back to pool (#852)
    • 53a3870 Support configurable delimiter for console encoder (#697)
    • 275c926 Added zapcore.TimeEncoderOfLayout (#629)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Bump github.com/stretchr/testify from 1.6.0 to 1.6.1

    Bump github.com/stretchr/testify from 1.6.0 to 1.6.1

    Bumps github.com/stretchr/testify from 1.6.0 to 1.6.1.

    Release notes

    Sourced from github.com/stretchr/testify's releases.

    Fixes breaking change with HTTPBodyContains

    A breaking change was accidentally released in v1.6.0 which breaks the API for the HTTPBodyContains and HTTPBodyNotContains, this release reverts that change.

    Commits
    • f654a91 Update Go versions in Travis
    • 3184a9e This reverts commit 0a813b5898c0ee8d00b4f13fae21ea5df8b35e74.
    • e2b269e This reverts commit 2adb7b54b75da2c74e9342ed115957fe0b07e0b4.
    • 6353e56 This reverts commit 9d083cac4a26c76f8d92dff41d459f3f2fc0b911.
    • 6561324 This reverts commit 484fff1ace1f0acb84676a548b53477685c16414.
    • 46420cf This reverts commit 1a43b8334acb9df58064b765cd16675cc7c2c8b3.
    • 303198d Revert "allow body for HTTPBodyContains and HTTPBodyNotContains for
    • e7cc868 Update TravisCI config
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Proposal: change unit test way about using global buffer

    Proposal: change unit test way about using global buffer

    This code is customized for my workload. It's not actual PR. I do not intend to surprise you. if you feel surprised I'll apologize.

    I'll make another PR soon in 2 weeks.

    Tasks

    1. Using global output buffer, change to member output buffer at each unit test.
    2. used const variables to define database actions.
    3. made a util function to check log level each a connection acitons.
  • adding hacky overriding log level

    adding hacky overriding log level

    This will allow us to do the following:

    dsn := "username:passwd@tcp(mysqlserver:3306)/dbname?parseTime=true"
    db, err := sql.Open("mysql", dsn) // db is *sql.DB
    // handle err
    loggerAdapter := zaplogadopter.New(...)
    db = sqldblogger.OpenDriver(
       dsn,
       db.Driver(),
       loggerAdapter,
       sqldblogger.WithMinimumLevel(sqldblogger.LevelError), // will only log connections and errors
    )
    
  • Bump github.com/rs/zerolog from 1.18.0 to 1.19.0

    Bump github.com/rs/zerolog from 1.18.0 to 1.19.0

    Bumps github.com/rs/zerolog from 1.18.0 to 1.19.0.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Bump github.com/sirupsen/logrus from 1.5.0 to 1.6.0

    Bump github.com/sirupsen/logrus from 1.5.0 to 1.6.0

    Bumps github.com/sirupsen/logrus from 1.5.0 to 1.6.0.

    Release notes

    Sourced from github.com/sirupsen/logrus's releases.

    Release v1.6.0

    Changelog

    Sourced from github.com/sirupsen/logrus's changelog.

    1.6.0

    Fixes:

    • end of line cleanup
    • revert the entry concurrency bug fix whic leads to deadlock under some circumstances
    • update dependency on go-windows-terminal-sequences to fix a crash with go 1.14

    Features:

    • add an option to the TextFormatter to completely disable fields quoting
    Commits
    • 60c74ad update CHANGELOG.md with 1.5.0 and 1.6.0 version contents
    • e8e563a Merge remote-tracking branch 'origin/master' into thlacroix-disable-quotes
    • 0fd458a complete documetation on TextFormatter.DisableQuote
    • 4d96c60 Merge branch 'disable-quotes' of https://github.com/thlacroix/logrus into thl...
    • a5b0247 Merge pull request #1136 from ialidzhikov/nit/line-endings
    • 163c051 Merge pull request #1137 from sirupsen/fix_crash_windows
    • e79215d update github.com/konsorten/go-windows-terminal-sequences dependency to v1.0.3
    • 4989a3f Change CRLF line endings to LF
    • aff00fe Adds additional test cases for DisableQuote
    • c7455de Adds flag to disable quotes in TextFormatter
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Bump go.uber.org/zap from 1.14.1 to 1.15.0

    Bump go.uber.org/zap from 1.14.1 to 1.15.0

    Bumps go.uber.org/zap from 1.14.1 to 1.15.0.

    Release notes

    Sourced from go.uber.org/zap's releases.

    v1.15.0

    Bugfixes:

    • #804[]: Fix handling of Time values out of UnixNano range.
    • #812[]: Fix IncreaseLevel being reset after a call to With.

    Enhancements:

    • #806[]: Add WithCaller option to supersede the AddCaller option. This allows disabling annotation of log entries with caller information if previously enabled with AddCaller.
    • #813[]: Deprecate NewSampler constructor in favor of NewSamplerWithOptions which supports a SamplerHook option. This option adds support for monitoring sampling decisions through a hook.

    Thanks to @danielbprice for their contributions to this release.

    #804: uber-go/zap#804 #812: uber-go/zap#812 #806: uber-go/zap#806 #813: uber-go/zap#813

    Changelog

    Sourced from go.uber.org/zap's changelog.

    1.15.0 (23 Apr 2020)

    Bugfixes:

    • #804[]: Fix handling of Time values out of UnixNano range.
    • #812[]: Fix IncreaseLevel being reset after a call to With.

    Enhancements:

    • #806[]: Add WithCaller option to supersede the AddCaller option. This allows disabling annotation of log entries with caller information if previously enabled with AddCaller.
    • #813[]: Deprecate NewSampler constructor in favor of NewSamplerWithOptions which supports a SamplerHook option. This option adds support for monitoring sampling decisions through a hook.

    Thanks to @danielbprice for their contributions to this release.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • Bump github.com/sirupsen/logrus from 1.4.2 to 1.5.0

    Bump github.com/sirupsen/logrus from 1.4.2 to 1.5.0

    Bumps github.com/sirupsen/logrus from 1.4.2 to 1.5.0.

    Release notes

    Sourced from github.com/sirupsen/logrus's releases.

    v1.5.0

    This new release introduces:

    • Ability to DisableHTMLEscape when using the JSON formatter: sirupsen/logrus#524
    • Support/fixes for go 1.14
    • Many many bugfixes
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
  • feat: to use const variables at all codes

    feat: to use const variables at all codes

    It's hard to recognize which actions is has a level between [queryer, executer, preparer].

    DB 'action' messages are needed to collect in a file. Also, log levels are separated by actions.

  • driver.ErrSkip is returned by methods that don't support it

    driver.ErrSkip is returned by methods that don't support it

    Hi, I'm trying to use this to wrap a driver that doesn't implement the context-aware methods from the sql package, but when I call db.Prepare I get driver.ErrSkip.

    That's because sqldblogger.connection implements driver.ConnPrepareContext, while the underlying driver doesn't, which means that db.Prepare will call PrepareContext on sqldblogger.connection, which in turn will return driver.ErrSkip so sql.DB handles it (ceb475bd061713e6792ca2e42f07f55c7a4c5b61). However, sql.DB doesn't handle it, as driver.ErrSkip is only supported in a couple methods

    // ErrSkip may be returned by some optional interfaces' methods to // indicate at runtime that the fast path is unavailable and the sql // package should continue as if the optional interface was not // implemented. ErrSkip is only supported where explicitly // documented. var ErrSkip = errors.New("driver: skip fast-path; continue as if unimplemented")

    A solution might be adding an option to use the context-less methods instead of returning driver.ErrSkip on methods that don't support driver.ErrSkip

  • feat: add option for injecting additional log fields

    feat: add option for injecting additional log fields

    I wanted the ability to inject some additional log fields at init time. Building on Option seemed like a logic fit for this functionality, which I've called "additional fields".

    This should allow a user to use something like this when initializing their logger:

    // multiple fields
    WithAdditionalFields(map[string]interface{}{"hello", "world"})
    
    // single field
    WithAdditionalField("hello", "world")
    

    It should be noted that I intentionally append the user-defined fields first so that in the event of a conflict, the internal ones will take precedence, which seemed like the right thing to do behaviorally.

  • Fix NamedValueChecker implemented on conn not used

    Fix NamedValueChecker implemented on conn not used

    Fixes #60

    https://github.com/golang/go/blob/0e85fd7561de869add933801c531bf25dee9561c/src/database/sql/convert.go#L129

    NamedValueChecker can also be implemented on connection, and above (golang's sql package) code fallbacks to it when statement does not implement it. This PR implements same behavior.

  • uint64 issues

    uint64 issues

    Hi, I'm trying to use this together with sqlx and have discovered a weird issue - when trying to insert uint64 value I get a: error: sql: converting argument $1 type: driver ColumnConverter error converted uint64 to unsupported type uint64

    The moment I remove sqldb-logger (by setting c.loggingEnabled = false), the issue goes away and everything works fine.

    Here some details on how I init the connection:

    import (
    	"context"
    	"database/sql"
    	_ "github.com/go-sql-driver/mysql"
    	"github.com/jmoiron/sqlx"
    	sqldblogger "github.com/simukti/sqldb-logger"
    )
    
    func init(c *Config) {
        dsn := c.MysqlConnectionString()
    
        sqlDb, err := sql.Open("mysql", dsn)
        if err != nil {
            return err
        }
        if c.loggingEnabled {
            sqlDb = sqldblogger.OpenDriver(dsn, sqlDb.Driver(), logger, sqldblogger.WithMinimumLevel(c.logLevel))
        }
    
        db := sqlx.NewDb(sqlDb, "mysql")
    }
    

    And then later I would run something like:

    func (s *Store) CreateAccount(context context.Context, accountId uint64, email string, username string) (bool, error) {
    	query := "INSERT INTO accounts (id, email, username, status, created_at, updated_at) VALUES (?, ?, ?, ?, NOW(), NOW())"
    	res, err := s.db.ExecContext(context, query, accountId, email, username, constants.AccountActive)
    	if err != nil {
    		return false, err
    	}
        return true, nil
    }
    

    And the CreateAccount will return an error specified above.

    Thoughts, ideas?

  • Configure transaction log level

    Configure transaction log level

    Great work on this library! It's really useful for debugging 👍🏼

    I'm wondering if these log levels can be made configurable instead of being hard-coded to Debug level.

System resource usage profiler tool which regularly takes snapshots of the memory and CPU load of one or more running processes so as to dynamically build up a profile of their usage of system resources.
System resource usage profiler tool which regularly takes snapshots of the memory and CPU load of one or more running processes so as to dynamically build up a profile of their usage of system resources.

Vegeta is a system resource usage tracking tool built to regularly take snapshots of the memory and CPU load of one or more running processes, so as to dynamically build up a profile of their usage of system resources.

Jan 16, 2022
Convenient Logger interface and std logger wrapper

Convenient logger interface and wrapper around std logger Interface type Logger interface { Error(err error) Debugf(format string, args ...interface

Nov 28, 2021
Logger - A thin wrapper of uber-go/zap logger for personal project

a thin wraper of uber-go/zap logger for personal project 0. thanks uber-go/zap B

Sep 17, 2022
Simple Golang tool for monitoring linux cpu, ram and disk usage.

Simple Golang tool for monitoring linux cpu, ram and disk usage.

Mar 19, 2022
Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email.

linux-alert Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email. Usage Create .env file from .env

Feb 6, 2022
A logger, for Go

Go-Log A logger, for Go! It's sort of log and code.google.com/p/log4go compatible, so in most cases can be used without any code changes. Breaking cha

Oct 7, 2022
Simple logger for Go programs. Allows custom formats for messages.
Simple logger for Go programs. Allows custom formats for messages.

go-logger A simple go logger for easy logging in your programs. Allows setting custom format for messages. Preview Install go get github.com/apsdehal/

Dec 17, 2022
Loggly Hooks for GO Logrus logger

Loggly Hooks for Logrus Usage package main import ( "github.com/sirupsen/logrus" "github.com/sebest/logrusly" ) var logglyToken string = "YOUR_LOG

Sep 26, 2022
A 12-factor app logger built for performance and happy development
A 12-factor app logger built for performance and happy development

logxi log XI is a structured 12-factor app logger built for speed and happy development. Simpler. Sane no-configuration defaults out of the box. Faste

Nov 27, 2022
Dead simple, super fast, zero allocation and modular logger for Golang

Onelog Onelog is a dead simple but very efficient JSON logger. It is one of the fastest JSON logger out there. Also, it is one of the logger with the

Sep 26, 2022
xlog is a logger for net/context aware HTTP applications
xlog is a logger for net/context aware HTTP applications

⚠️ Check zerolog, the successor of xlog. HTTP Handler Logger xlog is a logger for net/context aware HTTP applications. Unlike most loggers, xlog will

Sep 26, 2022
Zero Allocation JSON Logger
Zero Allocation JSON Logger

Zero Allocation JSON Logger The zerolog package provides a fast and simple logger dedicated to JSON output. Zerolog's API is designed to provide both

Jan 1, 2023
A powerful zero-dependency json logger.

ZKits Logger Library About This package is a library of ZKits project. This is a zero-dependency standard JSON log library that supports structured JS

Dec 14, 2022
Configurable Logger for Go

Timber! This is a logger implementation that supports multiple log levels, multiple output destinations with configurable formats and levels for each.

Jun 28, 2022
A feature-rich and easy to use logger for golang
A feature-rich and easy to use logger for golang

A feature-rich and easy to use logger for golang ?? Install ?? Common Logs lumber.Success() lumber.Info() lumber.Debug() lumber.Warning()

Dec 31, 2022
A minimal and extensible structured logger

⚠️ PRE-RELEASE ⚠️ DO NOT IMPORT THIS MODULE YOUR PROJECT WILL BREAK package log package log provides a minimal interface for structured logging in ser

Jan 7, 2023
HTTP request logger for Golang
HTTP request logger for Golang

Horus ?? Introduction Horus is a request logger and viewer for Go. It allows developers log and view http requests made to their web application. Inst

Dec 27, 2022
Simple Yet Powerful Logger

sypl sypl provides a Simple Yet Powerful Logger built on top of the Golang sypl. A sypl logger can have many Outputs, and each Output is responsible f

Sep 23, 2022
simple concurrent logger

XMUS-LOGGER pure golang logger compatible with golang io standards. USAGE : logOptions := logger.LoggerOptions{ LogLevel: 6, // read more about lo

Aug 1, 2022