# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
+import sys
import syslog
import os
global the_root_prefix
the_root_prefix = prefix
+log_destination = "syslog"
+def get_log_destination():
+ """Returns the current log destination.
+ 'syslog' means "log to syslog".
+ 'stderr' means "log to stderr"."""
+ return log_destination
+def set_log_destination(dest):
+ global log_destination
+ log_destination = dest
+
#
# Logging.
#
def log(s):
- syslog.syslog(s)
+ if get_log_destination() == 'syslog':
+ syslog.syslog(s)
+ else:
+ print >>sys.stderr, s
#
# Exceptions.
--pif-uuid The UUID of a PIF.
--force An interface name.
--root-prefix=DIR Use DIR as alternate root directory (for testing).
+ --no-syslog Write log messages to stderr instead of system log.
"""
# Notes:
"management",
"mac=", "device=", "mode=", "ip=", "netmask=", "gateway=",
"root-prefix=",
+ "no-syslog",
"help" ]
arglist, args = getopt.gnu_getopt(argv[1:], shortops, longops)
except getopt.GetoptError, msg:
force_rewrite_config[o[2:]] = a
elif o == "--root-prefix":
set_root_prefix(a)
+ elif o == "--no-syslog":
+ set_log_destination("stderr")
elif o == "-h" or o == "--help":
print __doc__ % {'command-name': os.path.basename(argv[0])}
return 0
- syslog.openlog(os.path.basename(argv[0]))
- log("Called as " + str.join(" ", argv))
+ if get_log_destination() == "syslog":
+ syslog.openlog(os.path.basename(argv[0]))
+ log("Called as " + str.join(" ", argv))
if len(args) < 1:
raise Usage("Required option <action> not present")