mirror of
https://github.com/kopia/kopia.git
synced 2026-01-05 21:17:52 -05:00
This is a breaking change to users who might be using Kopia as a library.
### Log Format
```json
{"t":"<timestamp-rfc-3389-microseconds>", "span:T1":"V1", "span:T2":"V2", "n":"<source>", "m":"<message>", /*parameters*/}
```
Where each record is associated with one or more spans that describe its scope:
* `"span:client": "<hash-of-username@hostname>"`
* `"span:repo": "<random>"` - random identifier of a repository connection (from `repo.Open`)
* `"span:maintenance": "<random>"` - random identifier of a maintenance session
* `"span:upload": "<hash-of-username@host:/path>"` - uniquely identifies upload session of a given directory
* `"span:checkpoint": "<random>"` - encapsulates each checkpoint operation during Upload
* `"span:server-session": "<random>"` -single client connection to the server
* `"span:flush": "<random>"` - encapsulates each Flush session
* `"span:maintenance": "<random>"` - encapsulates each maintenance operation
* `"span:loadIndex" : "<random>"` - encapsulates index loading operation
* `"span:emr" : "<random>"` - encapsulates epoch manager refresh
* `"span:writePack": "<pack-blob-ID>"` - encapsulates pack blob preparation and writing
(plus additional minor spans for various phases of the maintenance).
Notable points:
- Used internal zero allocation JSON writer for reduced memory usage.
- renamed `--disable-internal-log` to `--disable-repository-log` (controls saving blobs to repository)
- added `--disable-content-log` (controls writing of `content-log` files)
- all storage operations are also logged in a structural way and associated with the corresponding spans.
- all content IDs are logged in a truncated format (since first N bytes that are usually enough to be unique) to improve compressibility of logs (blob IDs are frequently repeated but content IDs usually appear just once).
This format should make it possible to recreate the journey of any single content throughout pack blobs, indexes and compaction events.
135 lines
2.8 KiB
Go
135 lines
2.8 KiB
Go
// Package logparam provides parameters for logging.
|
|
package logparam
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/kopia/kopia/internal/contentlog"
|
|
)
|
|
|
|
// String creates a string parameter.
|
|
//
|
|
//nolint:revive
|
|
func String(key, value string) stringParam {
|
|
return stringParam{Key: key, Value: value}
|
|
}
|
|
|
|
// Int64 creates an int64 parameter.
|
|
//
|
|
//nolint:revive
|
|
func Int64(key string, value int64) int64Param { return int64Param{Key: key, Value: value} }
|
|
|
|
// Int creates an int parameter.
|
|
//
|
|
//nolint:revive
|
|
func Int(key string, value int) int64Param {
|
|
return int64Param{Key: key, Value: int64(value)}
|
|
}
|
|
|
|
// Int32 creates an int32 parameter.
|
|
//
|
|
//nolint:revive
|
|
func Int32(key string, value int32) int64Param {
|
|
return int64Param{Key: key, Value: int64(value)}
|
|
}
|
|
|
|
// Bool creates a bool parameter.
|
|
//
|
|
//nolint:revive
|
|
func Bool(key string, value bool) boolParam { return boolParam{Key: key, Value: value} }
|
|
|
|
// Time creates a time parameter.
|
|
//
|
|
//nolint:revive
|
|
func Time(key string, value time.Time) timeParam { return timeParam{Key: key, Value: value} }
|
|
|
|
// Error creates an error parameter.
|
|
//
|
|
//nolint:revive
|
|
func Error(key string, value error) errorParam { return errorParam{Key: key, Value: value} }
|
|
|
|
// UInt64 creates a uint64 parameter.
|
|
//
|
|
//nolint:revive
|
|
func UInt64(key string, value uint64) uint64Param {
|
|
return uint64Param{Key: key, Value: value}
|
|
}
|
|
|
|
// UInt32 creates a uint32 parameter.
|
|
//
|
|
//nolint:revive
|
|
func UInt32(key string, value uint32) uint64Param {
|
|
return uint64Param{Key: key, Value: uint64(value)}
|
|
}
|
|
|
|
// Duration creates a duration parameter.
|
|
//
|
|
//nolint:revive
|
|
func Duration(key string, value time.Duration) durationParam {
|
|
return durationParam{Key: key, Value: value}
|
|
}
|
|
|
|
// int64Param is a parameter that writes a int64 value to the JSON writer.
|
|
type int64Param struct {
|
|
Key string
|
|
Value int64
|
|
}
|
|
|
|
func (v int64Param) WriteValueTo(jw *contentlog.JSONWriter) {
|
|
jw.Int64Field(v.Key, v.Value)
|
|
}
|
|
|
|
type uint64Param struct {
|
|
Key string
|
|
Value uint64
|
|
}
|
|
|
|
func (v uint64Param) WriteValueTo(jw *contentlog.JSONWriter) {
|
|
jw.UInt64Field(v.Key, v.Value)
|
|
}
|
|
|
|
type timeParam struct {
|
|
Key string
|
|
Value time.Time
|
|
}
|
|
|
|
func (v timeParam) WriteValueTo(jw *contentlog.JSONWriter) {
|
|
jw.TimeField(v.Key, v.Value)
|
|
}
|
|
|
|
type boolParam struct {
|
|
Key string
|
|
Value bool
|
|
}
|
|
|
|
func (v boolParam) WriteValueTo(jw *contentlog.JSONWriter) {
|
|
jw.BoolField(v.Key, v.Value)
|
|
}
|
|
|
|
type durationParam struct {
|
|
Key string
|
|
Value time.Duration
|
|
}
|
|
|
|
func (v durationParam) WriteValueTo(jw *contentlog.JSONWriter) {
|
|
jw.Int64Field(v.Key, v.Value.Microseconds())
|
|
}
|
|
|
|
type errorParam struct {
|
|
Key string
|
|
Value error
|
|
}
|
|
|
|
func (v errorParam) WriteValueTo(jw *contentlog.JSONWriter) {
|
|
jw.ErrorField(v.Key, v.Value)
|
|
}
|
|
|
|
type stringParam struct {
|
|
Key string
|
|
Value string
|
|
}
|
|
|
|
func (v stringParam) WriteValueTo(jw *contentlog.JSONWriter) {
|
|
jw.StringField(v.Key, v.Value)
|
|
}
|