This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git
The following commit(s) were added to refs/heads/main by this push:
new 01b80d9 chore: Add new logs and support time format display (#136)
01b80d9 is described below
commit 01b80d98a38154f4f80d9cdb128b9d81727f2b80
Author: youjie23 <[email protected]>
AuthorDate: Wed Nov 5 13:44:55 2025 +0800
chore: Add new logs and support time format display (#136)
---
commands/verify/verify.go | 16 +++++++++++-----
internal/components/trigger/http.go | 1 +
internal/{logger => constant}/log.go | 24 ++++--------------------
internal/logger/log.go | 5 ++++-
4 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/commands/verify/verify.go b/commands/verify/verify.go
index a09751e..7b866dc 100644
--- a/commands/verify/verify.go
+++ b/commands/verify/verify.go
@@ -20,6 +20,7 @@ package verify
import (
"context"
"fmt"
+ "github.com/apache/skywalking-infra-e2e/internal/constant"
"sync"
"time"
@@ -219,7 +220,7 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo
*verifyInfo) (err err
if v.GetExpected() == "" {
res[idx].Skip = false
- res[idx].Msg = fmt.Sprintf("failed to verify %v",
caseName(v))
+ res[idx].Msg = fmt.Sprintf("%s failed to verify %v",
formatVerificationTime(), caseName(v))
res[idx].Err = fmt.Errorf("the expected data file for
%v is not specified", caseName(v))
printer.Warning(res[idx].Msg)
@@ -233,9 +234,9 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo
*verifyInfo) (err err
for current := 0; current <= verifyInfo.retryCount; current++ {
if d, e := verifySingleCase(v.GetExpected(),
v.GetActual(), v.Query); e == nil {
if current == 0 {
- res[idx].Msg = fmt.Sprintf("verified %v
\n", caseName(v))
+ res[idx].Msg = fmt.Sprintf("%s verified
%v \n", formatVerificationTime(), caseName(v))
} else {
- res[idx].Msg = fmt.Sprintf("verified
%v, retried %d time(s)\n", caseName(v), current)
+ res[idx].Msg = fmt.Sprintf("%s verified
%v, retried %d time(s)\n", formatVerificationTime(), caseName(v), current)
}
res[idx].Skip = false
printer.Success(res[idx].Msg)
@@ -244,11 +245,12 @@ func verifyCasesSerially(verify *config.Verify,
verifyInfo *verifyInfo) (err err
if current == 0 {
printer.UpdateText(fmt.Sprintf("failed
to verify %v, will continue retry:", caseName(v)))
} else {
- printer.UpdateText(fmt.Sprintf("failed
to verify %v, retry [%d/%d]", caseName(v), current, verifyInfo.retryCount))
+ printer.UpdateText(fmt.Sprintf("failed
to verify %v, retry [%d/%d]", caseName(v), current,
+ verifyInfo.retryCount))
}
time.Sleep(verifyInfo.interval)
} else {
- res[idx].Msg = fmt.Sprintf("failed to verify
%v, retried %d time(s)", caseName(v), current)
+ res[idx].Msg = fmt.Sprintf("%s failed to verify
%v, retried %d time(s)", formatVerificationTime(), caseName(v), current)
if d != "" {
res[idx].Msg += fmt.Sprintf(", the
actual data is:\n%s\n", d)
}
@@ -267,6 +269,10 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo
*verifyInfo) (err err
return nil
}
+func formatVerificationTime() string {
+ return time.Now().Format(constant.LogTimestampFormat)
+}
+
func caseName(v *config.VerifyCase) string {
if v.Name == "" {
if v.Actual != "" {
diff --git a/internal/components/trigger/http.go
b/internal/components/trigger/http.go
index e1a035e..1a8cbd4 100644
--- a/internal/components/trigger/http.go
+++ b/internal/components/trigger/http.go
@@ -99,6 +99,7 @@ func (h *httpAction) Do() chan error {
if !sent && (err == nil || h.times ==
h.executedCount) {
result <- err
sent = true
+ logger.Log.Infof("trigger has sent
result after executed %d requests with err: %v", h.executedCount, err)
}
if h.times != math.MaxInt32 && h.executedCount
>= h.times {
logger.Log.Infof("trigger has completed
%d requests and will stop.", h.executedCount)
diff --git a/internal/logger/log.go b/internal/constant/log.go
similarity index 70%
copy from internal/logger/log.go
copy to internal/constant/log.go
index cdc6353..e2b6c2e 100644
--- a/internal/logger/log.go
+++ b/internal/constant/log.go
@@ -14,26 +14,10 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
+//
-package logger
-
-import (
- "os"
+package constant
- "github.com/sirupsen/logrus"
+const (
+ LogTimestampFormat = "2006-01-02 15:04:05"
)
-
-var Log *logrus.Logger
-
-func init() {
- if Log == nil {
- Log = logrus.New()
- }
- Log.Level = logrus.InfoLevel
- Log.SetOutput(os.Stdout)
- Log.SetFormatter(&logrus.TextFormatter{
- DisableTimestamp: true,
- DisableLevelTruncation: true,
- ForceColors: true,
- })
-}
diff --git a/internal/logger/log.go b/internal/logger/log.go
index cdc6353..2d9a19c 100644
--- a/internal/logger/log.go
+++ b/internal/logger/log.go
@@ -18,6 +18,7 @@
package logger
import (
+ "github.com/apache/skywalking-infra-e2e/internal/constant"
"os"
"github.com/sirupsen/logrus"
@@ -32,7 +33,9 @@ func init() {
Log.Level = logrus.InfoLevel
Log.SetOutput(os.Stdout)
Log.SetFormatter(&logrus.TextFormatter{
- DisableTimestamp: true,
+ DisableTimestamp: false,
+ FullTimestamp: true,
+ TimestampFormat: constant.LogTimestampFormat,
DisableLevelTruncation: true,
ForceColors: true,
})