Skip to content

Commit

Permalink
update for color support (#17)
Browse files Browse the repository at this point in the history
* update for color support

* add sshot from log/color

* fixing the buildinfo output
  • Loading branch information
ldemailly authored Jul 6, 2023
1 parent c002a36 commit 742b5a7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ You can see real use example in a server like [proxy](https://github.com/fortio/

Server example [sampleServer](sampleServer/main.go)

Previous style (non structured json log format):
Previous style (non structured json, no color log format):
```bash
% go run . -config-dir ./config -config-port 8888 -json-log=false a b
% go run . -config-dir ./config -config-port 8888 -logger-no-color -logger-json=false a b
14:50:54 I updater.go:47> Configmap flag value watching on ./config
14:50:54 I updater.go:156> updating loglevel to "verbose\n"
14:50:54 I logger.go:183> Log level is now 1 Verbose (was 2 Info)
Expand All @@ -25,8 +25,7 @@ Previous style (non structured json log format):
14:50:54 I scli.go:90> Starting sampleServer dev go1.20.3 arm64 darwin
14:50:55 I main.go:16> FD count 1s after start : 16
# When visiting the UI
14:51:06 ListFlags: GET / HTTP/1.1 [::1]:64731 () ...
# ...
14:51:10 I http_logging.go:73> ListFlags, method="GET", url="/", proto="HTTP/1.1", remote_addr="[::1]:59034",
14:51:15 I main.go:18> FD count 20s later : 16
14:51:15 I main.go:21> FD count stability check: 16
14:51:15 I main.go:21> FD count stability check: 16
Expand All @@ -47,7 +46,7 @@ With the flags ui on http://localhost:8888
New default style of logging since 1.5 (JSON for servers):
```bash
$ go run . -config-dir ./config -config-port 8888 a b
$ go run . -config-dir ./config -config-port 8888 a b 2>&1 | cat # forces no color because stderr isn't a terminal
```
```json
{"ts":1686609103.447926,"level":"info","file":"updater.go","line":47,"msg":"Configmap flag value watching on ./config"}
Expand All @@ -72,6 +71,10 @@ $ go run . -config-dir ./config -config-port 8888 a b
{"ts":1686609129.019703,"level":"info","file":"main.go","line":29,"msg":"Normal exit"}
```
And console output default colorized mode comes from [log](https://github.com/fortio/log#log)'s 1.6.0 or newer:
![Color example](https://github.com/fortio/log/blob/main/color.png)
## Additional builtins
(coming from `cli`'s base module)
Expand All @@ -80,13 +83,13 @@ $ go run . -config-dir ./config -config-port 8888 a b
e.g
```bash
$ go install fortio.org/cli/sampleServer@latest
go: downloading fortio.org/cli v1.7.0
$ go install fortio.org/scli/sampleServer@latest
go: downloading fortio.org/scli v1.7.0
$ sampleServer buildinfo
dev go1.20.5 arm64 darwin
1.7.0 h1:NC3z2k+2NY5zTB+XoQGX2MKJulMq61gltK8OrkR3U9U= go1.20.5 arm64 darwin
go go1.20.5
path fortio.org/cli/sampleServer
mod fortio.org/scli v1.7.0 h1:orn3xqUVLtgkD9LgYtAovVZtfzOzN0qCuItRTd5Z+d4=
path fortio.org/scli/sampleServer
mod fortio.org/scli v1.7.0 h1:NC3z2k+2NY5zTB+XoQGX2MKJulMq61gltK8OrkR3U9U=
dep fortio.org/cli v1.1.0 h1:ATIxi7DgA7WAexUCF8p5a0qlGYk48ZgkwSEDrvwXeN4=
dep fortio.org/dflag v1.5.2 h1:F9XVRj4Qr2IbJP7BMj7XZc9wB0Q/RZ61Ool+4YPVad8=
dep fortio.org/log v1.5.0 h1:0f/O7QPXQoDSnRjy8t0IyxTlQOYQsDOe0EO4Wnw8yCA=
Expand All @@ -95,6 +98,7 @@ dep fortio.org/version v1.0.2 h1:8NwxdX58aoeKx7T5xAPO0xlUu1Hpk42nRz5s6e6eKZ0=
dep github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
dep golang.org/x/exp v0.0.0-20230420155640-133eef4313cb h1:rhjz/8Mbfa8xROFiH+MQphmAmgqRM0bOMnytznhWEXk=
dep golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
build -buildmode=exe
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
Expand All @@ -107,7 +111,7 @@ build GOOS=darwin
### help
```bash
sampleServer 1.7.0 usage:
sampleServer 1.8.0 usage:
sampleServer [flags] arg1 arg2 [arg3...arg4]
or 1 of the special arguments
sampleServer {help|version|buildinfo}
Expand All @@ -118,8 +122,12 @@ flags:
Config port to open for dynamic flag UI/api
-logger-file-line
Filename and line numbers emitted in JSON logs, use -logger-file-line=false to disable (default true)
-logger-force-color
Force color output even if stderr isn't a terminal
-logger-json
Log in JSON format, use -logger-json=false to disable (default true)
-logger-no-color
Prevent colorized output even if stderr is a terminal
-logger-timestamp
Timestamps emitted in JSON logs, use -logger-timestamp=false to disable (default true)
-loglevel level
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module fortio.org/scli
go 1.18

require (
fortio.org/cli v1.1.0
fortio.org/cli v1.2.0
fortio.org/dflag v1.5.2
fortio.org/log v1.5.0
fortio.org/log v1.6.0
fortio.org/version v1.0.2
golang.org/x/sys v0.10.0
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
fortio.org/assert v1.1.4 h1:Za1RaG+OjsTMpQS3J3UCvTF6wc4+IOHCz+jAOU37Y4o=
fortio.org/cli v1.1.0 h1:ATIxi7DgA7WAexUCF8p5a0qlGYk48ZgkwSEDrvwXeN4=
fortio.org/cli v1.1.0/go.mod h1:O3nVImKwJSvHKbMYWkqMbEagAXCS1xvSv1YbHwkKJjY=
fortio.org/cli v1.2.0 h1:MXmbYnbNHcclf0xYLZjeCnTINby7FpooJxR01+hnBmM=
fortio.org/cli v1.2.0/go.mod h1:zJwHjRnvVqneF7ES+REfElc33xMjhbRDJslSrqIK9Kk=
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.5.0 h1:0f/O7QPXQoDSnRjy8t0IyxTlQOYQsDOe0EO4Wnw8yCA=
fortio.org/log v1.5.0/go.mod h1:u/8/2lyczXq52aT5Nw6reD+3cR6m/EbS2jBiIYhgiTU=
fortio.org/log v1.6.0 h1:GYt2UjoZdURBEb7J1fxBmLOirOrKvKhKKi7xLScqg1A=
fortio.org/log v1.6.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 Down

0 comments on commit 742b5a7

Please sign in to comment.