Log4r: logger inheritance, yaml configuration, alternatives?

I'm new to ruby ​​environments, and I was looking for a good logging framework to use in my ruby ​​and rails applications.

In my previous experiences, I successfully used log4j and log4p (perl port) and expected the same level of usability (and maturity) with log4r.

However, I must say that there are a number of things that are not entirely clear within log4r.

1 Registrar Inheritance

Logger inheritance is not managed at all!

If I declare a logger with the name "myapp" and then try to get the log name "myapp :: engine", the search will end using NameError.

I would expect the framework to return the root log according to the naming scheme and use the "myapp" logger.

Q1 . Of course, I can get around this and manage the names myself using the search method, but is there a cleaner way to do this without any extra coding?

2 YAML configuration

The second thing that bothers me is the configuration of the barley. There is literally no information on this system on the log4r website, the doc is linked forward to the missing pages, so all the information I can find is contained in the catalog of gem examples.

I was rather confused by the fact that the yaml configuration should contain a pre_config section and that I need to define my own levels.

If I delete pre_config secion or replace all "user" levels with standard ones (debug, info, warn, fatal), the following error will appear in the example:

log4r/yamlconfigurator.rb:68:in `decode_yaml': Log level must be in 0..7 (ArgumentError) 

So it seems that there is no easy way to use a simple file in which we only declare registrars and applications for the framework.

Q2 : I really think that I missed something, and this should be a way to provide a simple file, a javelin file. Do you have any examples of this use?

3 Rearrange variables in an XML file

Q3 . Yaml's customization system seems to provide such a function, but I could not find a similar function with XML files. Any ideas?

4 alternatives?

I have to say that I am very disappointed with the level of function and maturity of log4r compared to log4j and other log4j ports.

I am in this framework with a solid background of registering APIs in other languages ​​and find that I turn around in all kinds to make the “main things” run in the “real application”.

By this I mean a complex application consisting of several gems, console / script applications and the rails web web interface, where configuration is necessary and where we intensively use namespaces and inheritance.

I did a few searches to find something more suitable or mature, but did not find anything like it.

Q4 : Do you guys know any (serious) alternatives to the log4r structure that you can use in an enterprise-class application?

Thanks for reading all this!

I would really appreciate any pointers,

Respectfully,

+4
source share
2 answers

I agree that the log4r documentation is pretty poor. We use it, although it helps us very well, say, the enterpriseisey application.

We do not use logger inheritance, so I can’t help you with this, and I also don’t know about any alternative software, but:

Here is the code that we use to read the YAML configuration (in fact, I think we pass it as already loaded in Hash), it also supports variable substitution:

 require 'log4r' require 'log4r/yamlconfigurator' y = "log4r_config: # define all loggers ... loggers: - name : production level : INFO trace : 'false' outputters: - stdout # define all outputters (incl. formatters) outputters: - type : StdoutOutputter name : stdout formatter: date_pattern: '%Y-%m-%d %H:%M:%S' pattern : '%d %l: #\{TEST\} %m ' type : PatternFormatter" h = YAML.load y log_cfg = YamlConfigurator log_cfg['TEST'] = 'foobar' log_cfg.decode_yaml h['log4r_config'] @log = Logger['production'] @log.info 'test' #=>2010-05-20 14:36:32 INFO: foobar test 
+2
source

Since I am still “fighting” the barley configuration, I figured out the XML configuration code a bit and found an answer for Q3 that specifies parameter substitution.

Actually this works very similar to yaml stuff, all you need is to reference the C # {VARNAME} parameters in the XML file:

 <filename>#{logdir}/processing.log</filename> 

and install them in the configurator before reading the XML file:

 Log4r::Configurator['logdir']=log_dir_param ... Log4r::Configurator.load_xml_file(conf_file_xml) 

Also, when I mentioned that the log4r documentation is really in bad shape (many 404 errors), I was talking about a document available on rubyforge ...

I ended up looking at the sourceforge project and found a “good” (in ruby) doc at http://log4r.sourceforge.net/rdoc .

0
source

Source: https://habr.com/ru/post/1310100/


All Articles