Skip to content

Commit

Permalink
PMM-12338 Remove forced colors in logger with global utils folder. (#…
Browse files Browse the repository at this point in the history
…2399)

* PMM-12338 Remove forced colors in logger.

* PMM-12338 Move logger into global utils folder.

* PMM-12338 Format.

* PMM-12338 Lint.

* PMM-12338 Refactor.
  • Loading branch information
JiriCtvrtka authored Aug 9, 2023
1 parent ac9bb81 commit fa6b693
Show file tree
Hide file tree
Showing 38 changed files with 40 additions and 86 deletions.
8 changes: 3 additions & 5 deletions agent/cmd/pmm-agent-entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/percona/pmm/utils/logger"
)

var helpText = `
Expand Down Expand Up @@ -131,11 +133,7 @@ func main() {

var status int

logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: "2006-01-02T15:04:05.000-07:00",
})
logger.SetupGlobalLogger()

l := logrus.WithField("component", "entrypoint")

Expand Down
26 changes: 2 additions & 24 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
package main

import (
"fmt"
"path/filepath"
"runtime"

"github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/percona/pmm/agent/commands"
"github.com/percona/pmm/agent/config"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/version"
)

Expand All @@ -33,25 +29,7 @@ func main() {
panic("pmm-agent version is not set during build.")
}

// we don't have configuration options for formatter, so set it once there
logrus.SetFormatter(&logrus.TextFormatter{
// Enable multiline-friendly formatter in both development (with terminal) and production (without terminal):
// https://github.com/sirupsen/logrus/blob/839c75faf7f98a33d445d181f3018b5c3409a45e/text_formatter.go#L176-L178
ForceColors: true,
FullTimestamp: true,
TimestampFormat: "2006-01-02T15:04:05.000-07:00",

CallerPrettyfier: func(f *runtime.Frame) (string, string) {
_, function := filepath.Split(f.Function)

// keep a single directory name as a compromise between brevity and unambiguity
dir, file := filepath.Split(f.File)
dir = filepath.Base(dir)
file = fmt.Sprintf("%s/%s:%d", dir, file, f.Line)

return function, file
},
})
logger.SetupGlobalLogger()

// check that command-line flags and environment variables are correct,
// parse command, but do try not load config file
Expand Down
2 changes: 1 addition & 1 deletion managed/cmd/pmm-managed-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services/supervisord"
"github.com/percona/pmm/managed/utils/envvars"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion managed/cmd/pmm-managed-starlark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/managed/services/checks"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/version"
)

Expand Down
2 changes: 1 addition & 1 deletion managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ import (
"github.com/percona/pmm/managed/utils/clean"
"github.com/percona/pmm/managed/utils/envvars"
"github.com/percona/pmm/managed/utils/interceptors"
"github.com/percona/pmm/managed/utils/logger"
platformClient "github.com/percona/pmm/managed/utils/platform"
pmmerrors "github.com/percona/pmm/utils/errors"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/utils/sqlmetrics"
"github.com/percona/pmm/version"
)
Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
grpcstatus "google.golang.org/grpc/status"

"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/connection_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/version"
)

Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services/agents/channel"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

// Handler handles agent requests.
Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services/agents/channel"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/version"
)

Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/version"
)

Expand Down
2 changes: 1 addition & 1 deletion managed/services/grafana/auth_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
"gopkg.in/reform.v1/dialects/postgresql"

"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func TestNextPrefix(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/inventory/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

// AgentsService works with inventory API Agents.
Expand Down
2 changes: 1 addition & 1 deletion managed/services/inventory/inventory_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion managed/services/inventory/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (

"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func setup(t *testing.T) (*ServicesService, *AgentsService, *NodesService, func(t *testing.T), context.Context, *mockPrometheusService) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (

agentv1beta1 "github.com/percona/pmm/api/managementpb/agent"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

var now time.Time
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

"github.com/percona/pmm/api/managementpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func TestAnnotations(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/azure_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

azurev1beta1 "github.com/percona/pmm/api/managementpb/azure"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (

dbaasv1beta1 "github.com/percona/pmm/api/managementpb/dbaas"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
pmmversion "github.com/percona/pmm/version"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (

dbaasv1beta1 "github.com/percona/pmm/api/managementpb/dbaas"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

const dbKubeconfigTest = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import (
dbaasv1beta1 "github.com/percona/pmm/api/managementpb/dbaas"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services/dbaas/kubernetes"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
pmmversion "github.com/percona/pmm/version"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
dbaasv1beta1 "github.com/percona/pmm/api/managementpb/dbaas"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services/dbaas/kubernetes"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
pmmversion "github.com/percona/pmm/version"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import (
dbaasv1beta1 "github.com/percona/pmm/api/managementpb/dbaas"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services/dbaas/kubernetes"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
pmmversion "github.com/percona/pmm/version"
)

Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/node_mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import (
"github.com/percona/pmm/api/inventorypb"
nodev1beta1 "github.com/percona/pmm/api/managementpb/node"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func TestMgmtNodeService(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/api/managementpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func TestNodeService(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"github.com/percona/pmm/api/managementpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/services"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import (
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/api/managementpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func TestRDSService(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (

rolev1beta1 "github.com/percona/pmm/api/managementpb/role"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

//nolint:paralleltest
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/service_mgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

servicev1beta1 "github.com/percona/pmm/api/managementpb/service"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func TestMgmtServiceService(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/management/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/api/managementpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/managed/utils/tests"
"github.com/percona/pmm/utils/logger"
)

func TestServiceService(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion managed/services/qan/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/percona/pmm/api/inventorypb"
qanpb "github.com/percona/pmm/api/qanpb"
"github.com/percona/pmm/managed/models"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/managed/utils/testdb"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/utils/sqlmetrics"
)

Expand Down
2 changes: 1 addition & 1 deletion managed/services/supervisord/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
"golang.org/x/sys/unix"
"gopkg.in/yaml.v3"

"github.com/percona/pmm/managed/utils/logger"
pprofUtils "github.com/percona/pmm/managed/utils/pprof"
"github.com/percona/pmm/utils/logger"
"github.com/percona/pmm/utils/pdeathsig"
)

Expand Down
2 changes: 1 addition & 1 deletion managed/services/supervisord/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

var commonExpectedFiles = []string{
Expand Down
2 changes: 1 addition & 1 deletion managed/services/vmalert/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package vmalert

import "github.com/percona/pmm/managed/utils/logger"
import "github.com/percona/pmm/utils/logger"

//nolint:gochecknoinits
func init() {
Expand Down
2 changes: 1 addition & 1 deletion managed/utils/interceptors/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"google.golang.org/grpc/status"

"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/managed/utils/logger"
"github.com/percona/pmm/utils/logger"
)

func logRequest(l *logrus.Entry, prefix string, f func() error) (err error) {
Expand Down
Loading

0 comments on commit fa6b693

Please sign in to comment.