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

Initial logger support #2230

Merged
merged 3 commits into from Jan 31, 2024
Merged

Initial logger support #2230

merged 3 commits into from Jan 31, 2024

Conversation

mths1
Copy link
Contributor

@mths1 mths1 commented Dec 10, 2023

Proposed Changes

Work in Progress, but works. Currently only console and error log are supported. Investigating syslog and crash. Help is welcome...

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes issue #XXXX)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (correction or otherwise)
  • Cosmetics (whitespace, styles...)
  • DevOps (Build scripts, pipelines...)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CODE_OF_CONDUCT.md document
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if needed)
  • Any dependent changes have been merged and published in related repositories
  • I have updated changelog (At the bottom of the release version)
  • I have squashed all my commits into one before merging

Further Comments

If this is a relatively large or complex change, kick off the discussion by
explaining why you chose the solution you did and what alternatives you
considered, etc.

@mths1
Copy link
Contributor Author

mths1 commented Dec 10, 2023

Some decisions to make (among others I guess):

What about SASL? Currently it works with logger_sasl_compatible, but it would be possible to work without, either by let SASL write to the std-log (it writes as INFO, maybe we should move to NOTICE instead of info?), by keeping logger_sasl_compatible or having a seperate logger to a to-be-defined SASL file.

How should the output format look like? The default is:

2023-12-10T19:48:46.972961+01:00 info: Try to start vmq_swc: ok
2023-12-10T19:48:47.059590+01:00 info: Opening LevelDB database at "./data/msgstore/1"
2023-12-10T19:48:47.105198+01:00 info: Opening LevelDB database at "./data/msgstore/2"
2023-12-10T19:48:47.147255+01:00 info: Opening LevelDB database at "./data/msgstore/3"
2023-12-10T19:48:47.186576+01:00 info: Opening LevelDB database at "./data/msgstore/4"
2023-12-10T19:48:47.273619+01:00 info: Opening LevelDB database at "./data/msgstore/5"
2023-12-10T19:48:47.329384+01:00 info: Opening LevelDB database at "./data/msgstore/6"
2023-12-10T19:48:47.422189+01:00 info: Opening LevelDB database at "./data/msgstore/7"
2023-12-10T19:48:47.447329+01:00 info: Opening LevelDB database at "./data/msgstore/8"
2023-12-10T19:48:47.511926+01:00 info: Opening LevelDB database at "./data/msgstore/9"
2023-12-10T19:48:47.536903+01:00 info: Opening LevelDB database at "./data/msgstore/10"
2023-12-10T19:48:47.568671+01:00 info: Opening LevelDB database at "./data/msgstore/11"
2023-12-10T19:48:47.620563+01:00 info: Opening LevelDB database at "./data/msgstore/12"
2023-12-10T19:48:47.705046+01:00 info: Try to start vmq_generic_msg_store: ok
2023-12-10T19:48:48.028764+01:00 info: loaded 0 subscriptions into vmq_reg_trie
2023-12-10T19:48:48.042195+01:00 info: cluster event handler 'vmq_cluster' registered

What changes should the CLI support?

...

@mths1
Copy link
Contributor Author

mths1 commented Dec 10, 2023

(the failing tests are currently kind of expected. Didn't work yet on get them running

@mths1
Copy link
Contributor Author

mths1 commented Dec 10, 2023

Structured Logs Yes/No (would mean more refactoring)
SysLog (Seems not to be possible out-of-the-box)

@mths1 mths1 force-pushed the feature/logger branch 2 times, most recently from f130386 to ed5c6be Compare December 10, 2023 19:57
@ioolkos
Copy link
Contributor

ioolkos commented Dec 10, 2023

@mths1
Copy link
Contributor Author

mths1 commented Dec 10, 2023

Latest version does not need advanced_config anymore. Works now for console (file and real console) and error logging. Still investigating crash log and syslog...

@mths1
Copy link
Contributor Author

mths1 commented Dec 11, 2023

My latest idea:
console => filters SASL progress, now supports rotation
error => includes now SASL crashes, no need for crash log anymore
crash => for backwards compatibility, maybe disabled by default?
sasl => for backwards compatibility, contains supervisor progress (and crash), maybe disabled by default?

We could also include sasl progress reports into console, but it might then be better to upgrade our log_info to log_notice, so that we could filter them away with log_level notice.

Regressions:

  • Different settings for log rotation
  • Deprecation of SASL
  • Deprecation of crash
  • error_logger always forwarded to logger
  • different logging format string
  • Custom plugins would need to upgrade as well

@ioolkos
Copy link
Contributor

ioolkos commented Dec 11, 2023

@mths1
+1 for disabling crash log and SASL, as a default. I'd keep progress reports out of the console which allows us to keep "info" level.

@codeadict do you think structured logging should be part of the deal right from the beginning here? or got at it incrementally?

@mths1 mths1 force-pushed the feature/logger branch 6 times, most recently from 97f8c76 to 70fd0c0 Compare December 16, 2023 14:17
@mths1
Copy link
Contributor Author

mths1 commented Dec 16, 2023

Latest version to test:

  • Supports console log (enabled), error log (enabled), sasl log(disable), crash log(disabled), syslog (disabled)
  • Supports log rotation for all loggers (different feature set than lager though. Regression)
  • Syslog is supported via https://github.com/garazdawi/syslogger which rabbid uses as well
  • CLI support (vmq-admin log)

Next step would be to decide on the formatting. I added some config for keeping the default or switch to something similar to the previous format.

@mths1 mths1 force-pushed the feature/logger branch 2 times, most recently from 5554958 to db07c50 Compare December 16, 2023 14:53
@ioolkos
Copy link
Contributor

ioolkos commented Dec 16, 2023

Awesome!
One question I have: Doesn't Rabbit use https://github.com/schlagert/syslog, though? (looking at the Makefile). Would have the benefit of no additional Nifs (C sources). But I currently haven't looked into comparing both libraries (syslogger or syslog) in detail.

@mths1 mths1 force-pushed the feature/logger branch 8 times, most recently from 341cd06 to c34c7aa Compare December 17, 2023 20:11
@mths1 mths1 force-pushed the feature/logger branch 3 times, most recently from b95bc89 to da5f6b5 Compare December 18, 2023 08:12
@mths1
Copy link
Contributor Author

mths1 commented Dec 18, 2023

@ioolkos : Yes, you are right. Seems i copied the wrong link from somewhere. Good news, also works with the other library.

I added a json formatter (which is based on the one from rabbitmq). I won't work much on this anymore for now. It is ready for testing. Unless, we want to move to structured logging I assume there shouldn't be too many open points left.

@codeadict
Copy link
Contributor

https://github.com/schlagert/syslog is definitely better and well maintained and tested, structured logs could be a different PR, not necessary for V1

apps/vmq_bridge/rebar.config Outdated Show resolved Hide resolved
apps/vmq_commons/src/vmq_log.erl Outdated Show resolved Hide resolved
apps/vmq_commons/src/vmq_log_json_format.erl Outdated Show resolved Hide resolved
apps/vmq_diversity/rebar.config Outdated Show resolved Hide resolved
@@ -17,5 +17,5 @@
%%Eonblast hasn't merged the Erlang 18 related PR from djustinek
%%{emysql, {git, "git://github.com/Eonblast/Emysql.git", {tag, "v0.4.1"}}},
{mongodb, {git, "https://github.com/comtihon/mongodb-erlang.git", {ref, "713e8bd"}}},
{mcd, {git, "https://github.com/EchoTeam/mcd.git", {ref, "b5b4a32"}}}
{mcd, {git, "https://github.com/mths1/mcd.git", {branch, "master"}}}
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be in this branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to move mcd to vernemq repro (this is a mcd version without lager dependency)

apps/vmq_server/src/vmq_metadata.erl Outdated Show resolved Hide resolved
@@ -42,7 +43,7 @@ stop() ->
Impl = application:get_env(vmq_server, metadata_impl, vmq_plumtree),
_ = spawn(fun() ->
Ret = vmq_plugin_mgr:disable_plugin(Impl),
lager:info("Try to stop ~p: ~p", [Impl, Ret])
?LOG_INFO("Try to stop ~p: ~p", [Impl, Ret])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
?LOG_INFO("Try to stop ~p: ~p", [Impl, Ret])
?LOG_INFO("Trying to stop ~p: ~p", [Impl, Ret])

apps/vmq_swc/rebar.config Outdated Show resolved Hide resolved
apps/vmq_swc/test/vmq_swc_test_utils.erl Outdated Show resolved Hide resolved
apps/vmq_webhooks/rebar.config Outdated Show resolved Hide resolved
@ioolkos
Copy link
Contributor

ioolkos commented Jan 29, 2024

currently testing & reviewing. plan to merge this for the upcoming release.

mths1 and others added 3 commits January 31, 2024 12:13
@ioolkos ioolkos merged commit 6182880 into vernemq:main Jan 31, 2024
9 of 10 checks passed
mths1 added a commit to mths1/vernemq that referenced this pull request Feb 10, 2024
* Initial logger support

* Apply suggestions from code review

Address code review

Co-authored-by: Dairon M. <dairon.medina@gmail.com>

* Address review comments (log show -> log show config)

---------

Co-authored-by: mths1 <mths1>
Co-authored-by: Dairon M. <dairon.medina@gmail.com>
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