summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2013-12-26 00:11:37 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2013-12-26 00:22:32 +0100
commit1e97c1c6537724fc3f4866da06b1e380471c1c06 (patch)
treeb161f348c4b8c380e1d0fcc2320c5fc2d889871e
parent8655f934aabe1ba64668cb9dfff6e3e65e79083a (diff)
downloadlogactio-1e97c1c6537724fc3f4866da06b1e380471c1c06.tar.gz
logactio-1e97c1c6537724fc3f4866da06b1e380471c1c06.tar.xz
logactio-1e97c1c6537724fc3f4866da06b1e380471c1c06.zip
Added logging to stdout
Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
-rw-r--r--LogActio/Logger.py17
-rw-r--r--docs/source/starting.rst3
-rwxr-xr-xlogactio4
3 files changed, 22 insertions, 2 deletions
diff --git a/LogActio/Logger.py b/LogActio/Logger.py
index 692f36f..a160f12 100644
--- a/LogActio/Logger.py
+++ b/LogActio/Logger.py
@@ -28,6 +28,7 @@ import syslog
LOGTYPE_FILE = 0
LOGTYPE_SYSLOG = 1
+LOGTYPE_STDOUT = 2
class FileLogger(object):
def __init__(self, logfile):
@@ -57,6 +58,20 @@ class SysLogger(object):
syslog.closelog()
+class StdoutLogger(object):
+ def __init__(self):
+ import sys
+ self.__logf = sys.stdout
+
+
+ def _log(self, lvl, msg):
+ self.__logf.write("[%i] %s\n" % (lvl, msg))
+ self.__logf.flush()
+
+
+ def _close(self):
+ pass
+
class Logger(object):
def __init__(self, logtype, logdest, verblvl):
@@ -65,6 +80,8 @@ class Logger(object):
self.__logger = FileLogger(logdest)
elif logtype == LOGTYPE_SYSLOG:
self.__logger = SysLogger(logdest)
+ elif logtype == LOGTYPE_STDOUT:
+ self.__logger = StdoutLogger()
def Log(self, lvl, msg):
if lvl <= self.__verblevel:
diff --git a/docs/source/starting.rst b/docs/source/starting.rst
index 59ff815..76f680a 100644
--- a/docs/source/starting.rst
+++ b/docs/source/starting.rst
@@ -68,7 +68,8 @@ for the pid file.
By default logactio will do all logging via syslog. If you want to log to a
separate file, add the *--log-type=file* and *--log-file=/path/to/my/log.file*.
When logactio writes to syslog, they are tagged with *logactio*. This may be
-modified with the *--syslog-id* argument.
+modified with the *--syslog-id* argument. To log to stdout, use
+*--log-type=stdout*
If you want to run logactio as a daemon, add the *--daemon* argument as well.
diff --git a/logactio b/logactio
index d56bf70..58c1e7e 100755
--- a/logactio
+++ b/logactio
@@ -47,7 +47,7 @@ if __name__ == '__main__':
parser.add_option("-v", "--verbose", action="count", default=0,
dest="verb",
help="Increase the log verbosity")
- parser.add_option("-L", "--log-type", type="choice", choices=["syslog","file"],
+ parser.add_option("-L", "--log-type", type="choice", choices=["syslog","file", "stdout"],
dest="logtype", default="syslog",
help="Should logging go to file or syslog? (default: %default)")
parser.add_option("-l", "--log-file",
@@ -66,6 +66,8 @@ if __name__ == '__main__':
logger = Logger.Logger(Logger.LOGTYPE_SYSLOG, opts.syslogid, opts.verb)
elif opts.logtype == "file":
logger = Logger.Logger(Logger.LOGTYPE_FILE, opts.logfile, opts.verb)
+ elif opts.logtype == "stdout":
+ logger = Logger.Logger(Logger.LOGTYPE_STDOUT, opts.logfile, opts.verb)
else:
raise Exception("Unknown log type '%s'" % opts.logtype)