From 73f0ca5a2f83bd2b1d7ff87456f59366b2d0f038 Mon Sep 17 00:00:00 2001 From: llaoj Date: Mon, 14 Nov 2022 08:53:57 +0800 Subject: [PATCH] writes log --- README.md | 10 +++++----- utils/log.go | 4 ++-- webtty/webtty.go | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1c7fbe0..0e0f869 100644 --- a/README.md +++ b/README.md @@ -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 ``` -## Operation log +## Writes log 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`: ```sh -# !/bin/bash +#!/bin/bash echo "Welcome: $4" 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:14 [oplog] pwdCR {"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 [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 diff --git a/utils/log.go b/utils/log.go index 66ac4a3..8c57be2 100644 --- a/utils/log.go +++ b/utils/log.go @@ -1,8 +1,8 @@ package utils -func FormatOperationLog(line *[]byte) (log string) { +func FormatWriteLog(line *[]byte) (log string) { ascii := map[byte]string{ - 0: "", //NUL + 0: "NUL", 1: "SOH", 2: "STX", 3: "ETX", diff --git a/webtty/webtty.go b/webtty/webtty.go index 9c940dc..5f6193b 100644 --- a/webtty/webtty.go +++ b/webtty/webtty.go @@ -194,7 +194,8 @@ func (wt *WebTTY) handleMasterReadEvent(data []byte, line *[]byte) error { if err != nil { 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 }