0

I am trying to implement logging on connected users in my vernemq client using erlang. From documentation, I found that this could be bad, due to the scalability of the client and the assumption that there might be a lot of clients connecting and disconnecting. This is not my case, I will just have a bunch of clients but a lot of messages. Anyway, to my question. Is it possible to change the log file when using error_logger? Or should I use a different module for logging? Log file can be in any location if it had to, but I need it separated from vernemqs console.log. A followup question would be, can I somehow get a floating window on logs? I don't need to keep logs from previous year and I don't want to manually clean them every day or week or something like that

Thanks for any responses

1 Answers1

0

From OTP21 on, you should use logger instead of error_logger, although the error_logger API is kept for compatibility (it justs uses logger under the hood).

With logger, which you can configure with the system configuration, you can use file backends such as logger_std_h (check the example configurations).

In logger_std_h you can set file rotation.

José M
  • 3,294
  • 1
  • 14
  • 16
  • May I ask you where exactly to put it? I am very new to erlang, as you can probably see. I tried putting what is in documentation as an example into my rebar.config file (I use rebar3 for that plugin), but I see no file with the log entry (I tried searching with grep -r on the entire system). – Ondřej Chládek Mar 18 '21 at 13:15
  • @OndřejChládek This is application configuration, so it should be placed in the sys.config files. You have [documentation and examples for rebar3](https://rebar3.org/docs/deployment/releases/#application-configuration) – José M Mar 19 '21 at 02:29
  • I tried to insert example configurations into `config/sys.config` and run `rebar3 compile` but it did not pass any config to the compiled version. At the documentation, they seem to use `rebar release` but if I use the release files, verne cannot find the plugin. Putting sys.config into compiled plugin also did not resolve the issue. I am just trying to write simple plugin but I cannot figure this out. Thanks – Ondřej Chládek Mar 19 '21 at 10:36
  • @OndřejChládek I misunderstood the nature of the plugin, in that case you can use [application:set_env/*](http://erlang.org/doc/apps/kernel/application.html#set_env-4) from your code (although I don't recommend it) or search and edit vernemq's sys.config file – José M Mar 19 '21 at 12:34
  • After thinking twice about it, you may want to use [logger's configuration API](http://erlang.org/doc/man/logger.html#configuration_API) instead to set up your plugin logs separately from the rest of the system's (but modifying the system's log config is better done through sys.config) – José M Mar 19 '21 at 13:23
  • Thanks! will take a look on it and hopefully resolve the issue – Ondřej Chládek Mar 19 '21 at 13:32