Browse Source

[logs] added log level for LOGLEVEL environment variable, INFO is default. fixed typo in variable_value

Maxime Alves LIRMM@home 3 years ago
parent
commit
e025bc47bb
2 changed files with 17 additions and 5 deletions
  1. 7
    4
      pyheatpump/logger.py
  2. 10
    1
      pyheatpump/models/variable_value.py

+ 7
- 4
pyheatpump/logger.py View File

@@ -1,17 +1,20 @@
1 1
 #!/usr/bin/env python
2
-
2
+from os import environ
3 3
 import logging
4 4
 
5 5
 FORMAT = '[%(asctime)s][%(levelname)s][%(name)s][%(funcName)s](l.%(lineno)d) %(message)s'
6 6
 logging.basicConfig(
7 7
     format=FORMAT,
8
-    level=logging.DEBUG)
8
+    level=environ.get('LOGLEVEL', logging.INFO))
9 9
 logger = None
10 10
 
11 11
 def logger_init():
12
-    if 'logger' not in locals() or not logger:
13
-        logger = logging.getLogger('pyheatpump')
12
+    global logger
13
+    flag = not logger
14
+    logger = logging.getLogger('pyheatpump')
15
+    if flag:
14 16
         logger.info('Initialized pyHeatpump')
17
+    return logger
15 18
 
16 19
 if __name__ == '__main__':
17 20
     logger_init()

+ 10
- 1
pyheatpump/models/variable_value.py View File

@@ -4,6 +4,9 @@ from datetime import datetime
4 4
 from pprint import pprint
5 5
 
6 6
 from .variable_type import VariableType
7
+from pyheatpump.logger import logger_init
8
+
9
+logger = logger_init()
7 10
 
8 11
 class VariableValue(RowClass):
9 12
     type: VariableType = None
@@ -12,12 +15,18 @@ class VariableValue(RowClass):
12 15
     value: int = None
13 16
 
14 17
     def __init__(self, **kwargs):
18
+        logger.debug("""Create VariableValue object with attributes\n
19
+        :type:{}
20
+        :address:{}
21
+        :value:{}""".format(*kwargs.values()))
15 22
         if 'type' in kwargs.keys() and type(kwargs['type']) != VariableType:
16 23
             kwargs['type'] = VariableType.get(kwargs['type'])
17 24
 
25
+
18 26
         super().__init__(**kwargs)
19 27
 
20 28
     def insert(self):
29
+
21 30
         try:
22 31
             sql(
23 32
             """
@@ -26,7 +35,7 @@ class VariableValue(RowClass):
26 35
             VALUES
27 36
             ('{}', {}, {})
28 37
             """.format(
29
-                self.type, self.address, self.vaule
38
+                self.type, self.address, self.value
30 39
             ))
31 40
             return True
32 41
         except Exception as e:

Loading…
Cancel
Save