diff options
author | Daniel Schauenberg <d@unwiredcouch.com> | 2013-03-23 14:41:36 -0700 |
---|---|---|
committer | Daniel Schauenberg <d@unwiredcouch.com> | 2013-03-23 14:41:36 -0700 |
commit | ea194fcf6a9f108ada557519f8ed50f9ea047da0 (patch) | |
tree | d5e9e9f40821fbd00a41c3a75a020aa4cf0d6f2c | |
parent | 2520e4261be709b330c80c0074c270e3d0f3b51f (diff) | |
parent | 1ff0fa104f32e55886d437ae90d402b9a7585c55 (diff) | |
download | logster-ea194fcf6a9f108ada557519f8ed50f9ea047da0.zip logster-ea194fcf6a9f108ada557519f8ed50f9ea047da0.tar.gz logster-ea194fcf6a9f108ada557519f8ed50f9ea047da0.tar.bz2 |
Merge pull request #43 from citylive/module_anywhere
Allow full module name to specify the parser
-rw-r--r-- | README.md | 8 | ||||
-rwxr-xr-x | bin/logster | 10 |
2 files changed, 15 insertions, 3 deletions
@@ -63,6 +63,14 @@ to Ganglia or Graphite or Amazon CloudWatch. $ 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 d0f0952..29901cf 100755 --- a/bin/logster +++ b/bin/logster @@ -119,6 +119,9 @@ if 'cloudwatch' in options.output and not options.aws_key and not options.aws_se cmdline.error("You must supply --aws-key and --aws-secret-key or Set environment variables. AWS_ACCESS_KEY_ID for --aws-key, AWS_SECRET_ACCESS_KEY_ID for --aws-secret-key") 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 @@ -288,9 +291,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 |