Skip to content

Commit

Permalink
detect docker containers status && json formatter logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Zztrans committed Aug 6, 2024
1 parent cf57c5f commit d685cd7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ unset-data: build

.PHONY: setup-dependencies
setup-dependencies: build get-front get-problem-packages
docker compose up -d postgres redis minio clickhouse
@echo "Wait 2 seconds for db setup"
sleep 2s
@if [ "$(shell docker ps -f status=running | grep -E "postgres|redis|minio|clickhouse" | wc -l)" -eq 4 ]; then \
echo "Containers already up"; \
./bin/clean; \
else \
docker compose up -d postgres redis minio clickhouse; \
@echo "Wait 10 seconds for db setup"; \
sleep 10s; \
fi
./bin/init;

.PHONY: setup-data
setup-data:setup-dependencies unset-data
./bin/init

.PHONY: get-front
get-front:
Expand All @@ -98,7 +101,7 @@ check: gen-proto install-cilint
golangci-lint run

.PHONY: test
test: build gen-swagger setup-data
test: build gen-swagger setup-dependencies
go test -race -covermode=atomic -coverprofile=coverage.out -cover -v -count=1 \
./models/... ./modules/... ./services/...

Expand Down
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[log]
level = "debug"
force_quote = true
pretty_json = true
time_on = true
time_format = "2006-01-02 15:04:05"

Expand Down
15 changes: 7 additions & 8 deletions modules/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const logLevelProp = "log.level"
const logForceQuote = "log.force_quote"
const logPrettyJson = "log.pretty_json"
const logTimeOn = "log.time_on"
const logTimeFormat = "log.time_format"

Expand All @@ -31,8 +31,8 @@ func setupLog() {

logrus.SetLevel(logrus.DebugLevel)
lvl := config_module.AppConfig().GetString(logLevelProp)
forceQuote := config_module.AppConfig().GetBool(logForceQuote)
fullTimeOn := config_module.AppConfig().GetBool(logTimeOn)
prettyJson := config_module.AppConfig().GetBool(logPrettyJson)
timeOn := config_module.AppConfig().GetBool(logTimeOn)
timestampFormat := config_module.AppConfig().GetString(logTimeFormat)

logLevel, err := logrus.ParseLevel(lvl)
Expand All @@ -41,11 +41,10 @@ func setupLog() {
logrus.SetLevel(logLevel)
}
// TODO: control log format in config
// logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.SetFormatter(&logrus.TextFormatter{
ForceQuote: forceQuote, // value Quote
FullTimestamp: fullTimeOn,
TimestampFormat: timestampFormat,
logrus.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: timestampFormat,
DisableTimestamp: !timeOn,
PrettyPrint: prettyJson,
})
}

Expand Down

0 comments on commit d685cd7

Please sign in to comment.