diff --git a/.gitignore b/.gitignore index ac7b2b5..03d330b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -*.psd \ No newline at end of file +*.psd +*.pyc +*.log +*.log \ No newline at end of file diff --git a/plugin_test/boswatch.log b/plugin_test/boswatch.log new file mode 100644 index 0000000..0564611 --- /dev/null +++ b/plugin_test/boswatch.log @@ -0,0 +1,50 @@ +18.05.2015 03:30:59 - INFO: Alarm! +18.05.2015 03:30:59 - DEBUG: Loading plugin template +18.05.2015 03:30:59 - DEBUG: Throw Template Plugin +18.05.2015 03:30:59 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! +18.05.2015 03:30:59 - DEBUG: try 5/0 +18.05.2015 03:30:59 - ERROR: Error in Template Plugin +Traceback (most recent call last): + File "./plugins\template\__init__.py", line 8, in run + test = 5/0 +ZeroDivisionError: division by zero +18.05.2015 03:31:00 - INFO: Alarm! +18.05.2015 03:31:00 - DEBUG: Loading plugin template +18.05.2015 03:31:00 - DEBUG: Throw Template Plugin +18.05.2015 03:31:00 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! +18.05.2015 03:31:00 - DEBUG: try 5/0 +18.05.2015 03:31:00 - ERROR: Error in Template Plugin +Traceback (most recent call last): + File "./plugins\template\__init__.py", line 8, in run + test = 5/0 +ZeroDivisionError: division by zero +18.05.2015 03:31:01 - INFO: Alarm! +18.05.2015 03:31:01 - DEBUG: Loading plugin template +18.05.2015 03:31:01 - DEBUG: Throw Template Plugin +18.05.2015 03:31:01 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! +18.05.2015 03:31:01 - DEBUG: try 5/0 +18.05.2015 03:31:01 - ERROR: Error in Template Plugin +Traceback (most recent call last): + File "./plugins\template\__init__.py", line 8, in run + test = 5/0 +ZeroDivisionError: division by zero +18.05.2015 03:31:02 - INFO: Alarm! +18.05.2015 03:31:02 - DEBUG: Loading plugin template +18.05.2015 03:31:02 - DEBUG: Throw Template Plugin +18.05.2015 03:31:02 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! +18.05.2015 03:31:02 - DEBUG: try 5/0 +18.05.2015 03:31:02 - ERROR: Error in Template Plugin +Traceback (most recent call last): + File "./plugins\template\__init__.py", line 8, in run + test = 5/0 +ZeroDivisionError: division by zero +18.05.2015 03:31:03 - INFO: Alarm! +18.05.2015 03:31:03 - DEBUG: Loading plugin template +18.05.2015 03:31:03 - DEBUG: Throw Template Plugin +18.05.2015 03:31:03 - INFO: ZVEI: 12345 wurde auf 80000000 empfangen! +18.05.2015 03:31:03 - DEBUG: try 5/0 +18.05.2015 03:31:03 - ERROR: Error in Template Plugin +Traceback (most recent call last): + File "./plugins\template\__init__.py", line 8, in run + test = 5/0 +ZeroDivisionError: division by zero diff --git a/plugin_test/plugin_test.py b/plugin_test/plugin_test.py index daff263..b85c5c2 100644 --- a/plugin_test/plugin_test.py +++ b/plugin_test/plugin_test.py @@ -4,10 +4,43 @@ import time import pluginloader +#create new logger +import logging +logger = logging.getLogger() +logger.setLevel(logging.DEBUG) + +#set log string format +formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s', '%d.%m.%Y %I:%M:%S') + +#create a file loger +fh = logging.FileHandler('boswatch.log', 'w') +fh.setLevel(logging.DEBUG) #log level >= Debug +fh.setFormatter(formatter) +logger.addHandler(fh) + +#create a display loger +ch = logging.StreamHandler() +ch.setLevel(logging.ERROR) #log level >= Error +ch.setFormatter(formatter) +logger.addHandler(ch) + +#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 - critical error, program exit + + +data = {"zvei":"12345"} + while True: time.sleep(1) - print ("Alarm!") + logging.info("Alarm!") for i in pluginloader.getPlugins(): - print("Loading plugin " + i["name"]) + logging.debug("Load Plugin: " + i["name"]) plugin = pluginloader.loadPlugin(i) - plugin.run() \ No newline at end of file + plugin.run("zvei","80000000",data) \ No newline at end of file diff --git a/plugin_test/plugins/http/__init__.py b/plugin_test/plugins/http/__init__.py deleted file mode 100644 index 5f1887e..0000000 --- a/plugin_test/plugins/http/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -def run(): - print("throw HTTP Plugin") \ No newline at end of file diff --git a/plugin_test/plugins/interface.txt b/plugin_test/plugins/interface.txt new file mode 100644 index 0000000..6d487c8 --- /dev/null +++ b/plugin_test/plugins/interface.txt @@ -0,0 +1,19 @@ +Übergabe an Plugin: + +typ = FMS, ZVEI oder POC +freq = Frequenz in Hz +data = {"KEY":"VALUE"} als Python Dict + +ZVEI: +- zvei + +FMS: +- fms +- status +- direction +- tki + +POCSAG: +- ric +- sub_ric +- text diff --git a/plugin_test/plugins/mysql/__init__.py b/plugin_test/plugins/mysql/__init__.py deleted file mode 100644 index c61db52..0000000 --- a/plugin_test/plugins/mysql/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -def run(): - print("Throw MySql Plugin") \ No newline at end of file diff --git a/plugin_test/plugins/template/__init__.py b/plugin_test/plugins/template/__init__.py index 1f27ab2..bd86c59 100644 --- a/plugin_test/plugins/template/__init__.py +++ b/plugin_test/plugins/template/__init__.py @@ -1,2 +1,10 @@ -def run(): - print("Throw template Plugin") \ No newline at end of file +import logging + +def run(typ,freq,data): + logging.debug("Strat Plugin: template") + try: + logging.info("ZVEI: %s wurde auf %s empfangen!", data["zvei"],freq) + logging.debug("try 5/0") + test = 5/0 + except: + logging.exception("Error in Template Plugin") \ No newline at end of file