summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Fabry <jan.fabry@mobilevikings.com>2013-01-31 14:22:34 +0100
committerCityLive <info@citylive.be>2013-01-31 14:22:34 +0100
commit1ff0fa104f32e55886d437ae90d402b9a7585c55 (patch)
treecad7ac652ae1af314d60df99865884f1895c5f8a
parent8403d9dad1e88968898b8ecf2e9412018da3a7cd (diff)
downloadlogster-1ff0fa104f32e55886d437ae90d402b9a7585c55.zip
logster-1ff0fa104f32e55886d437ae90d402b9a7585c55.tar.gz
logster-1ff0fa104f32e55886d437ae90d402b9a7585c55.tar.bz2
Allow parser from any reachable module
-rw-r--r--README.md8
-rwxr-xr-xbin/logster10
2 files changed, 15 insertions, 3 deletions
diff --git a/README.md b/README.md
index af1f8ea..572e169 100644
--- a/README.md
+++ b/README.md
@@ -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