Move logging helpers and configuration to dedicated package

parent a84a4f8a
......@@ -8,7 +8,7 @@ import (
"github.com/urfave/cli"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers/cli"
"gitlab.com/gitlab-org/gitlab-runner/log"
_ "gitlab.com/gitlab-org/gitlab-runner/commands/helpers"
)
......@@ -40,8 +40,8 @@ func main() {
logrus.Fatalln("Command", command, "not found")
}
cli_helpers.ConfigureLogging(app)
cli_helpers.AddSecretsCleanupLogHook()
log.AddSecretsCleanupLogHook()
log.ConfigureLogging(app)
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
......
......@@ -21,10 +21,10 @@ import (
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers"
"gitlab.com/gitlab-org/gitlab-runner/helpers/certificate"
"gitlab.com/gitlab-org/gitlab-runner/helpers/cli"
prometheus_helper "gitlab.com/gitlab-org/gitlab-runner/helpers/prometheus"
"gitlab.com/gitlab-org/gitlab-runner/helpers/sentry"
"gitlab.com/gitlab-org/gitlab-runner/helpers/service"
"gitlab.com/gitlab-org/gitlab-runner/log"
"gitlab.com/gitlab-org/gitlab-runner/network"
"gitlab.com/gitlab-org/gitlab-runner/session"
)
......@@ -259,7 +259,7 @@ func (mr *RunCommand) loadConfig() error {
}
// Set log level
if !cli_helpers.IsCustomLevelUsed() && mr.config.LogLevel != nil {
if !log.IsCustomLevelUsed() && mr.config.LogLevel != nil {
level, err := logrus.ParseLevel(*mr.config.LogLevel)
if err != nil {
logrus.WithError(err).Fatal("Failed to parse error level from configuration file")
......@@ -644,7 +644,7 @@ func (mr *RunCommand) Execute(context *cli.Context) {
}
if mr.Syslog {
cli_helpers.SetSystemLogger(svc)
log.SetSystemLogger(svc)
}
logrus.AddHook(&mr.sentryLogHook)
......
package cli_helpers
package log
import (
"os"
......@@ -10,8 +10,8 @@ import (
)
const (
LogFormatText = "text"
LogFormatJSON = "json"
FormatText = "text"
FormatJSON = "json"
)
var (
......@@ -19,17 +19,17 @@ var (
customLevelUsed = false
logFlags = []cli.Flag{
cli.StringFlag{
Name: "log-format",
Usage: "Chose log format (options: text, json)",
EnvVar: "LOG_FORMAT",
Value: LogFormatText,
},
cli.BoolFlag{
Name: "debug",
Usage: "debug mode",
EnvVar: "DEBUG",
},
cli.StringFlag{
Name: "log-format",
Usage: "Chose log format (options: text, json)",
EnvVar: "LOG_FORMAT",
Value: FormatText,
},
cli.StringFlag{
Name: "log-level, l",
Usage: "Log level (options: debug, info, warn, error, fatal, panic)",
......@@ -38,8 +38,8 @@ var (
}
formats = map[string]logrus.Formatter{
LogFormatText: new(logrus.TextFormatter),
LogFormatJSON: new(logrus.JSONFormatter),
FormatText: new(logrus.TextFormatter),
FormatJSON: new(logrus.JSONFormatter),
}
)
......
// +build darwin dragonfly freebsd linux netbsd openbsd
package cli_helpers
package log
import (
"os"
......
package cli_helpers
package log
func watchForGoroutinesDump() {
}
package cli_helpers
package log
import (
"github.com/sirupsen/logrus"
......@@ -18,5 +18,5 @@ func (s *SecretsCleanupHook) Fire(entry *logrus.Entry) error {
}
func AddSecretsCleanupLogHook() {
logrus.AddHook(&SecretsCleanupHook{})
logrus.AddHook(new(SecretsCleanupHook))
}
package cli_helpers_test
package log
import (
"bytes"
......@@ -6,8 +6,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"gitlab.com/gitlab-org/gitlab-runner/helpers/cli"
)
func TestSecretsCleanupHook(t *testing.T) {
......@@ -34,7 +32,7 @@ func TestSecretsCleanupHook(t *testing.T) {
logger := logrus.New()
logger.Out = buffer
logger.AddHook(&cli_helpers.SecretsCleanupHook{})
logger.AddHook(new(SecretsCleanupHook))
logger.Errorln(test.message)
......
package cli_helpers
package log
import (
"github.com/ayufan/golang-kardianos-service"
......
......@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers/cli"
"gitlab.com/gitlab-org/gitlab-runner/log"
_ "gitlab.com/gitlab-org/gitlab-runner/cache/gcs"
_ "gitlab.com/gitlab-org/gitlab-runner/cache/s3"
......@@ -52,11 +53,12 @@ func main() {
}
cli_helpers.LogRuntimePlatform(app)
cli_helpers.ConfigureLogging(app)
cli_helpers.SetupCPUProfile(app)
cli_helpers.FixHOME(app)
cli_helpers.WarnOnBool(os.Args)
log.ConfigureLogging(app)
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment