-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
Conversation
logger_test.go
Outdated
} | ||
} | ||
|
||
func TestLogger_PrintWithTextWriter(t *testing.T) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
postgres_logger.go
Outdated
"time" | ||
) | ||
|
||
type PostgresLogger struct { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
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 { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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()?
Issue