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

Implement the feature to log to file, with support for JSON. #234

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

dimitri
Copy link
Owner

@dimitri dimitri commented Apr 5, 2023

This allows pgcopydb to log both to the terminal and also to a file, where the format is not adjusted for terminal width (long time format, source file and line always included).

Also implements logging in JSON, using a JSON object per line with a static set of attributes that includes all the metadata we have about the log message.

The control of this feature set is entirely based on using environment variables, no new command line switch has been introduced. It is possible to log both in plain text with colors on the terminal and to a JSON file at the same time.

This allows pgcopydb to log both to the terminal and also to a file, where
the format is not adjusted for terminal width (long time format, source file
and line always included).

Also implements logging in JSON, using a JSON object per line with a static
set of attributes that includes all the metadata we have about the log
message.

The control of this feature set is entirely based on using environment
variables, no new command line switch has been introduced. It is possible to
log both in plain text with colors on the terminal and to a JSON file at the
same time.
@dimitri dimitri merged commit 0ab7a11 into main Apr 5, 2023
@dimitri dimitri deleted the feature/log-to-file branch April 5, 2023 10:10
Copy link

@devinshteyn2 devinshteyn2 left a comment

Choose a reason for hiding this comment

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

Couple of ideas:
In case pgcopydb is used in some sort of automation pipeline handled by a group of machines or kind of serverless, and logs are monitored and aggregated, it would be nice to know machine name. Maybe give users an option to add machine name?

Aligning log tag names with PG tag log names? ts -> timestamp, log -> message, level -> severity?
https://www.postgresql.org/docs/current/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-JSONLOG

@dimitri
Copy link
Owner Author

dimitri commented Apr 6, 2023

Thanks for review and input, and your patience for the review of your PR. Using same JSON keys as Postgres is an excellent feedback, do you want to implement it? (ts -> timestamp, log -> message, level -> error_severity, file -> file_name, line -> file_line_num).

There is no provision in Postgres JSON log format for a machine name, so I would rather pass on that part.

Do you want to open a new PR fixing the JSON log key names?

@devinshteyn2
Copy link

If you would like me to make these changes, I'd be happy to do it if you can wait for a couple of weeks, I'm literally going on vacation tomorrow, and got my plate full for today :-) Yet, they are fairly small, probably makes more sense if somebody else adds them.

@dimitri
Copy link
Owner Author

dimitri commented Apr 7, 2023

Done. Have a good vacation time ;-)

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