diff options
-rw-r--r-- | man/bcfg2-server.8 | 4 | ||||
-rw-r--r-- | man/bcfg2.1 | 4 | ||||
-rw-r--r-- | src/lib/Logger.py | 7 | ||||
-rw-r--r-- | src/lib/Options.py | 2 | ||||
-rwxr-xr-x | src/sbin/bcfg2 | 3 | ||||
-rwxr-xr-x | src/sbin/bcfg2-reports | 9 | ||||
-rwxr-xr-x | src/sbin/bcfg2-server | 5 |
7 files changed, 25 insertions, 9 deletions
diff --git a/man/bcfg2-server.8 b/man/bcfg2-server.8 index 67bac3755..a6abd5a92 100644 --- a/man/bcfg2-server.8 +++ b/man/bcfg2-server.8 @@ -27,6 +27,10 @@ Use an alternative path for bcfg2.conf. The default is /etc/bcfg2.conf .RS Daemonize, placing the program pid in the specified pidfile. .RE +.B \-o <LogFile Path> +.RS +Writes a log to the specified path. +.RE .SH "SEE ALSO" .BR bcfg2(1), .BR bcfg2-repo-validate(8) diff --git a/man/bcfg2.1 b/man/bcfg2.1 index f03ba35e7..841beb7d9 100644 --- a/man/bcfg2.1 +++ b/man/bcfg2.1 @@ -82,6 +82,10 @@ verbosity rework) Run in bulletproof mode. This currently only effect behavior in the debian toolset; it calls apt-get update and clean and dpkg --configure --pending. .RE +.B \-o <LogFile Path> +.RS +Writes a log to the specified path. +.RE .SH "SEE ALSO" .BR bcfg2-server(8), .BR bcfg2-info(8) diff --git a/src/lib/Logger.py b/src/lib/Logger.py index 429538090..b9b4679bb 100644 --- a/src/lib/Logger.py +++ b/src/lib/Logger.py @@ -127,7 +127,7 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler): self.socket.send("Reconnected to syslog") self.socket.send(msg) -def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='daemon', level=0): +def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='daemon', level=0, to_file=None): '''setup logging for bcfg2 software''' if hasattr(logging, 'already_setup'): return @@ -151,5 +151,10 @@ def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='da logging.root.error("failed to activate syslogging") except: print "Failed to activate syslogging" + if not to_file == None: + filelog = logging.FileHandler(to_file) + filelog.setLevel(logging.DEBUG) + filelog.setFormatter(logging.Formatter('%(name)s[%(process)d]: %(message)s')) + logging.root.addHandler(filelog) logging.root.setLevel(level) logging.already_setup = True diff --git a/src/lib/Options.py b/src/lib/Options.py index 5d62196aa..21cb31fdf 100644 --- a/src/lib/Options.py +++ b/src/lib/Options.py @@ -253,6 +253,8 @@ ENCODING = Option('Encoding of cfg files', default=sys.getdefaultencoding(), cmd OMIT_LOCK_CHECK = Option('Omit lock check', default=False, cmd='-O') +LOGGING_FILE_PATH = Option('Set path of file log', default=None, cmd='-o', odesc='<path>', cf=('logging', 'path')) + class OptionParser(OptionSet): '''OptionParser bootstraps option parsing, getting the value of the config file''' def __init__(self, args): diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2 index 6f7612b0b..42371009f 100755 --- a/src/sbin/bcfg2 +++ b/src/sbin/bcfg2 @@ -120,6 +120,7 @@ class Client: 'decision-list': DECISION_LIST, 'encoding': Bcfg2.Options.ENCODING, 'omit-lock-check': Bcfg2.Options.OMIT_LOCK_CHECK, + 'filelog': Bcfg2.Options.LOGGING_FILE_PATH, } self.setup = Bcfg2.Options.OptionParser(optinfo) @@ -134,7 +135,7 @@ class Client: level = 20 if self.setup['debug']: level = 0 - Bcfg2.Logger.setup_logging('bcfg2', to_syslog=False, level=level) + Bcfg2.Logger.setup_logging('bcfg2', to_syslog=False, level=level, to_file=self.setup['filelog']) self.logger = logging.getLogger('bcfg2') self.logger.debug(self.setup) if 'drivers' in self.setup and self.setup['drivers'] == 'help': diff --git a/src/sbin/bcfg2-reports b/src/sbin/bcfg2-reports index 1e64669e8..fdc9989d0 100755 --- a/src/sbin/bcfg2-reports +++ b/src/sbin/bcfg2-reports @@ -88,9 +88,9 @@ def print_fields(fields, cli, max_name, entrydict): print display def print_entry(item, max_name): - fmt = ("%%-%dx " % (max_name)) - fdata = [item.name, item.kind] - dispplay = fmt % tuple(fdata) + fmt = ("%%-%ds " % (max_name)) + fdata = item.kind + ":" + item.name + display = fmt % (fdata) print display fields = "" @@ -120,7 +120,7 @@ for option in opts: extraentry = option[1] if option[0] == '-x': expire = option[1] - if option[0] == '-s': + if option[0] == '-s' or option[0] == '-b' or option[0] == '-e': singlehost = option[1] if expire != "": @@ -255,7 +255,6 @@ else: else: for c_inst in c_list: result.append(c_inst) - max_name = -1 if 'name' in fields: for c_inst in result: diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server index d58c8b45e..ba438a07d 100755 --- a/src/sbin/bcfg2-server +++ b/src/sbin/bcfg2-server @@ -208,6 +208,7 @@ if __name__ == '__main__': 'passwd' : Bcfg2.Options.SERVER_PASSWORD, 'static' : Bcfg2.Options.SERVER_STATIC, 'encoding' : Bcfg2.Options.ENCODING, + 'filelog' : Bcfg2.Options.LOGGING_FILE_PATH, }) @@ -217,10 +218,10 @@ if __name__ == '__main__': level = 0 if setup['daemon']: - Bcfg2.Logger.setup_logging('bcfg2-server', to_console=False, level=level) + Bcfg2.Logger.setup_logging('bcfg2-server', to_console=False, level=level, to_file=setup['filelog']) Bcfg2.Daemon.daemonize(setup['daemon']) else: - Bcfg2.Logger.setup_logging('bcfg2-server', level=level) + Bcfg2.Logger.setup_logging('bcfg2-server', level=level, to_file=setup['filelog']) if not setup['key']: print "No key specified in '%s'" % setup['configfile'] |