Skip to content

Commit

Permalink
Update to log 1.5.0 with sec.usec TS format/example (#14)
Browse files Browse the repository at this point in the history
* update to log 1.5.0 with sec.usec TS format/example. Add flag to remove TS and rename the JSON one
  • Loading branch information
ldemailly authored Jun 26, 2023
1 parent 16ea058 commit 0e3e726
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ New default style of logging since 1.5 (JSON for servers):
$ go run . -config-dir ./config -config-port 8888 a b
```
```json
{"ts":1686609103447926,"level":"info","file":"updater.go","line":47,"msg":"Configmap flag value watching on ./config"}
{"ts":1686609103449381,"level":"info","file":"updater.go","line":156,"msg":"updating loglevel to \"verbose\\n\""}
{"ts":1686609103449406,"level":"info","file":"logger.go","line":224,"msg":"Log level is now 1 Verbose (was 2 Info)"}
{"ts":1686609103450125,"level":"info","file":"updater.go","line":97,"msg":"Now watching . and config"}
{"ts":1686609103450240,"level":"info","file":"updater.go","line":162,"msg":"Background thread watching config now running"}
{"ts":1686609103450523,"level":"info","file":"scli.go","line":87,"msg":"Fortio scli dev dflag config server listening on [::]:8888"}
{"ts":1686609103450534,"level":"info","file":"scli.go","line":96,"msg":"Starting sampleServer dev go1.20.5 arm64 darwin"}
{"ts":1686609104452193,"level":"info","file":"main.go","line":16,"msg":"FD count 1s after start : 14"}
{"ts":1686609103.447926,"level":"info","file":"updater.go","line":47,"msg":"Configmap flag value watching on ./config"}
{"ts":1686609103.449381,"level":"info","file":"updater.go","line":156,"msg":"updating loglevel to \"verbose\\n\""}
{"ts":1686609103.449406,"level":"info","file":"logger.go","line":224,"msg":"Log level is now 1 Verbose (was 2 Info)"}
{"ts":1686609103.450125,"level":"info","file":"updater.go","line":97,"msg":"Now watching . and config"}
{"ts":1686609103.450240,"level":"info","file":"updater.go","line":162,"msg":"Background thread watching config now running"}
{"ts":1686609103.450523,"level":"info","file":"scli.go","line":87,"msg":"Fortio scli dev dflag config server listening on [::]:8888"}
{"ts":1686609103.450534,"level":"info","file":"scli.go","line":96,"msg":"Starting sampleServer dev go1.20.5 arm64 darwin"}
{"ts":1686609104.452193,"level":"info","file":"main.go","line":16,"msg":"FD count 1s after start : 14"}
# list flag (curl localhost:8888)
{"ts":1686609330309960,"level":"info","file":"http_logging.go","line":73,"msg":"ListFlags","method":"GET","url":"/","proto":"HTTP/1.1","remote_addr":"127.0.0.1:60554","header.x-forwarded-proto":"","header.x-forwarded-for":"","user-agent":"curl/8.0.1","header.host":"localhost:8888","header.User-Agent":"curl/8.0.1","header.Accept":"*/*"}
{"ts":1686609124453697,"level":"info","file":"main.go","line":18,"msg":"FD count 20s later : 14"}
{"ts":1686609124454075,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124454411,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124454745,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124455071,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124455462,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124455482,"level":"info","file":"main.go","line":27,"msg":"Running until interrupted (ctrl-c)..."}
{"ts":1686609330.309960,"level":"info","file":"http_logging.go","line":73,"msg":"ListFlags","method":"GET","url":"/","proto":"HTTP/1.1","remote_addr":"127.0.0.1:60554","header.x-forwarded-proto":"","header.x-forwarded-for":"","user-agent":"curl/8.0.1","header.host":"localhost:8888","header.User-Agent":"curl/8.0.1","header.Accept":"*/*"}
{"ts":1686609124.453697,"level":"info","file":"main.go","line":18,"msg":"FD count 20s later : 14"}
{"ts":1686609124.454075,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124.454411,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124.454745,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124.455071,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124.455462,"level":"info","file":"main.go","line":21,"msg":"FD count stability check: 14"}
{"ts":1686609124.455482,"level":"info","file":"main.go","line":27,"msg":"Running until interrupted (ctrl-c)..."}
# After ^C
{"ts":1686609129019649,"level":"warn","file":"scli.go","line":107,"msg":"Interrupt received."}
{"ts":1686609129019703,"level":"info","file":"main.go","line":29,"msg":"Normal exit"}
{"ts":1686609129.019649,"level":"warn","file":"scli.go","line":107,"msg":"Interrupt received."}
{"ts":1686609129.019703,"level":"info","file":"main.go","line":29,"msg":"Normal exit"}
```
## Additional builtins
Expand Down Expand Up @@ -109,8 +109,7 @@ build GOOS=darwin
### help
```bash
$ sampleServer help
sampleServer 0.1.0 usage:
sampleServer 1.6.0 usage:
sampleServer [flags] arg1 arg2 [arg3...arg4]
or 1 of the special arguments
sampleServer {help|version|buildinfo}
Expand All @@ -119,15 +118,19 @@ flags:
Config directory to watch for dynamic flag changes
-config-port port
Config port to open for dynamic flag UI/api
-logger-json
Log in JSON format, use -logger-json=false to disable (default true)
-logger-timestamp
Timestamps emitted in JSON logs, use -logger-timestamp=false to disable (default true)
-loglevel level
log level, one of [Debug Verbose Info Warning Error Critical Fatal] (default Info)
-quiet
Quiet mode, sets log level to warning
Quiet mode, sets loglevel to Error (quietly) to reduces the output
```
### version
Short 'numeric' version (v skipped, useful for docker image tags etc)
```bash
$ sampleServer version
0.1.1
1.6.0
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.18
require (
fortio.org/cli v1.1.0
fortio.org/dflag v1.5.2
fortio.org/log v1.4.0
fortio.org/log v1.5.0
fortio.org/version v1.0.2
golang.org/x/sys v0.8.0
golang.org/x/sys v0.9.0
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ fortio.org/cli v1.1.0 h1:ATIxi7DgA7WAexUCF8p5a0qlGYk48ZgkwSEDrvwXeN4=
fortio.org/cli v1.1.0/go.mod h1:O3nVImKwJSvHKbMYWkqMbEagAXCS1xvSv1YbHwkKJjY=
fortio.org/dflag v1.5.2 h1:F9XVRj4Qr2IbJP7BMj7XZc9wB0Q/RZ61Ool+4YPVad8=
fortio.org/dflag v1.5.2/go.mod h1:ppb/A8u+KKg+qUUYZNYuvRnXuVb8IsdHb/XGzsmjkN8=
fortio.org/log v1.4.0 h1:xTCWj0nCj1QFw+QoBmOmxLsXXb7nqtwyoNGYcLFWEA4=
fortio.org/log v1.4.0/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU=
fortio.org/log v1.5.0 h1:0f/O7QPXQoDSnRjy8t0IyxTlQOYQsDOe0EO4Wnw8yCA=
fortio.org/log v1.5.0/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU=
fortio.org/sets v1.0.3 h1:HzewdGjH69YmyW06yzplL35lGr+X4OcqQt0qS6jbaO4=
fortio.org/sets v1.0.3/go.mod h1:QZVj0r6KP/ZD9ebySW9SgxVNy/NjghUfyHW9NN+WU+4=
fortio.org/version v1.0.2 h1:8NwxdX58aoeKx7T5xAPO0xlUu1Hpk42nRz5s6e6eKZ0=
Expand All @@ -14,5 +14,5 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb h1:rhjz/8Mbfa8xROFiH+MQphmAmgqRM0bOMnytznhWEXk=
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9 changes: 7 additions & 2 deletions scli.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ func ServerMain() bool {
configDir := flag.String("config-dir", "", "Config `directory` to watch for dynamic flag changes")
configPort := flag.String("config-port", "", "Config `port` to open for dynamic flag UI/api")
dynloglevel.LoggerFlagSetup("loglevel")
dflag.DynBool(flag.CommandLine, "json-log", true,
"Log in JSON format, use -json-log=false to disable").WithSyncNotifier(func(_ bool, newValue bool) {
dflag.DynBool(flag.CommandLine, "logger-json", true,
"Log in JSON format, use -logger-json=false to disable").WithSyncNotifier(func(_ bool, newValue bool) {
log.Debugf("Changing log format to JSON %v", newValue)
log.Config.JSON = newValue
})
dflag.DynBool(flag.CommandLine, "logger-timestamp", true,
"Timestamps emitted in JSON logs, use -logger-timestamp=false to disable").WithSyncNotifier(func(_ bool, newValue bool) {
log.Debugf("Changing log format to JSON timestamp %v", newValue)
log.Config.NoTimestamp = !newValue
})
cli.ServerMode = true
cli.Main() // will call ExitFunction() if there are usage errors
if *configDir != "" {
Expand Down

0 comments on commit 0e3e726

Please sign in to comment.