From b55b53a85e36d9c4fa4fb5232740a498692c5a06 Mon Sep 17 00:00:00 2001 From: ZhangJian He Date: Sat, 2 Nov 2024 11:34:48 +0800 Subject: [PATCH] feat: add logger in application Signed-off-by: ZhangJian He --- go.mod | 15 ++++++++------- go.sum | 30 ++++++++++++++++-------------- main.go | 1 + pkg/boot/boot.go | 16 +++++++++++++--- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index aead2e1..418081c 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,13 @@ module github.com/opengemini/opengemini-client-go-application go 1.20 require ( - github.com/libgox/buffer v0.0.0-20241031081046-5d4932c890d4 - github.com/libgox/envx v0.0.0-20241031234047-a094467ecb9f - github.com/libgox/flyway v0.0.0-20241031081155-664faf8b516f - github.com/libgox/gocollections v0.0.0-20241031081053-07bce0388f78 - github.com/libgox/retry v0.0.0-20241101011336-167b47045bd9 - github.com/libgox/spring-cloud-go v0.0.3-0.20241026022417-5db252b8b188 + github.com/libgox/buffer v0.1.0 + github.com/libgox/envx v0.1.0 + github.com/libgox/flyway v0.1.0 + github.com/libgox/gocollections v0.1.0 + github.com/libgox/retry v0.1.0 + github.com/libgox/slogsimple v0.1.1 + github.com/libgox/spring-cloud-go v0.1.1 github.com/libgox/unicodex v0.0.1 github.com/protocol-laboratory/opcua-go v0.0.0-20241022080800-2ff8b0ffb7c8 golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 @@ -18,7 +19,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/libgox/addr v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/protocol-laboratory/zookeeper-client-go v0.0.4-0.20241026020853-9929d040af36 // indirect + github.com/protocol-laboratory/zookeeper-client-go v0.1.1 // indirect github.com/stretchr/testify v1.9.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index dcef52a..f9f0c09 100644 --- a/go.sum +++ b/go.sum @@ -24,18 +24,20 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= github.com/libgox/addr v0.2.0 h1:he4Vv7lzcGy/1qNpjJufEWRql0S23Ki/j0XpTDMDu3s= github.com/libgox/addr v0.2.0/go.mod h1:j0hEfpRqTZy4BsstS9Egsn1U0JmNdj/VkbF2VBmJlFw= -github.com/libgox/buffer v0.0.0-20241031081046-5d4932c890d4 h1:vpGf8mO0s2GRZuWSrX1MRWVwa6l+WAmMkkW5NxOag98= -github.com/libgox/buffer v0.0.0-20241031081046-5d4932c890d4/go.mod h1:VAuNNs9Mp5NttnP8etLB4FI4ZZ67sRUnk/jTb/BnSqo= -github.com/libgox/envx v0.0.0-20241031234047-a094467ecb9f h1:JRR+kDPnQOHRuURzLT15sI7v5WZ6qA/9ePZUMyzI7Ug= -github.com/libgox/envx v0.0.0-20241031234047-a094467ecb9f/go.mod h1:tY6BqljHogxCny9PPIB8lrK4ZusVXyPGdjjPrpQBGao= -github.com/libgox/flyway v0.0.0-20241031081155-664faf8b516f h1:ORjk8aiHiZcD153peCNEXlMP6pp2QCIKMx/h/VRGybQ= -github.com/libgox/flyway v0.0.0-20241031081155-664faf8b516f/go.mod h1:mGoke7/soomn6WdAOo75552S5Y8jjjUm6zudtM/WI9I= -github.com/libgox/gocollections v0.0.0-20241031081053-07bce0388f78 h1:qMJhPfSqjFjsWk4lufbQDH2Vu1cz9E0jKRZq4jm7bxI= -github.com/libgox/gocollections v0.0.0-20241031081053-07bce0388f78/go.mod h1:Y4udpR8lStv1f67hVWbMCrcTyTvf98bFFsu/ZXvAvZ0= -github.com/libgox/retry v0.0.0-20241101011336-167b47045bd9 h1:DTnutjCJRIbTHGwpaM9vyZ2MIT808NYGtxgHtrQ5UIE= -github.com/libgox/retry v0.0.0-20241101011336-167b47045bd9/go.mod h1:LVgyTROtcSz8k/vEgtRnoMSwIXKaGY57qZymrKMpb/M= -github.com/libgox/spring-cloud-go v0.0.3-0.20241026022417-5db252b8b188 h1:KWMS8mvvtWl3pDxB7qu2SCrYkm2WsgOymRK2p59thtw= -github.com/libgox/spring-cloud-go v0.0.3-0.20241026022417-5db252b8b188/go.mod h1:0bHHFwTumvrlRwU/yWndUzI93+RJDrm6pWbZl5dNjjs= +github.com/libgox/buffer v0.1.0 h1:a1cIIX4zW+7ybY/Ys20v/HmuhTvOsi3xdewirFl6mnc= +github.com/libgox/buffer v0.1.0/go.mod h1:VAuNNs9Mp5NttnP8etLB4FI4ZZ67sRUnk/jTb/BnSqo= +github.com/libgox/envx v0.1.0 h1:K/z+MYKKu/ixLclbxUmVXuyYvvemg7CwiRbnveoKpQw= +github.com/libgox/envx v0.1.0/go.mod h1:tY6BqljHogxCny9PPIB8lrK4ZusVXyPGdjjPrpQBGao= +github.com/libgox/flyway v0.1.0 h1:Bee3grCFVKzV+S3tvQDCQMVQqirekEttNXMiiSuZDUc= +github.com/libgox/flyway v0.1.0/go.mod h1:mGoke7/soomn6WdAOo75552S5Y8jjjUm6zudtM/WI9I= +github.com/libgox/gocollections v0.1.0 h1:uTvbl5SqayPgN9LDMeXD1QCU5mHNAwgtHc3Ktg7JiUA= +github.com/libgox/gocollections v0.1.0/go.mod h1:Y4udpR8lStv1f67hVWbMCrcTyTvf98bFFsu/ZXvAvZ0= +github.com/libgox/retry v0.1.0 h1:fNYUskjoFARnpWxaarQZfIv5wLZ+BM1qebEnAXH8R1U= +github.com/libgox/retry v0.1.0/go.mod h1:LQ3ivFBJelpV/nuuwxsf5KiLwORL+LaBIYrgnaDxyCo= +github.com/libgox/slogsimple v0.1.1 h1:xHQVmGm8pKgE2CqBZxQ9oAh+ucbb8wdhXFBZdlJQCHo= +github.com/libgox/slogsimple v0.1.1/go.mod h1:hZPb6cYomHqLPXr9EcDcGumvHZtM1HROZJlPvHEPXCA= +github.com/libgox/spring-cloud-go v0.1.1 h1:p1VYXln1OjfwEJAiO2LRZX/jFC3Ld/qjV0SvUTyGoOw= +github.com/libgox/spring-cloud-go v0.1.1/go.mod h1:w4kEWwD/0xJu6JY5L+/wnPe+Bb8QM5cQSzHhP3aJPVA= github.com/libgox/unicodex v0.0.1 h1:yUuZWMVXC5N9dcYgIc3aO7+2M5jN+XVatrU08Y5fC4k= github.com/libgox/unicodex v0.0.1/go.mod h1:RaB9wNp/oOS0Ew5+Wml7WePjztZ3njXiNid08KOmgjs= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= @@ -54,8 +56,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/protocol-laboratory/opcua-go v0.0.0-20241022080800-2ff8b0ffb7c8 h1:G6dNiZGs7jmjiL3nRcAaoWsrkteeLnBDqPwkOgUVC2g= github.com/protocol-laboratory/opcua-go v0.0.0-20241022080800-2ff8b0ffb7c8/go.mod h1:pK+CGt9aKG68k0c4MWCvwF9dpyObrcxK9J8PIUwn2h0= -github.com/protocol-laboratory/zookeeper-client-go v0.0.4-0.20241026020853-9929d040af36 h1:O9iIJjCwLXOAK4lSHghHcfH3HKc+RuzNTUP1+xdfR2w= -github.com/protocol-laboratory/zookeeper-client-go v0.0.4-0.20241026020853-9929d040af36/go.mod h1:UKYaKMjuO6NNZXHEn5wH+OyKm5LVH28rjs4Zx/htNc8= +github.com/protocol-laboratory/zookeeper-client-go v0.1.1 h1:Bbor3IL6B7uFk2+pcKKmS0GJvSaUsM9+joFXK+QMyDU= +github.com/protocol-laboratory/zookeeper-client-go v0.1.1/go.mod h1:xFuvgUWIcZtATIPd//XjcND0nIqPmUpyrTE15LPw8ZE= github.com/shirou/gopsutil/v3 v3.23.12 h1:z90NtUkp3bMtmICZKpC4+WaknU1eXtp5vtbQ11DgpE4= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= diff --git a/main.go b/main.go index 925876c..b2d863d 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( _ "github.com/libgox/flyway" _ "github.com/libgox/gocollections/listx" _ "github.com/libgox/retry" + _ "github.com/libgox/slogsimple" _ "github.com/libgox/spring-cloud-go" _ "github.com/libgox/unicodex/letter" _ "github.com/protocol-laboratory/opcua-go/opcua" diff --git a/pkg/boot/boot.go b/pkg/boot/boot.go index 29d1901..b7fde63 100644 --- a/pkg/boot/boot.go +++ b/pkg/boot/boot.go @@ -2,15 +2,25 @@ package boot import ( "github.com/libgox/envx" + "github.com/libgox/slogsimple" "golang.org/x/exp/slog" + "os" ) -type ClientApplication struct { +type Application struct { + logger *slog.Logger } -func NewClientApplication() *ClientApplication { +func NewTestClientApplication() *Application { logger := slog.Default() envx.GetStrOr("POD_NAME", "defaultName") logger.Info("Starting client application") - return &ClientApplication{} + return &Application{} +} + +func (a *Application) Boot() { + a.logger = slog.New(slogsimple.NewHandler(&slogsimple.Config{ + Output: os.Stdout, + MinLevel: slog.LevelInfo, + })) }