simple logging and data output with plugin

This commit is contained in:
Schrolli 2015-05-18 12:03:42 +02:00
parent 466e017cfb
commit 947bc9417c
6 changed files with 93 additions and 8 deletions

43
plugin_test/boswatch.log Normal file
View file

@ -0,0 +1,43 @@
18.05.2015 12:00:39 - INFO: Alarm!
18.05.2015 12:00:39 - DEBUG: Loading plugin template
18.05.2015 12:00:39 - DEBUG: Throw Template Plugin
18.05.2015 12:00:40 - INFO: Alarm!
18.05.2015 12:00:40 - DEBUG: Loading plugin template
18.05.2015 12:00:40 - DEBUG: Throw Template Plugin
18.05.2015 12:00:41 - INFO: Alarm!
18.05.2015 12:00:41 - DEBUG: Loading plugin template
18.05.2015 12:00:41 - DEBUG: Throw Template Plugin
18.05.2015 12:00:42 - INFO: Alarm!
18.05.2015 12:00:42 - DEBUG: Loading plugin template
18.05.2015 12:00:42 - DEBUG: Throw Template Plugin
18.05.2015 12:01:58 - INFO: Alarm!
18.05.2015 12:01:58 - DEBUG: Loading plugin template
18.05.2015 12:01:58 - DEBUG: Throw Template Plugin
18.05.2015 12:01:58 - DEBUG: try 5/0
18.05.2015 12:02:09 - INFO: Alarm!
18.05.2015 12:02:09 - DEBUG: Loading plugin template
18.05.2015 12:02:09 - DEBUG: Throw Template Plugin
18.05.2015 12:02:09 - DEBUG: try 5/0
18.05.2015 12:02:09 - ERROR: Error in Template Plugin
Traceback (most recent call last):
File "./plugins\template\__init__.py", line 7, in run
test = 5/0
ZeroDivisionError: division by zero
18.05.2015 12:02:10 - INFO: Alarm!
18.05.2015 12:02:10 - DEBUG: Loading plugin template
18.05.2015 12:02:10 - DEBUG: Throw Template Plugin
18.05.2015 12:02:10 - DEBUG: try 5/0
18.05.2015 12:02:10 - ERROR: Error in Template Plugin
Traceback (most recent call last):
File "./plugins\template\__init__.py", line 7, in run
test = 5/0
ZeroDivisionError: division by zero
18.05.2015 12:02:11 - INFO: Alarm!
18.05.2015 12:02:11 - DEBUG: Loading plugin template
18.05.2015 12:02:11 - DEBUG: Throw Template Plugin
18.05.2015 12:02:11 - DEBUG: try 5/0
18.05.2015 12:02:11 - ERROR: Error in Template Plugin
Traceback (most recent call last):
File "./plugins\template\__init__.py", line 7, in run
test = 5/0
ZeroDivisionError: division by zero

View file

@ -4,10 +4,23 @@
import time
import pluginloader
import logging
logging.basicConfig(filename='boswatch.log',level=logging.DEBUG, format='%(asctime)s - %(levelname)s: %(message)s', datefmt='%d.%m.%Y %I:%M:%S')
#https://docs.python.org/2/howto/logging.html#logging-basic-tutorial
#log levels
#debug - debug messages only for log
#info - only an information
#warning
#error - normal error - program goes further
#exception - error handler in try:exc: into the message
#critical - big error, program exit
while True:
time.sleep(1)
print ("Alarm!")
logging.info("Alarm!")
for i in pluginloader.getPlugins():
print("Loading plugin " + i["name"])
logging.debug("Loading plugin " + i["name"])
plugin = pluginloader.loadPlugin(i)
plugin.run()
plugin.run("zvei","","","12345","","")

View file

@ -1,2 +0,0 @@
def run():
print("throw HTTP Plugin")

View file

@ -0,0 +1,26 @@
ZVEI:
=====
typ = zvei
time = datetime
frequenz= empfangsfrequenz
data1 = zvei code
data2 =
data3 =
FMS:
====
typ = fms
time = datetime
frequenz= empfangsfrequenz
data1 = fms kennung
data2 = status
data3 = richtung
POCSAG 1200:
============
typ = poc1200
time = datetime
frequenz= empfangsfrequenz
data1 = ric
data2 = sub_ric
data3 = text

View file

@ -1,2 +0,0 @@
def run():
print("Throw MySql Plugin")

View file

@ -1,2 +1,9 @@
def run():
print("Throw template Plugin")
import logging
def run(typ,time,frequenz,data1,data2,data3):
logging.debug("Throw Template Plugin")
try:
logging.debug("try 5/0")
test = 5/0
except:
logging.exception("Error in Template Plugin")