diff options
author | Jan Fabry <jan.fabry@mobilevikings.com> | 2013-01-31 14:22:34 +0100 |
---|---|---|
committer | CityLive <info@citylive.be> | 2013-01-31 14:22:34 +0100 |
commit | 1ff0fa104f32e55886d437ae90d402b9a7585c55 (patch) | |
tree | cad7ac652ae1af314d60df99865884f1895c5f8a | |
parent | 8403d9dad1e88968898b8ecf2e9412018da3a7cd (diff) | |
download | logster-1ff0fa104f32e55886d437ae90d402b9a7585c55.zip logster-1ff0fa104f32e55886d437ae90d402b9a7585c55.tar.gz logster-1ff0fa104f32e55886d437ae90d402b9a7585c55.tar.bz2 |
Allow parser from any reachable module
-rw-r--r-- | README.md | 8 | ||||
-rwxr-xr-x | bin/logster | 10 |
2 files changed, 15 insertions, 3 deletions
@@ -63,6 +63,14 @@ to either Ganglia or Graphite. $ sudo /usr/sbin/logster --dry-run --output=graphite --graphite-host=graphite.example.com:2003 SampleLogster /var/log/httpd/access_log +You can use the provided parsers, or you can use your own parsers by passing +the complete module and parser name. In this case, the name of the parser does +not have to match the name of the module (you can have a logster.py file with a +MyCustomParser parser). Just make sure the module is in your Python path - via +a virtualenv, for example. + + $ /env/my_org/bin/logster --dry-run --output=stdout my_org_package.logster.MyCustomParser /var/log/my_custom_log + Additional usage details can be found with the -h option: $ ./logster -h diff --git a/bin/logster b/bin/logster index bd77b43..12edb38 100755 --- a/bin/logster +++ b/bin/logster @@ -112,6 +112,9 @@ if 'graphite' in options.output and not options.graphite_host: cmdline.error("You must supply --graphite-host when using 'graphite' as an output type.") class_name = arguments[0] +if class_name.find('.') == -1: + # If it's a single name, find it in the base logster package + class_name = 'logster.parsers.%s.%s' % (class_name, class_name) log_file = arguments[1] state_dir = options.state_dir logtail = options.logtail @@ -251,9 +254,10 @@ def main(): logger.info("Executing parser %s on logfile %s" % (class_name, log_file)) logger.debug("Using state file %s" % logtail_state_file) - # Import and instantiate the class from the module passed in. Files and Class names must be the same. - module = __import__('logster.parsers.' + class_name, globals(), locals(), [class_name]) - parser = getattr(module, class_name)(option_string=options.parser_options) + # Import and instantiate the class from the module passed in. + module_name, parser_name = class_name.rsplit('.', 1) + module = __import__(module_name, globals(), locals(), [parser_name]) + parser = getattr(module, parser_name)(option_string=options.parser_options) # Check for lock file so we don't run multiple copies of the same parser # simultaneuosly. This will happen if the log parsing takes more time than |