Skip to content
Snippets Groups Projects
Commit b6e90643 authored by David Jericho's avatar David Jericho
Browse files

#881 cta-fst-gcd logs can be now sent to stdout by command line option for...

#881 cta-fst-gcd logs can be now sent to stdout by command line option for container based deployments
parent ea9a2eef
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,9 @@ Prints the usage message.
\fB\-c CONFIG, \-\-config CONFIG
Sets the path of the configuration file. If not set then the default value of
\fB/etc/cta/cta-fst-gcd.conf\fP is used.
.TP
\fB\-s, \-\-stdout
Sets log output to stdout. This disables use of a log file.
.SH RETURN VALUE
Zero on success and non-zero on failure.
.SH FILES
......@@ -57,7 +60,7 @@ parameters.
.TP
.B /var/log/eos/fst/cta-fst-gcd.log
The default log file of the \fBcta-fst-gcd\fP daemon. This can be overriden by
modifying \fBcta-fst-gcd.conf\fP accordingly.
modifying \fBcta-fst-gcd.conf\fP accordingly or disabled using the
\fB\-s\fP/\fB\-\-stdout\fP option.
.SH AUTHOR
\fBCTA\fP Team
......@@ -504,6 +504,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', default='/etc/cta/{}.conf'.format(programname), help='Configuration file path')
parser.add_argument('-s', '--stdout', action='store_true', help='Print logs to standard output, overriding configuration file path')
args = parser.parse_args()
if not os.path.isfile(args.config):
......@@ -521,7 +522,12 @@ def main():
hostname = socket.gethostname()
fqdn = socket.getfqdn()
log = get_logger(hostname, programname, config.log_file)
if args.stdout == True:
# If --stdout has been given on the command line, use False as the log path to set output to stdout
log = get_logger(hostname, programname, False)
else:
log = get_logger(hostname, programname, config.log_file)
log.info('{} started'.format(programname))
log.info('The fqdn of this machine is {}'.format(fqdn))
......@@ -540,11 +546,15 @@ def get_logger(hostname, programname, logpath):
log_handler = None
logging_dir = os.path.dirname(logpath)
if not os.path.isdir(logging_dir):
raise UserError('The logging directory {} is not a directory or does not exist'.format(logging_dir))
if not os.access(logging_dir, os.W_OK):
raise UserError('The logging directory {} cannot be written to'.format(logging_dir))
if logpath == False:
log_handler = logging.StreamHandler(stream = sys.stdout)
else:
logging_dir = os.path.dirname(logpath)
if not os.path.isdir(logging_dir):
raise UserError('The logging directory {} is not a directory or does not exist'.format(logging_dir))
if not os.access(logging_dir, os.W_OK):
raise UserError('The logging directory {} cannot be written to'.format(logging_dir))
log_handler = logging.handlers.TimedRotatingFileHandler(filename = logpath, when = 'midnight')
log_handler = logging.handlers.TimedRotatingFileHandler(filename = logpath, when = 'midnight')
log_handler.setLevel(logging.INFO)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment