def __init__(self, program_name, facility=None):
# Default values always get evaluated, for which reason we avoid
# using 'syslog' directly, which may not be available.
facility = facility if facility is not None else syslog.LOG_USER
if not syslog:
raise RuntimeError("Syslog not available on this platform")
super(SyslogHandler, self).__init__()
syslog.openlog(program_name, 0, facility)
python类openlog()的实例源码
def __init__(self):
syslog.openlog(facility=syslog.LOG_DAEMON)
def __init__(self, name, facility=syslog.LOG_DAEMON):
logging.Handler.__init__(self)
syslog.openlog(name, syslog.LOG_PID, facility)
def __init__(self):
syslog.openlog(ident="BroadView")
def __init__(self):
syslog.openlog(facility=syslog.LOG_DAEMON)
def __init__(self, root, title, text, func, *args, **kw):
Trace.__init__(self, trace = 0)
self.root = root
self.title = title
self.text = text
self.func = func
self.args = args
self.kw = kw
self.trace_1("OK Cancel dialog created\n")
syslog.openlog("tkController", syslog.LOG_LOCAL0)
def main():
args = docopt(__doc__,
version="sdic {}".format(VERSION))
# Check that the given directory exists
if not isdir(args['<directory>']):
error("The folder {} does not exist".format(args['<directory>']))
# Try to get the config of the servers we are gonna use
servers = get_servers_from_config(args['<directory>'])
# Check that we are not already running
program_name = os.path.basename(sys.argv[0])
lock = FileLock("/tmp/{}.lock".format(program_name))
if lock.is_locked():
error("{} is already running. Delete {} if it's a mistake.".format(
program_name, lock.path))
# Everything's ok, run the main program
with lock:
syslog.openlog('sdic')
has_output = False
if not args['<server>']:
for server in servers:
if launch_queries(args['<directory>'], server):
has_output = True
else:
for server in servers:
if server['name'] == args['<server>']:
if launch_queries(args['<directory>'], server):
has_output = True
if has_output:
return 1
syslog.closelog()
def log(self, entry):
""" This method will log information to the local syslog facility """
if self.logging:
syslog.openlog('ansible-%s' % self.module._name)
syslog.syslog(syslog.LOG_NOTICE, entry)
def _log_to_syslog(self, msg):
if HAS_SYSLOG:
module = 'ansible-%s' % self._name
facility = getattr(syslog, self._syslog_facility, syslog.LOG_USER)
syslog.openlog(str(module), 0, facility)
syslog.syslog(syslog.LOG_INFO, msg)
def error(message):
"""Error handling for logs"""
errormsg = u"ERROR: %s" % message
debug(errormsg)
syslog.openlog("StallNoMan")
syslog.syslog(syslog.LOG_ERR, errormsg)
def log(message):
"""Syslog handling for logs"""
infomsg = u"%s" % message
debug(infomsg)
syslog.openlog("StallNoMan")
syslog.syslog(syslog.LOG_INFO, infomsg)
def __init__(self, facility, process_name):
super(SysLogHandler, self).__init__()
if facility not in SysLogHandler._FACILITIES:
raise ValueError("invalid syslog facility: %s" % (facility,))
syslog.openlog(process_name, syslog.LOG_PID,
SysLogHandler._FACILITIES[facility])
def _log_to_syslog(self, msg):
if HAS_SYSLOG:
module = 'ansible-%s' % self._name
facility = getattr(syslog, self._syslog_facility, syslog.LOG_USER)
syslog.openlog(str(module), 0, facility)
syslog.syslog(syslog.LOG_INFO, msg)
def push_log_to_server(self):
"""????"""
try:
# ???????? 128 * 1024 ???????????????????
step = 127 * 1024
for i in xrange(0, len(self.message), step):
syslog.openlog("", 0, self.facility)
syslog.syslog(self.severity, self.message[i:i + step])
except BaseException:
traceback.print_exc()
def send_message(self, message="", **kwargs):
"""Send a message to a user."""
import syslog
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
syslog.openlog(title, self._option, self._facility)
syslog.syslog(self._priority, message)
syslog.closelog()
def main():
try:
syslog_flags = syslog.LOG_PID
if os.isatty(sys.stderr.fileno()):
syslog_flags |= syslog.LOG_PERROR
syslog.openlog("rpki-torrent", syslog_flags)
# If I seriously expected this script to get a lot of further use,
# I might rewrite this using subparsers, but it'd be a bit tricky
# as argparse doesn't support making the subparser argument
# optional and transmission gives no sane way to provide arguments
# when running a completion script. So, for the moment, let's
# just fix the bugs accidently introduced while converting the
# universe to argparse without making any radical changes to the
# program structure here, even if the result looks kind of klunky.
parser = argparse.ArgumentParser(description = __doc__)
parser.add_argument("-c", "--config",
help = "configuration file")
parser.add_argument("action", choices = ("poll", "generate", "mirror"), nargs = "?",
help = "action to take")
args = parser.parse_args()
global cfg
cfg = MyConfigParser()
cfg.read(args.config or
[os.path.join(dn, fn)
for fn in ("rcynic.conf", "rpki.conf")
for dn in ("/var/rcynic/etc", "/usr/local/etc", "/etc")])
if cfg.act_as_generator:
if args.action == "generate":
generator_main()
elif args.action == "mirror":
mirror_main()
else:
raise UseTheSourceLuke
else:
if args.action is None and all(v in os.environ for v in tr_env_vars):
torrent_completion_main()
elif args.action == "poll":
poll_main()
else:
raise UseTheSourceLuke
except:
for line in traceback.format_exc().splitlines():
syslog.syslog(line)
sys.exit(1)