Skip to content

Commit

Permalink
Enable nxos-installos syslog (#35)
Browse files Browse the repository at this point in the history
* Added ability to log to syslog for nxos-installos script

* uprev setup.py
  • Loading branch information
bobbywatson3 authored Nov 15, 2017
1 parent 6d476da commit b5c96ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
39 changes: 19 additions & 20 deletions bin/nxos-installos
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import sys
import os
import json
import argparse
import yaml
import logging
import logging.handlers

import aeon.nxos as nxos
from aeon.nxos.exceptions import NxosException
Expand Down Expand Up @@ -50,10 +50,17 @@ psr.add_argument(
'--md5sum', required=True,
help='MD5 checksum value')

psr.add_argument(
log_group = psr.add_mutually_exclusive_group()
log_group.add_argument(
'--logfile',
help='name of log file')

log_group.add_argument(
'--syslog',
action='store_true',
help='If set, log to syslog.'
)

# ##### -------------------------
# ##### authentication
# ##### -------------------------
Expand All @@ -75,35 +82,27 @@ group.add_argument(
g_cli_args = psr.parse_args()


def setup_logging(logname, logfile, target):
def setup_logging(logname, target, syslog=False, logfile=None):
log = logging.getLogger(name=logname)
log.setLevel(logging.INFO)

fmt = logging.Formatter(
'%(asctime)s:%(levelname)s:{target}:%(message)s'
.format(target=target))

handler = logging.FileHandler(logfile) if logfile else logging.StreamHandler(sys.stdout)
'%(name)s %(levelname)s {target}: %(message)s'.format(target=target))
if syslog:
handler = logging.handlers.SysLogHandler(address='/dev/log')
elif logfile:
handler = logging.FileHandler(logfile)
else:
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(fmt)
log.addHandler(handler)
return log


g_log = setup_logging(logname=_PROGNAME,
logfile=g_cli_args.logfile,
target=g_cli_args.target)
def setup_logging():
g_log.setLevel(logging.INFO)
fh = logging.FileHandler(g_cli_args.logfile)
fmt = logging.Formatter(
'%(asctime)s:%(levelname)s: {target}:%(message)s'
.format(target=g_cli_args.target))
fh.setFormatter(fmt)
g_log.addHandler(fh)

if g_cli_args.logfile:
setup_logging()

target=g_cli_args.target,
syslog=g_cli_args.syslog)

# ##### -----------------------------------------------------------------------
# #####
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def requirements(filename):

setup(
name="aeon-venos",
version="0.9.6",
version="0.9.7",
author="Jeremy Schulman",
url='https://github.com/Apstra/aeon-venos',
author_email="jeremy@apstra.com",
Expand Down

0 comments on commit b5c96ca

Please sign in to comment.