Ver código fonte

added some more info messages, imporved logging

Helmut Pozimski 11 anos atrás
pai
commit
6e17e8788b
1 arquivos alterados com 10 adições e 10 exclusões
  1. 10 10
      stdd

+ 10 - 10
stdd

@@ -39,19 +39,15 @@ parser.add_option("-c", "--config", dest="config", help="define an\
 	alternative path to the configuration file")
 (options, arguments) = parser.parse_args()
 
-""" define a sighandler to properly catch signals """
-
-
-run = True
 
 
 """ define a sighandler to properly catch signals """
 
 def sighandler(signum, frame):
 	if signum == 2:
-		pass
+		logger.info("received SIGINT, stopping daemon")
 	elif signum == 15:
-		pass
+		logger.info("received SIGTERM, stopping daemon")
 	display.writeDigit(0, 0)
 	display.writeDigit(1, 0)
 	display.writeDigit(3, 0)
@@ -60,7 +56,7 @@ def sighandler(signum, frame):
 		if daemon.Stop() is True:
 			sys.exit(0)
 		else:
-			#TODO: Log error message
+			logger.error("stopping daemon failed, PID file was not deleted!")
 			sys,exit(1)
 	
 """ create the configuration object according to the given parameters and
@@ -90,10 +86,14 @@ elif config.syslog_level == "error":
 else:
 	logger.setLevel(logging.INFO)
 
-syslog_handler = logging.handlers.SysLogHandler("/dev/log")
+if config.syslog_facility == "user":
+	syslog_handler = logging.handlers.SysLogHandler("/dev/log")
+elif config.syslog_facility == "daemon":
+	syslog_handler = logging.handlers.SysLogHandler("/dev/log",
+		facility=logging.handlers.SysLogHandler.LOG_DAEMON)
 console_handler = logging.StreamHandler()
 
-formatter = logging.Formatter("%%(name)s:  %(message)s")
+formatter = logging.Formatter("%(name)s[os.getuid()]:  %(message)s")
 
 syslog_handler.setFormatter(formatter)
 console_handler.setFormatter(formatter)
@@ -145,7 +145,7 @@ else:
 	display.setBrightness(config.brightness_low)
 """Define the main loop"""
 def main():
-	while run is True:
+	while True:
 		date_now = datetime.datetime.now()
 		minute = date_now.minute
 		hour = date_now.hour