cleaned up all this logging stuff. logging to files does not work anymore but that will be fixed. use -q when starting linspector for now

This commit is contained in:
Johannes Findeisen 2013-10-27 02:28:20 +01:00
commit cbb106ee8a
38 changed files with 188 additions and 164 deletions

View file

@ -18,16 +18,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import subprocess as sp
from subprocess import Popen
from subprocess import CalledProcessError
from datetime import datetime as dt
from logging import getLogger
logger = getLogger(__name__)
#TODO: Move this to shell.py service file. this definitely is shell execution. (hanez)
class Command:
def __init__(self, command, log):
def __init__(self, command):
self.command = command
self.log = log
self.output = None
self.error = None
self.retcode = 0
@ -46,12 +50,12 @@ class Command:
try:
self.commandStart = dt.now()
self.log.info("calling command " + str(self.command) + " at " + str(self.commandStart))
logger.info("calling command " + str(self.command) + " at " + str(self.commandStart))
#self.output=sp.check_output(self.command.split())
process = Popen(self.command, stdout=sp.PIPE, stderr=sp.PIPE, shell=True)
self.output, self.error = process.communicate()
self.log.debug(str(self.output))
self.log.debug(str(self.error))
logger.debug(str(self.output))
logger.debug(str(self.error))
self.retcode = process.poll()
except CalledProcessError:
self.error = CalledProcessError.output

View file

@ -22,14 +22,11 @@ import sys
import os
import time
import atexit
from signal import SIGTERM
"""
TODO: Think about, that daemonizing this software is not our goal but when we want to that, this needs a rewrite and
should maybe move over to the daemon frontend. daemon.py will remain the the base for this and should stay in linspector/core .
Since a daemon it normally not a frontend we should think about how to handle this. When daemonizing a real frontend
like "Lish" will make no sense but a frontend like "https" or "xmpp" could be useful anyway...
"""
from signal import SIGTERM
from logging import getLogger
logger = getLogger(__name__)
class LinspectorDaemon(Daemon):

View file

@ -21,6 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from collections import OrderedDict
from logging import getLogger
logger = getLogger(__name__)
class LinspectorInterface(object):

View file

@ -22,6 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from binascii import crc32
from logging import getLogger
logger = getLogger(__name__)
def generateId():
@ -60,9 +63,6 @@ class Job:
ret = "0" + ret
return ret
def set_logger(self, log):
self.log = log
def set_job(self, job):
self.job = job
@ -85,7 +85,7 @@ class Job:
self.jobThreshold += 1
if self.jobThreshold >= serviceThreshold:
self.log.debug("Threshold reached!")
logger.debug("Threshold reached!")
self.handle_alarm(jobInfo, self.jobThreshold - serviceThreshold)
def handle_alarm(self, jobInfo, thresholdOffset):
@ -95,8 +95,8 @@ class Job:
task.execute(jobInfo.get_message(), self.core)
def handle_call(self):
self.log.debug("handle call")
self.log.debug(self.service)
logger.debug("handle call")
logger.debug(self.service)
if self._enabled:
try:
jobInfo = JobInfo(self.hex_string(), self.host, self.service)
@ -105,14 +105,14 @@ class Job:
self.handle_threshold(jobInfo, self.service.get_threshold(), jobInfo.was_execution_successful())
self.log.debug("Code: " + str(jobInfo.get_errorcode()) + ", Message: " + str(jobInfo.get_message()))
logger.debug("Code: " + str(jobInfo.get_errorcode()) + ", Message: " + str(jobInfo.get_message()))
self.jobInfos.append(jobInfo)
except Exception, e:
self.log.debug(e)
logger.debug(e)
else:
self.log.debug("Job " + self.hex_string() + " disabled")
logger.debug("Job " + self.hex_string() + " disabled")
class JobInfo(object):

View file

@ -17,15 +17,11 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from ..core import logger
from logging import getLogger
from ..core.daemon import Daemon
"""
TODO: Think about, that daemonizing this software is not our goal but when we want to that, this needs a rewrite and
should maybe move over to the daemon frontend. daemon.py will remain the the base for this and should stay in linspector/core .
Since a daemon it normally not a frontend we should think about how to handle this. When daemonizing a real frontend
like "Lish" will make no sense but a frontend like "https" or "xmpp" could be useful anyway...
"""
logger = getLogger(__name__)
class LinspectorDaemon(Daemon):

View file

@ -1,77 +0,0 @@
"""
Copyright (c) 2011-2013 "Johannes Findeisen and Rafael Timmerberg"
This file is part of Linspector (http://linspector.org).
Linspector is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging
import logging.handlers
import os
import os.path as path
class Logger():
"""
Logger class that prints its messages and keeps them also inside a logfile
"""
def __init__(self, logfile="./linspector.log", logLevel=logging.DEBUG, logfileLevel=logging.DEBUG):
"""
initializes a new Logger object.
:param logLevel: the LoggingLevel from the console output (DEBUG default)
:param logfile: the file where to log. Logs are rotated by default.
:param logfileLevel: the LoggingLevel for the file Logger. (DEBUG default)
"""
logfile = path.expanduser(logfile)
if not path.exists(path.dirname(logfile)):
os.makedirs(path.dirname(logfile))
self.log = logging.getLogger("LinspectorLogger")
self.log.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler()
consoleHandler.setLevel(logLevel)
fileHandler = logging.handlers.RotatingFileHandler(logfile, maxBytes=1024000, backupCount=4)
fileHandler.setLevel(logfileLevel)
consoleFormatter = logging.Formatter('[%(levelname)s]: %(message)s')
fileFormatter = logging.Formatter('%(asctime)s [%(levelname)s]: %(message)s')
consoleHandler.setFormatter(consoleFormatter)
fileHandler.setFormatter(fileFormatter)
self.log.addHandler(consoleHandler)
self.log.addHandler(fileHandler)
def d(self, message):
self.log.debug(message)
def i(self, message):
self.log.info(message)
def w(self, message):
self.log.warn(message)
def e(self, message):
self.log.error(message)
def c(self, message):
self.log.critical(message)
def close(self):
logging.shutdown()

View file

@ -17,8 +17,12 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from logging import getLogger
from apscheduler.scheduler import Scheduler
logger = getLogger(__name__)
class Scheduler(Scheduler):
def test(self):