Description
The following remsh session shows that at first, both config log level and lager_file_backend levels are the same (info), but after we use config to change the level to notice, the lager level remains at info:
(cloudant@db1.v)26> config:get("log","level"). "info" (cloudant@db1.v)27> gen_event:which_handlers(lager_event). [{lager_file_backend,"/var/log/cloudant/cloudant.log"}, lager_backend_throttle] (cloudant@db1.v)28> lager:get_loglevel({lager_file_backend,"/var/log/cloudant/cloudant.log"}). info (cloudant@db1.v)29> config:set("log","level","notice",false). ok (cloudant@db1.v)30> lager:get_loglevel({lager_file_backend,"/var/log/cloudant/cloudant.log"}). info
The problem occurs because https://github.com/apache/couchdb-couch-log-lager/blob/master/src/couch_log_lager.erl#L67 obtains the handlers from application:get_env(lager, handlers), which returns the a structure defined in sys.config, but it should use gen_event:which_handlers(lager_event), which returns the actual list of handlers:
(cloudant@db1.v)31> application:get_env(lager, handlers). {ok,[{lager_file_backend, [{file,"/var/log/cloudant/cloudant.log"}, {formatter,lager_default_formatter}, {formatter_config, [date," ",time," [",severity,"] ",node," ",pid," ",message, "\n"]}]}]} (cloudant@db1.v)32> gen_event:which_handlers(lager_event). [{lager_file_backend,"/var/log/cloudant/cloudant.log"}, lager_backend_throttle]