Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postgres format logs #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

deffer1337
Copy link

logger_test.go Outdated
}
}

func TestLogger_PrintWithTextWriter(t *testing.T) {
Copy link
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.

logger.go Outdated
fieldValues FieldValues
}

func NewLogger(fieldValues FieldValues, loggerWriters ...LoggerWriter) *Logger {
Copy link
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.

"time"
)

type PostgresLogger struct {
Copy link
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?

walg_logger.go Outdated
}

func setupWalgLoggers() {
if logLevel == NormalLogLevel {
Copy link
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.

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
Member

Choose a reason for hiding this comment

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

same here

logging.go Outdated
if logWriter == TextWalg {
setupWalgLoggers()
} else if logWriter == JsonPg {
setupJsonPgLoggers()
Copy link
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