## @package Log # Wrapper for Python logging # # @author mob # # for questions and comments: # support@neobotix.de, subject: "Logging" # # ----------------------------------------------------------------------------------- # # Copyright (c) 2009 Neobotix (www.neobotix.de) # # This software is allowed to be used and modified only in association with a Neobotix # robot platform. It is allowed to include the software into applications and # to distribute it with a Neobotix robot platform. # # This software is provided WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the Neobotix License (Version 1.0) for more details. # # You should have received a copy of the Neobotix License # along with this software; if not, write to the # Gesellschaft fuer Produktionssysteme, Neobotix, Nobelstrasse 12, 70569 Stuttgart, Germany # # ----------------------------------------------------------------------------------- import logging import logging.handlers PORT = 4445 formatter = logging.Formatter("%(levelname)-5s %(asctime)s %(module)s %(lineno)-4d %(message)s") # remote logging handler global h2 h2 = logging.handlers.DatagramHandler("127.0.0.1", PORT) # Set up a specific logger with our desired output level logger = logging.getLogger('NeoPyClientLog') logger.setLevel(logging.DEBUG) h0 = logging.StreamHandler() h0.setFormatter(formatter) logger.addHandler(h0) ## Set up the rotating File handler # @param filename The name of the logfiles # @param max_size The maximum size in bytes # @param backupCount The number of files to save # # Initializes the rotating file handler def initFileHandler(filename, max_size, fileCount): h1 = logging.handlers.RotatingFileHandler(filename, maxBytes=max_size, backupCount=fileCount) h1.setFormatter(formatter) logger.addHandler(h1) ## Set the log level # @param level the log level, 0 is critical, 4 is debug # # Set the log level def setLogLevel(level): if(level==0): logger.setLevel(logging.CRITICAL) if(level==1): logger.setLevel(logging.ERROR) if(level==2): logger.setLevel(logging.WARNING) if(level==3): logger.setLevel(logging.INFO) else: logger.setLevel(logging.DEBUG) ## Start remote logging # @param server The server to log to # # Start remote logging def initRemoteLog(server): global h2 if h2: logger.removeHandler(h2) h2 = logging.handlers.DatagramHandler(server, PORT) h2.setFormatter(formatter) logger.addHandler(h2) logger.debug(" try to connect to:" + server + " port:" + str(PORT))