Skip to content

Commit

Permalink
implemented --logLevel flag
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangda committed May 13, 2021
1 parent d032580 commit edf726f
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Releases

## Release v0.0.9

* Implemented new config parameter --logLevel
* Dependencies updated

## Release v0.0.8

* Fixed golang version in github actions pipeline
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ go tool pprof http:https://127.0.0.1:8080/debug/pprof/goroutine
# terminal 2, for mq-to-db-02 inside the docker-compose-file
go tool pprof http:https://127.0.0.1:8081/debug/pprof/goroutine


# once you are into tool pprof, execute the command web
(pprof) web
```
Expand Down
25 changes: 21 additions & 4 deletions cmd/mq-to-db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ func init() { // package initializer
flag.BoolVar(&conf.Server.KeepAlivesEnabled, "server.keepAlivesEnabled", true, "Server KeepAlivesEnabled")
flag.BoolVar(&conf.Server.Debug, "debug", false, "debug")
flag.BoolVar(&conf.Server.Profile, "profile", false, "Enable program profile")
flag.StringVar(&conf.Server.LogFormat, "logFormat", "text", "Log Format [text|json] ")
flag.StringVar(&conf.Server.LogFormat, "logFormat", "text", "Log Format [text|json]")
flag.StringVar(&conf.Server.LogLevel, "logLevel", "info", "Log Level [debug|info|warning|panic|fatal]")

// Application conf flags
flag.StringVar(&conf.Application.ConfigFile, "configFile", "config", "Configuration file")

// Application version flags
showVersion := flag.Bool("version", false, "Show application version")
showVersionInfo := flag.Bool("versionInfo", false, "Show application version information")
Expand Down Expand Up @@ -118,12 +121,26 @@ func init() { // package initializer
log.SetFormatter(&logrus.TextFormatter{DisableColors: false, DisableTimestamp: false, FullTimestamp: true})
}

if conf.Server.Debug {
switch conf.Server.LogLevel {
case "debug":
log.SetLevel(logrus.DebugLevel)
} else {
case "info":
log.SetLevel(logrus.InfoLevel)
case "warning":
log.SetLevel(logrus.WarnLevel)
case "panic":
log.SetLevel(logrus.PanicLevel)
case "fatal":
log.SetLevel(logrus.FatalLevel)
default:
log.SetLevel(logrus.InfoLevel)
}

// if --debug, force debug log level no matter what value is in logLevel
if conf.Server.Debug {
log.SetLevel(logrus.DebugLevel)
}

log.Info("Application initialized")
}

Expand Down Expand Up @@ -652,7 +669,7 @@ func HomePage(w http.ResponseWriter, r *http.Request) {
<ul>
<li><a href="{{.ProfileLink}}">{{.ProfileLink}}</a></li>
</ul>
<h3><a href="https://prometheus.io/">If you want to know more about Metrics and Exporters go to https://prometheus.io</a></h3>
</body>
Expand Down
2 changes: 1 addition & 1 deletion config-sample.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
dispatcher:
consumerConcurrency: 4 # Number of go routines consuming messages from Queue
storageWorkers: 40 # Number of go routines sending messages to storage
storageWorkers: 40 # Number of go routines sending messages to storage

consumer:
kind: rabbitmq
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ services:
environment:
SERVER_ADDRESS: 0.0.0.0 # means all the ips into the container
SERVER_PORT: 8080
#LOGLEVEL: fatal # as a env var
command:
- --profile
- --logLevel=info # as a container arg
#- --debug
ports:
- 8080:8080
Expand Down Expand Up @@ -130,8 +132,10 @@ services:
environment:
SERVER_ADDRESS: 0.0.0.0 # means all the ips into the container
SERVER_PORT: 8081
#LOGLEVEL: fatal # as a env var
command:
- --profile
- --logLevel=info # as a container arg
#- --debug
ports:
- 8081:8081
Expand Down
2 changes: 1 addition & 1 deletion docker-compose/mq-to-db/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ consumer:
exclusive: false
autoACK: false
PrefetchCount: 500
PrefetchSize: 0
PrefetchSize: 0
args:
x-message-ttl: 180000
x-dead-letter-exchange: retry.exchange
Expand Down
4 changes: 2 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The configuration file could be `named as you want`, by default if you don't spe
This could be located in any place, but by default when service start this find the configuration file in the following location:

1. `./config.yaml` Next to the service binary `mq-to-db`
2. `/etc/mq-to-db/config.yaml` Into the standard `Linux` configuration filesystem
2. `/etc/mq-to-db/config.yaml` Into the standard `Linux` configuration File System
3. `$HOME/config.yaml` Into the `user home` which is executing the service binary `mq-to-db`

__NOTE:__ Remember that thanks to the parameter `--configFile` you can tell to the service which configuration file you want to use, for example:
Expand Down Expand Up @@ -44,7 +44,7 @@ consumer:
exclusive: false
autoACK: false
PrefetchCount: 1500
PrefetchSize: 0
PrefetchSize: 0
args: # Optional
x-message-ttl: 180000
x-dead-letter-exchange: retry.exchange
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/christiangda/mq-to-db
go 1.16

require (
github.com/lib/pq v1.10.0
github.com/lib/pq v1.10.1
github.com/prometheus/client_golang v1.10.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/streadway/amqp v1.0.0
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c // indirect
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.1 h1:6VXZrLU0jHBYyAqrSPa+MgPfnSvTPuMgK+k0o5kVFWo=
github.com/lib/pq v1.10.1/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
Expand Down Expand Up @@ -439,6 +441,8 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mUOKexJBNsLf4Z+6En1Q=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Config struct {
ShutdownTimeout time.Duration `json:"shutdownTimeout" yaml:"shutdownTimeout"`
KeepAlivesEnabled bool `json:"keepAlivesEnabled" yaml:"keepAlivesEnabled"`
LogFormat string `json:"logFormat" yaml:"logFormat"`
LogLevel string `json:"logLevel" yaml:"logLevel"`
Debug bool `json:"debug" yaml:"debug"`
Profile bool `json:"profile" yaml:"profile"`
}
Expand Down

0 comments on commit edf726f

Please sign in to comment.