-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ftr: 3.0 lumberjack log sample #179
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="logger-client" type="GoApplicationRunConfiguration" factoryName="Go Application" singleton="false"> | ||
<module name="dubbo-go-samples" /> | ||
<working_directory value="$PROJECT_DIR$" /> | ||
<envs> | ||
<env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/logger/go-client/conf/log.yml" /> | ||
<env name="CONF_CONSUMER_FILE_PATH" value="$PROJECT_DIR$/logger/go-client/conf/client.yml" /> | ||
</envs> | ||
<kind value="PACKAGE" /> | ||
<filePath value="$PROJECT_DIR$/logger/go-client/cmd/client.go" /> | ||
<package value="github.com/apache/dubbo-go-samples/logger/go-client/cmd" /> | ||
<directory value="$PROJECT_DIR$" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,15 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="logger-server" type="GoApplicationRunConfiguration" factoryName="Go Application" singleton="false"> | ||
<module name="dubbo-go-samples" /> | ||
<working_directory value="$PROJECT_DIR$" /> | ||
<envs> | ||
<env name="APP_LOG_CONF_FILE" value="$PROJECT_DIR$/logger/go-server/conf/log.yml" /> | ||
<env name="CONF_PROVIDER_FILE_PATH" value="$PROJECT_DIR$/logger/go-server/conf/server.yml" /> | ||
</envs> | ||
<kind value="PACKAGE" /> | ||
<filePath value="$PROJECT_DIR$/logger/go-server/cmd/server.go" /> | ||
<package value="github.com/apache/dubbo-go-samples/logger/go-server/cmd" /> | ||
<directory value="$PROJECT_DIR$" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,116 @@ | ||
## Log usage | ||
|
||
The samples demonstrate how to configure dubbo-go logger using lumberjack | ||
|
||
### Configuration | ||
|
||
Output file settings | ||
|
||
```yaml | ||
lumberjackConfig: | ||
# The name of the log file | ||
filename: "logs.log" | ||
# The maximum size of each log file length, the default is 100M | ||
maxSize: 1 | ||
# Maximum number of days to keep logs (only keep the logs of the most recent days) | ||
maxAge: 3 | ||
# Only keep the most recent log files, used to control the size of the total log of the program | ||
maxBackups: 5 | ||
# Whether to use local time, UTC time is used by default | ||
localTime: true | ||
# Whether to compress the log file, the compression method is gzip | ||
compress: false | ||
``` | ||
|
||
Log format and level settings | ||
|
||
```yaml | ||
zapConfig: | ||
level: "debug" | ||
development: false | ||
disableCaller: false | ||
disableStacktrace: false | ||
sampling: | ||
encoding: "console" | ||
|
||
# encoder | ||
encoderConfig: | ||
messageKey: "message" | ||
levelKey: "level" | ||
timeKey: "time" | ||
nameKey: "logger" | ||
callerKey: "caller" | ||
stacktraceKey: "stacktrace" | ||
lineEnding: "" | ||
levelEncoder: "capitalColor" | ||
timeEncoder: "iso8601" | ||
durationEncoder: "seconds" | ||
callerEncoder: "short" | ||
nameEncoder: "" | ||
|
||
outputPaths: | ||
- "stderr" | ||
errorOutputPaths: | ||
- "stderr" | ||
initialFields: | ||
``` | ||
|
||
If you do not want to output to a file, you can follow the rules below to set only zap | ||
|
||
```yaml | ||
level: "debug" | ||
development: false | ||
disableCaller: false | ||
disableStacktrace: false | ||
sampling: | ||
encoding: "console" | ||
|
||
# encoder | ||
encoderConfig: | ||
messageKey: "message" | ||
levelKey: "level" | ||
timeKey: "time" | ||
nameKey: "logger" | ||
callerKey: "caller" | ||
stacktraceKey: "stacktrace" | ||
lineEnding: "" | ||
levelEncoder: "capitalColor" | ||
timeEncoder: "iso8601" | ||
durationEncoder: "seconds" | ||
callerEncoder: "short" | ||
nameEncoder: "" | ||
|
||
outputPaths: | ||
- "stderr" | ||
errorOutputPaths: | ||
- "stderr" | ||
initialFields: | ||
``` | ||
|
||
### Run | ||
|
||
A cycle of 1000000 times is set on the go-client side, and the server will be called all the time to facilitate the viewing of the log output | ||
|
||
```go | ||
func main() { | ||
config.Load() | ||
time.Sleep(3 * time.Second) | ||
|
||
for i := 0;i < 1000000; i ++ { | ||
test() | ||
} | ||
|
||
} | ||
|
||
func test() { | ||
logger.Info("\n\n\nstart to test dubbo") | ||
user := &pkg.User{} | ||
err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user) | ||
if err != nil { | ||
logger.Infof("error: %v\n", err) | ||
os.Exit(1) | ||
return | ||
} | ||
logger.Infof("response result: %v\n", user) | ||
} | ||
``` |
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,116 @@ | ||
## 日志使用 | ||
|
||
该 samples 演示了如何使用 lumberjack 配置 dubbo-go logger | ||
|
||
### 配置 | ||
|
||
输出文件设置 | ||
|
||
```yaml | ||
lumberjackConfig: | ||
# 写日志的文件名称 | ||
filename: "logs.log" | ||
# 每个日志文件长度的最大大小,默认100M | ||
maxSize: 1 | ||
# 日志保留的最大天数(只保留最近多少天的日志) | ||
maxAge: 3 | ||
# 只保留最近多少个日志文件,用于控制程序总日志的大小 | ||
maxBackups: 5 | ||
# 是否使用本地时间,默认使用UTC时间 | ||
localTime: true | ||
# 是否压缩日志文件,压缩方法gzip | ||
compress: false | ||
``` | ||
|
||
zap 日志格式和级别设置 | ||
|
||
```yaml | ||
zapConfig: | ||
level: "debug" | ||
development: false | ||
disableCaller: false | ||
disableStacktrace: false | ||
sampling: | ||
encoding: "console" | ||
|
||
# encoder | ||
encoderConfig: | ||
messageKey: "message" | ||
levelKey: "level" | ||
timeKey: "time" | ||
nameKey: "logger" | ||
callerKey: "caller" | ||
stacktraceKey: "stacktrace" | ||
lineEnding: "" | ||
levelEncoder: "capitalColor" | ||
timeEncoder: "iso8601" | ||
durationEncoder: "seconds" | ||
callerEncoder: "short" | ||
nameEncoder: "" | ||
|
||
outputPaths: | ||
- "stderr" | ||
errorOutputPaths: | ||
- "stderr" | ||
initialFields: | ||
``` | ||
|
||
如果不希望输出到文件中,可以按照如下规则,仅设置 zap | ||
|
||
```yaml | ||
level: "debug" | ||
development: false | ||
disableCaller: false | ||
disableStacktrace: false | ||
sampling: | ||
encoding: "console" | ||
|
||
# encoder | ||
encoderConfig: | ||
messageKey: "message" | ||
levelKey: "level" | ||
timeKey: "time" | ||
nameKey: "logger" | ||
callerKey: "caller" | ||
stacktraceKey: "stacktrace" | ||
lineEnding: "" | ||
levelEncoder: "capitalColor" | ||
timeEncoder: "iso8601" | ||
durationEncoder: "seconds" | ||
callerEncoder: "short" | ||
nameEncoder: "" | ||
|
||
outputPaths: | ||
- "stderr" | ||
errorOutputPaths: | ||
- "stderr" | ||
initialFields: | ||
``` | ||
|
||
### 运行 | ||
|
||
在 go-client 端设置了一个 1000000 次的循环,会一直调用 server 来方便查看日志的输出情况 | ||
|
||
```go | ||
func main() { | ||
config.Load() | ||
time.Sleep(3 * time.Second) | ||
|
||
for i := 0;i < 1000000; i ++ { | ||
test() | ||
} | ||
|
||
} | ||
|
||
func test() { | ||
logger.Info("\n\n\nstart to test dubbo") | ||
user := &pkg.User{} | ||
err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user) | ||
if err != nil { | ||
logger.Infof("error: %v\n", err) | ||
os.Exit(1) | ||
return | ||
} | ||
logger.Infof("response result: %v\n", user) | ||
} | ||
``` |
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,72 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"time" | ||
) | ||
|
||
import ( | ||
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl" | ||
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance" | ||
_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory" | ||
"dubbo.apache.org/dubbo-go/v3/config" | ||
"dubbo.apache.org/dubbo-go/v3/common/logger" | ||
_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl" | ||
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" | ||
_ "dubbo.apache.org/dubbo-go/v3/registry/protocol" | ||
_ "dubbo.apache.org/dubbo-go/v3/registry/zookeeper" | ||
|
||
hessian "github.com/apache/dubbo-go-hessian2" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go-samples/helloworld/go-client/pkg" | ||
) | ||
|
||
var userProvider = new(pkg.UserProvider) | ||
|
||
func init() { | ||
config.SetConsumerService(userProvider) | ||
hessian.RegisterPOJO(&pkg.User{}) | ||
} | ||
|
||
// need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run | ||
func main() { | ||
config.Load() | ||
time.Sleep(3 * time.Second) | ||
|
||
for i := 0;i < 1000000; i ++ { | ||
test() | ||
} | ||
|
||
} | ||
|
||
func test() { | ||
logger.Info("\n\n\nstart to test dubbo") | ||
user := &pkg.User{} | ||
err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user) | ||
if err != nil { | ||
logger.Infof("error: %v\n", err) | ||
os.Exit(1) | ||
return | ||
} | ||
logger.Infof("response result: %v\n", user) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The maximum size of each log file length, its unit is MiB. The default value is 100MiB.