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 feature for enabling json logging #3462

Merged
merged 1 commit into from Jul 4, 2023

Conversation

lemmus-org
Copy link
Contributor

Allows configuring log output to be json formatted when built using the json-log feature.

For example:

  • cargo run
2023-07-03T03:52:43.045692Z  INFO lemmy_db_schema::utils: Running Database migrations (This may take a long time)...
2023-07-03T03:52:43.047078Z  INFO lemmy_db_schema::utils: Database migrations complete.
2023-07-03T03:52:43.083464Z  INFO lemmy_server::code_migrations: Running user_updates_2020_04_02
2023-07-03T03:52:43.084804Z  INFO lemmy_server::code_migrations: 0 person rows updated.
2023-07-03T03:52:43.085039Z  INFO lemmy_server::code_migrations: Running community_updates_2020_04_02
2023-07-03T03:52:43.085850Z  INFO lemmy_server::code_migrations: 0 community rows updated.
2023-07-03T03:52:43.085964Z  INFO lemmy_server::code_migrations: Running post_updates_2020_04_03
2023-07-03T03:52:43.086656Z  INFO lemmy_server::code_migrations: 0 post rows updated.
2023-07-03T03:52:43.086765Z  INFO lemmy_server::code_migrations: Running comment_updates_2020_04_03
2023-07-03T03:52:43.088325Z  INFO lemmy_server::code_migrations: 0 comment rows updated.
2023-07-03T03:52:43.088440Z  INFO lemmy_server::code_migrations: Running private_message_updates_2020_05_05
2023-07-03T03:52:43.088873Z  INFO lemmy_server::code_migrations: 0 private message rows updated.
2023-07-03T03:52:43.088975Z  INFO lemmy_server::code_migrations: Running post_thumbnail_url_updates_2020_07_27
2023-07-03T03:52:43.089405Z  INFO lemmy_server::code_migrations: 0 Post thumbnail_url rows updated.
2023-07-03T03:52:43.089514Z  INFO lemmy_server::code_migrations: Running apub_columns_2021_02_02
2023-07-03T03:52:43.090065Z  INFO lemmy_server::code_migrations: Running instance_actor_2021_09_29
2023-07-03T03:52:43.093276Z  INFO lemmy_server::code_migrations: Running regenerate_public_keys_2022_07_05
2023-07-03T03:52:43.093989Z  INFO lemmy_server::code_migrations: Running initialize_local_site_2022_10_10
  • cargo run --feature json-log
{"timestamp":"2023-07-03T03:48:47.630411Z","level":"INFO","fields":{"message":"Running Database migrations (This may take a long time)..."},"target":"lemmy_db_schema::utils"}
{"timestamp":"2023-07-03T03:48:48.433914Z","level":"INFO","fields":{"message":"Database migrations complete."},"target":"lemmy_db_schema::utils"}
{"timestamp":"2023-07-03T03:48:48.471113Z","level":"INFO","fields":{"message":"Running user_updates_2020_04_02"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.472628Z","level":"INFO","fields":{"message":"0 person rows updated."},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.472864Z","level":"INFO","fields":{"message":"Running community_updates_2020_04_02"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.473765Z","level":"INFO","fields":{"message":"0 community rows updated."},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.473887Z","level":"INFO","fields":{"message":"Running post_updates_2020_04_03"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.474783Z","level":"INFO","fields":{"message":"0 post rows updated."},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.474913Z","level":"INFO","fields":{"message":"Running comment_updates_2020_04_03"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.476622Z","level":"INFO","fields":{"message":"0 comment rows updated."},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.476728Z","level":"INFO","fields":{"message":"Running private_message_updates_2020_05_05"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.477190Z","level":"INFO","fields":{"message":"0 private message rows updated."},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.477305Z","level":"INFO","fields":{"message":"Running post_thumbnail_url_updates_2020_07_27"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.477748Z","level":"INFO","fields":{"message":"0 Post thumbnail_url rows updated."},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.477855Z","level":"INFO","fields":{"message":"Running apub_columns_2021_02_02"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.478434Z","level":"INFO","fields":{"message":"Running instance_actor_2021_09_29"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.482569Z","level":"INFO","fields":{"message":"Running regenerate_public_keys_2022_07_05"},"target":"lemmy_server::code_migrations"}
{"timestamp":"2023-07-03T03:48:48.483338Z","level":"INFO","fields":{"message":"Running initialize_local_site_2022_10_10"},"target":"lemmy_server::code_migrations"}

Using structured logging can be really helpful for analysis, especially when ingested by 3rd-party tools. They can auto-detect the fields allowing you to easily search or generate metrics/alerts based on values.

@Nutomic Nutomic enabled auto-merge (squash) July 3, 2023 14:38
@Nutomic Nutomic merged commit ff47d97 into LemmyNet:main Jul 4, 2023
1 check passed
@lemmus-org lemmus-org deleted the structured-logging branch July 4, 2023 19:41
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.

None yet

3 participants