writes log

This commit is contained in:
llaoj 2022-11-14 08:53:57 +08:00
parent a7d7ea6629
commit 73f0ca5a2f
3 changed files with 9 additions and 8 deletions

View File

@ -151,7 +151,7 @@ When you want to create a jailed environment for each client, you can use Docker
$ gotty -w docker run -it --rm busybox $ gotty -w docker run -it --rm busybox
``` ```
## Operation log ## Writes log
User's input in terminal can be found in logs. for example: User's input in terminal can be found in logs. for example:
@ -164,7 +164,7 @@ if you run gotty like this:
this is `test.sh`: this is `test.sh`:
```sh ```sh
# !/bin/bash #!/bin/bash
echo "Welcome: $4" echo "Welcome: $4"
kubectl -n $1 exec -it $2 -c $3 -- sh kubectl -n $1 exec -it $2 -c $3 -- sh
@ -174,12 +174,12 @@ visit `http://127.0.0.1:8080/?arg=without-istio&arg=sleep-7b6d569576-57sjq&arg=s
``` ```
... ...
2022/11/13 10:48:12 [oplog] lsCR {"arg":["without-istio","sleep-7b6d569576-57sjq","sleep","21001713"]} 2022/11/13 10:48:12 [wlog] lsCR {"arg":["without-istio","sleep-7b6d569576-57sjq","sleep","21001713"]}
2022/11/13 10:48:14 [oplog] pwdCR {"arg":["without-istio","sleep-7b6d569576-57sjq","sleep","21001713"]} 2022/11/13 10:48:14 [wlog] pwdCR {"arg":["without-istio","sleep-7b6d569576-57sjq","sleep","21001713"]}
... ...
``` ```
Using the `[oplog]` flag, you can collect and store these logs persistently. All args are in the log, including the userID. Using the `[wlog]` flag, you can collect and store these logs persistently. All args are in the log, including the userID.
## Development ## Development

View File

@ -1,8 +1,8 @@
package utils package utils
func FormatOperationLog(line *[]byte) (log string) { func FormatWriteLog(line *[]byte) (log string) {
ascii := map[byte]string{ ascii := map[byte]string{
0: "", //NUL 0: "NUL",
1: "SOH", 1: "SOH",
2: "STX", 2: "STX",
3: "ETX", 3: "ETX",

View File

@ -194,7 +194,8 @@ func (wt *WebTTY) handleMasterReadEvent(data []byte, line *[]byte) error {
if err != nil { if err != nil {
return errors.Wrapf(err, "failed to marshal arguments map") return errors.Wrapf(err, "failed to marshal arguments map")
} }
log.Printf("[oplog] %s %s\n", utils.FormatOperationLog(line), string(argumentsByte)) log.Printf("[wlog] %v\n", line)
log.Printf("[wlog] %s %s\n", utils.FormatWriteLog(line), string(argumentsByte))
*line = nil *line = nil
} }