Skip to content

Commit 5f15fed

Browse files
committed
* Removed support of YDB_LOG_NO_COLOR environment variable
* Changed default behaviour of internal logger to without coloring * Fixed coloring (to true) with environment variable `YDB_LOG_SEVERITY_LEVEL`
1 parent 47508b3 commit 5f15fed

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Added `database/sql` events for tracing `database/sql` driver events
44
* Added internal logging for `database/sql` events
55
* Supports `YDB_LOG_DETAILS` environment variable for specify scope of log messages
6+
* Removed support of `YDB_LOG_NO_COLOR` environment variable
7+
* Changed default behaviour of internal logger to without coloring
8+
* Fixed coloring (to true) with environment variable `YDB_LOG_SEVERITY_LEVEL`
69

710
## v3.33.0
811
* Added `retry.DoTx` helper for retrying `database/sql` transactions

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ Next packages provide debug tooling:
126126
|----------------------------------|-----------|---------|--------------------------------------------------------------------------------------------------------------------------|
127127
| `YDB_SSL_ROOT_CERTIFICATES_FILE` | `string` | | path to certificates file |
128128
| `YDB_LOG_SEVERITY_LEVEL` | `string` | `quiet` | severity logging level of internal driver logger. Supported: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `quiet` |
129-
| `YDB_LOG_DETAILS` | `string` | `.*` | pattern for lookup internal logger logs |
130-
| `YDB_LOG_NO_COLOR` | `bool` | `false` | set any non empty value to disable colouring logs with internal driver logger |
129+
| `YDB_LOG_DETAILS` | `string` | `.*` | regexp for lookup internal logger logs |
131130
| `GRPC_GO_LOG_VERBOSITY_LEVEL` | `integer` | | set to `99` to see grpc logs |
132131
| `GRPC_GO_LOG_SEVERITY_LEVEL` | `string` | | set to `info` to see grpc logs |

connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func open(ctx context.Context, opts ...Option) (_ Connection, err error) {
376376
),
377377
WithNamespace("ydb"),
378378
WithMinLevel(log.FromString(logLevel)),
379-
WithNoColor(os.Getenv("YDB_LOG_NO_COLOR") != ""),
379+
WithColoring(),
380380
),
381381
)
382382
}

discovery/discovery_e2e_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestDiscovery(t *testing.T) {
6868
ydb.WithOutWriter(os.Stdout),
6969
ydb.WithErrWriter(os.Stdout),
7070
ydb.WithMinLevel(log.WARN),
71+
ydb.WithColoring(),
7172
),
7273
ydb.WithUserAgent(userAgent),
7374
ydb.WithRequestsType(requestType),

internal/logger/log.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ type logger struct {
2020
external log.Logger
2121
namespace string
2222
minLevel level.Level
23-
noColor bool
23+
coloring bool
2424
out io.Writer
2525
err io.Writer
2626
}
2727

2828
func New(opts ...Option) *logger {
2929
l := &logger{
3030
minLevel: level.INFO,
31-
noColor: false,
31+
coloring: false,
3232
out: os.Stdout,
3333
err: os.Stderr,
3434
}
@@ -39,25 +39,25 @@ func New(opts ...Option) *logger {
3939
}
4040

4141
func (l *logger) format(format string, logLevel level.Level) string {
42-
if l.noColor {
42+
if l.coloring {
4343
return fmt.Sprintf(
44-
"%-5s %23s %26s %s\n",
44+
"%s%-5s %23s %26s%s %s%s%s\n",
45+
logLevel.BoldColor(),
4546
logLevel.String(),
4647
time.Now().Format(dateLayout),
4748
"["+l.namespace+"]",
49+
colorReset,
50+
logLevel.Color(),
4851
format,
52+
colorReset,
4953
)
5054
}
5155
return fmt.Sprintf(
52-
"%s%-5s %23s %26s%s %s%s%s\n",
53-
logLevel.BoldColor(),
56+
"%-5s %23s %26s %s\n",
5457
logLevel.String(),
5558
time.Now().Format(dateLayout),
5659
"["+l.namespace+"]",
57-
colorReset,
58-
logLevel.Color(),
5960
format,
60-
colorReset,
6161
)
6262
}
6363

@@ -144,6 +144,6 @@ func (l *logger) WithName(name string) log.Logger {
144144
err: l.err,
145145
namespace: join(l.namespace, name),
146146
minLevel: l.minLevel,
147-
noColor: l.noColor,
147+
coloring: l.coloring,
148148
}
149149
}

internal/logger/options.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import (
99

1010
type Option func(l *logger)
1111

12-
func WithNoColor(b bool) Option {
12+
func Nop() Option {
13+
return func(l *logger) {}
14+
}
15+
16+
func WithColoring() Option {
1317
return func(l *logger) {
14-
l.noColor = b
18+
l.coloring = true
1519
}
1620
}
1721

logger_options.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ func WithMinLevel(minLevel log.Level) LoggerOption {
1818
return LoggerOption(logger.WithMinLevel(level.Level(minLevel)))
1919
}
2020

21+
// WithNoColor specified coloring of log messages
22+
//
23+
// Deprecated: has no effect now, use WithColoring instead
2124
func WithNoColor(b bool) LoggerOption {
22-
return LoggerOption(logger.WithNoColor(b))
25+
return LoggerOption(logger.Nop())
26+
}
27+
28+
func WithColoring() LoggerOption {
29+
return LoggerOption(logger.WithColoring())
2330
}
2431

2532
func WithExternalLogger(external log.Logger) LoggerOption {

0 commit comments

Comments
 (0)