@@ -9,22 +9,27 @@ import (
9
9
)
10
10
11
11
type options struct {
12
- errorFieldname string
13
- durationFieldname string
14
- timeFieldname string
15
- sqlQueryFieldname string
16
- sqlArgsFieldname string
17
- stmtIDFieldname string
18
- connIDFieldname string
19
- txIDFieldname string
20
- sqlQueryAsMsg bool
21
- logArgs bool
22
- logDriverErrSkip bool
23
- wrapResult bool
24
- minimumLogLevel Level
25
- durationUnit DurationUnit
26
- timeFormat TimeFormat
27
- uidGenerator UIDGenerator
12
+ errorFieldname string
13
+ durationFieldname string
14
+ timeFieldname string
15
+ startTimeFieldname string
16
+ sqlQueryFieldname string
17
+ sqlArgsFieldname string
18
+ stmtIDFieldname string
19
+ connIDFieldname string
20
+ txIDFieldname string
21
+ sqlQueryAsMsg bool
22
+ logArgs bool
23
+ logDriverErrSkip bool
24
+ wrapResult bool
25
+ minimumLogLevel Level
26
+ durationUnit DurationUnit
27
+ timeFormat TimeFormat
28
+ uidGenerator UIDGenerator
29
+ includeStartTime bool
30
+ preparerLevel Level
31
+ queryerLevel Level
32
+ execerLevel Level
28
33
}
29
34
30
35
// setDefaultOptions called first time before Log() called (see: OpenDriver()).
@@ -33,6 +38,7 @@ func setDefaultOptions(opt *options) {
33
38
opt .errorFieldname = "error"
34
39
opt .durationFieldname = "duration"
35
40
opt .timeFieldname = "time"
41
+ opt .startTimeFieldname = "start"
36
42
opt .sqlQueryFieldname = "query"
37
43
opt .sqlArgsFieldname = "args"
38
44
opt .stmtIDFieldname = "stmt_id"
@@ -46,6 +52,10 @@ func setDefaultOptions(opt *options) {
46
52
opt .durationUnit = DurationMillisecond
47
53
opt .timeFormat = TimeFormatUnix
48
54
opt .uidGenerator = newDefaultUIDDGenerator ()
55
+ opt .includeStartTime = false
56
+ opt .preparerLevel = LevelInfo
57
+ opt .queryerLevel = LevelInfo
58
+ opt .execerLevel = LevelInfo
49
59
}
50
60
51
61
// DurationUnit is total time spent on an actual driver function call calculated by time.Since(start).
@@ -140,7 +150,7 @@ func (u *defaultUID) UniqueID() string {
140
150
// using math/rand.Read because it's slightly faster than crypto/rand.Read
141
151
// unique id always scoped under connectionID so there is no need to super-secure-random using crypto/rand.
142
152
//
143
- // nolint: gosec
153
+ // nolint // disable gosec check as it does not need crypto/rand
144
154
if _ , err := rand .Read (random [:]); err != nil {
145
155
panic (fmt .Sprintf ("sqldblogger: random read error from math/rand: '%s'" , err .Error ()))
146
156
}
@@ -332,3 +342,53 @@ func WithWrapResult(flag bool) Option {
332
342
opt .wrapResult = flag
333
343
}
334
344
}
345
+
346
+ // WithIncludeStartTime flag to include actual start time before actual driver execution.
347
+ //
348
+ // Can be useful if we want to combine Log implementation with tracing from context
349
+ // and set start time span manually.
350
+ //
351
+ // Default: false
352
+ func WithIncludeStartTime (flag bool ) Option {
353
+ return func (opt * options ) {
354
+ opt .includeStartTime = flag
355
+ }
356
+ }
357
+
358
+ // WithStartTimeFieldname to customize start time fieldname on log output.
359
+ //
360
+ // If WithIncludeStartTime true, start time fieldname will use this value.
361
+ //
362
+ // Default: "start"
363
+ func WithStartTimeFieldname (name string ) Option {
364
+ return func (opt * options ) {
365
+ opt .startTimeFieldname = name
366
+ }
367
+ }
368
+
369
+ // WithPreparerLevel set default level of Prepare(Context) method calls.
370
+ //
371
+ // Default: LevelInfo
372
+ func WithPreparerLevel (lvl Level ) Option {
373
+ return func (opt * options ) {
374
+ opt .preparerLevel = lvl
375
+ }
376
+ }
377
+
378
+ // WithQueryerLevel set default level of Query(Context) method calls.
379
+ //
380
+ // Default: LevelInfo
381
+ func WithQueryerLevel (lvl Level ) Option {
382
+ return func (opt * options ) {
383
+ opt .queryerLevel = lvl
384
+ }
385
+ }
386
+
387
+ // WithExecerLevel set default level of Exec(Context) method calls.
388
+ //
389
+ // Default: LevelInfo
390
+ func WithExecerLevel (lvl Level ) Option {
391
+ return func (opt * options ) {
392
+ opt .execerLevel = lvl
393
+ }
394
+ }
0 commit comments