Skip to content

Add postgres format logs#5

Open
deffer1337 wants to merge 6 commits intowal-g:masterfrom
deffer1337:master
Open

Add postgres format logs#5
deffer1337 wants to merge 6 commits intowal-g:masterfrom
deffer1337:master

Conversation

@deffer1337
Copy link
Copy Markdown

Comment thread logger_test.go Outdated
}
}

func TestLogger_PrintWithTextWriter(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many tests with only little details different, extract the separate function with common code and provide the input / expected output.

Comment thread logger.go Outdated
fieldValues FieldValues
}

func NewLogger(fieldValues FieldValues, loggerWriters ...LoggerWriter) *Logger {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need many writers at the same time, so I suggest to change it to a single writer for simplicity.

Comment thread postgres_logger.go Outdated
"time"
)

type PostgresLogger struct {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need separate struct for pg logger? Can we just provide the correct writer to the constructor of the main one?

Comment thread walg_logger.go Outdated
}

func setupWalgLoggers() {
if logLevel == NormalLogLevel {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only difference is the destinations for debug/info/error loggers, other code must not be duplicated.

Comment thread postgres_logger.go Outdated
var ErrorPostgresLogger = NewLogger(GetFieldValues(ErrorLoggerType), NewTextWriter(os.Stderr, BasicFormat, BasicFields))
var DebugPostgresLogger = NewLogger(GetFieldValues(DebugLoggerType), NewTextWriter(ioutil.Discard, BasicFormat, BasicFields))
func setupJsonPgLoggers() {
if logLevel == NormalLogLevel {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment thread logging.go Outdated
if logWriter == TextWalg {
setupWalgLoggers()
} else if logWriter == JsonPg {
setupJsonPgLoggers()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need to use separate functions? Can we just setup the writer and field values and then send it to setupLoggers()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants