-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
- Loading branch information
Showing
18 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package distribution // import "github.com/kubecub/log/distribution" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package main //github.com/kubecub/log/example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
|
||
"github.com/kubecub/log" | ||
) | ||
|
||
var ( | ||
h bool | ||
|
||
level int | ||
format string | ||
) | ||
|
||
func main() { | ||
flag.BoolVar(&h, "h", false, "Print this help.") | ||
flag.IntVar(&level, "l", 0, "Log level.") | ||
flag.StringVar(&format, "f", "console", "log output format.") | ||
|
||
flag.Parse() | ||
|
||
if h { | ||
flag.Usage() | ||
|
||
return | ||
} | ||
|
||
// logger配置 | ||
opts := &log.Options{ | ||
Level: "debug", | ||
Format: "console", | ||
EnableColor: true, | ||
DisableCaller: true, | ||
OutputPaths: []string{"test.log", "stdout"}, | ||
ErrorOutputPaths: []string{"error.log"}, | ||
} | ||
// 初始化全局logger | ||
log.Init(opts) | ||
defer log.Flush() | ||
|
||
// WithValues使用 | ||
lv := log.WithValues("X-Request-ID", "7a7b9f24-4cae-4b2a-9464-69088b45b904") | ||
|
||
// Context使用 | ||
lv.Infof("Start to call pirntString function") | ||
ctx := lv.WithContext(context.Background()) | ||
pirntString(ctx, "World") | ||
} | ||
|
||
func pirntString(ctx context.Context, str string) { | ||
lc := log.FromContext(ctx) | ||
lc.Infof("Hello %s", str) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
|
||
"github.com/kubecub/log" | ||
) | ||
|
||
var ( | ||
h bool | ||
|
||
level int | ||
format string | ||
) | ||
|
||
func main() { | ||
flag.BoolVar(&h, "h", false, "Print this help.") | ||
flag.IntVar(&level, "l", 0, "Log level.") | ||
flag.StringVar(&format, "f", "console", "log output format.") | ||
|
||
flag.Parse() | ||
|
||
if h { | ||
flag.Usage() | ||
|
||
return | ||
} | ||
|
||
// logger配置 | ||
opts := &log.Options{ | ||
Level: "debug", | ||
Format: "console", | ||
EnableColor: true, // if you need output to local path, with EnableColor must be false. | ||
DisableCaller: true, | ||
OutputPaths: []string{"test.log", "stdout"}, | ||
ErrorOutputPaths: []string{"error.log"}, | ||
} | ||
// 初始化全局logger | ||
log.Init(opts) | ||
defer log.Flush() | ||
|
||
// Debug、Info(with field)、Warnf、Errorw使用 | ||
log.Debug("This is a debug message") | ||
log.Info("This is a info message", log.Int32("int_key", 10)) | ||
log.Warnf("This is a formatted %s message", "warn") | ||
log.Errorw("Message printed with Errorw", "X-Request-ID", "fbf54504-64da-4088-9b86-67824a7fb508") | ||
|
||
// WithValues使用 | ||
lv := log.WithValues("X-Request-ID", "7a7b9f24-4cae-4b2a-9464-69088b45b904") | ||
lv.Infow("Info message printed with [WithValues] logger") | ||
lv.Infow("Debug message printed with [WithValues] logger") | ||
|
||
// Context使用 | ||
ctx := lv.WithContext(context.Background()) | ||
lc := log.FromContext(ctx) | ||
lc.Info("Message printed with [WithContext] logger") | ||
|
||
ln := lv.WithName("test") | ||
ln.Info("Message printed with [WithName] logger") | ||
|
||
// V level使用 | ||
log.V(log.InfoLevel).Info("This is a V level message") | ||
log.V(log.ErrorLevel). | ||
Infow("This is a V level message with fields", "X-Request-ID", "7a7b9f24-4cae-4b2a-9464-69088b45b904") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package main //github.com/kubecub/log/simple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package main | ||
|
||
import "github.com/kubecub/log" | ||
|
||
func main() { | ||
log.Infof("this is a test log, message: %s", "good") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package main //github.com/kubecub/log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright © 2023 KubeCub & Xinwei Xiong(cubxxw). All rights reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/kubecub/log" | ||
) | ||
|
||
func main() { | ||
defer log.Flush() | ||
|
||
log.V(0).Info("This is a V level message") | ||
log.V(0).Infow("This is a V level message with fields", "X-Request-ID", "7a7b9f24-4cae-4b2a-9464-69088b45b904") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters