pretty job string function for lish, fixed logging
TODO: set Logging levels
This commit is contained in:
parent
157de0cbd4
commit
0bfb8ef3ae
4 changed files with 22 additions and 6 deletions
|
|
@ -62,13 +62,14 @@ def parseArgs():
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def setupLogging(logfile="./log/linspector.log", logLevel=logging.DEBUG, logfileLevel=logging.DEBUG):
|
def setupLogging(logfile="./log/linspector.log", logLevel=logging.ERROR, logfileLevel=logging.DEBUG):
|
||||||
logfile = path.expanduser(logfile)
|
logfile = path.expanduser(logfile)
|
||||||
if not path.exists(path.dirname(logfile)):
|
if not path.exists(path.dirname(logfile)):
|
||||||
os.makedirs(path.dirname(logfile))
|
os.makedirs(path.dirname(logfile))
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.CRITICAL)
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
log.setLevel(logging.DEBUG)
|
#log.setLevel(logging.)
|
||||||
|
|
||||||
consoleHandler = logging.StreamHandler()
|
consoleHandler = logging.StreamHandler()
|
||||||
consoleHandler.setLevel(logLevel)
|
consoleHandler.setLevel(logLevel)
|
||||||
|
|
@ -76,6 +77,7 @@ def setupLogging(logfile="./log/linspector.log", logLevel=logging.DEBUG, logfile
|
||||||
fileHandler = logging.handlers.RotatingFileHandler(logfile, maxBytes=1024000, backupCount=4)
|
fileHandler = logging.handlers.RotatingFileHandler(logfile, maxBytes=1024000, backupCount=4)
|
||||||
fileHandler.setLevel(logfileLevel)
|
fileHandler.setLevel(logfileLevel)
|
||||||
|
|
||||||
|
|
||||||
consoleFormatter = logging.Formatter('[%(levelname)s]: %(message)s')
|
consoleFormatter = logging.Formatter('[%(levelname)s]: %(message)s')
|
||||||
#TODO: if debug with file and function else without that
|
#TODO: if debug with file and function else without that
|
||||||
fileFormatter = logging.Formatter('%(asctime)s %(pathname)s %(module)s %(funcName)s %(lineno)d [%(levelname)s]: %(message)s')
|
fileFormatter = logging.Formatter('%(asctime)s %(pathname)s %(module)s %(funcName)s %(lineno)d [%(levelname)s]: %(message)s')
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ KEY_CORE = "core"
|
||||||
|
|
||||||
class ConfigurationException(Exception):
|
class ConfigurationException(Exception):
|
||||||
def __init__(self, msg, log):
|
def __init__(self, msg, log):
|
||||||
log.e(msg)
|
log.error(msg)
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from binascii import crc32
|
||||||
|
|
||||||
|
|
||||||
def generateId():
|
def generateId():
|
||||||
|
|
@ -43,9 +44,22 @@ class Job:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.__dict__)
|
return str(self.__dict__)
|
||||||
|
|
||||||
|
|
||||||
|
def __hex__(self):
|
||||||
|
return hex(crc32(str(self.service) + str(self.host) + str(self.members)))
|
||||||
|
|
||||||
def set_logger(self, log):
|
def set_logger(self, log):
|
||||||
self.log = log
|
self.log = log
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def pretty_string(self):
|
||||||
|
ret = self.__hex__()
|
||||||
|
if ret[0] == "-":
|
||||||
|
ret = ret[1:]
|
||||||
|
ret += ": (" + str(self.host) + str(self.service) + str(self.job) + ")"
|
||||||
|
return ret[2:]
|
||||||
|
|
||||||
def set_job(self, job):
|
def set_job(self, job):
|
||||||
self.job = job
|
self.job = job
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ class LishCommander(Exit, ShellCommander, LogCommander):
|
||||||
try:
|
try:
|
||||||
hgCommander = HostgroupCommander(hg)
|
hgCommander = HostgroupCommander(hg)
|
||||||
hgCommander.cmdloop("Entering Hostmode of " + hgName + ":\n")
|
hgCommander.cmdloop("Entering Hostmode of " + hgName + ":\n")
|
||||||
except KeyboardInterrupt, ke:
|
except KeyboardInterrupt, key:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def do_python(self, text):
|
def do_python(self, text):
|
||||||
|
|
@ -172,8 +172,8 @@ class LishCommander(Exit, ShellCommander, LogCommander):
|
||||||
|
|
||||||
def do_jobs(self, text):
|
def do_jobs(self, text):
|
||||||
if text == "list":
|
if text == "list":
|
||||||
for job in self._scheduler.get_jobs():
|
for job in self._jobs:
|
||||||
print job
|
print job.pretty_string()
|
||||||
|
|
||||||
def help_jobs(self):
|
def help_jobs(self):
|
||||||
print "Job helper functions"
|
print "Job helper functions"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue