我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用syslog.LOG_PID。
def __init__(self, name, facility=syslog.LOG_DAEMON): logging.Handler.__init__(self) syslog.openlog(name, syslog.LOG_PID, facility)
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 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)