Browse Source

Now HttpException logs with lodel.logger

Yann Weber 8 years ago
parent
commit
dd9f017b98
1 changed files with 22 additions and 0 deletions
  1. 22
    0
      lodel/plugins/webui/exceptions.py

+ 22
- 0
lodel/plugins/webui/exceptions.py View File

1
 #-*- coding: utf-8 -*-
1
 #-*- coding: utf-8 -*-
2
 
2
 
3
 from werkzeug.wrappers import Response
3
 from werkzeug.wrappers import Response
4
+from lodel.context import LodelContext
4
 
5
 
5
 class HttpException(Exception):
6
 class HttpException(Exception):
6
 
7
 
23
         self.status_code = status_code
24
         self.status_code = status_code
24
         self.tpl = tpl
25
         self.tpl = tpl
25
         self.custom = custom
26
         self.custom = custom
27
+    
28
+    ##@brief Log exception with lodel logger
29
+    def log(self):
30
+        LodelContext.expose_modules(globals(), {'lodel.logger': 'logger'})
31
+        msg = "Webui HTTP exception : %s" % self
32
+        if self.status_code / 100 == 4:
33
+            logger.security(msg)
34
+        elif self.status_code / 100 == 5:
35
+            logger.error(msg)
36
+        else:
37
+            logger.warning(msg)
38
+    
39
+    def __str__(self):
40
+        return "HTTP:%d '%s'" % (self.status_code, self.custom)
26
 
41
 
27
     def render(self, request):
42
     def render(self, request):
43
+        self.log()
28
         from .interface.template.loader import TemplateLoader
44
         from .interface.template.loader import TemplateLoader
29
         loader = TemplateLoader()
45
         loader = TemplateLoader()
30
         tpl_vars = {
46
         tpl_vars = {
55
             custom = title)
71
             custom = title)
56
         self.errors = errors
72
         self.errors = errors
57
 
73
 
74
+    def __str__(self):
75
+        ret = super().__str__()
76
+        ret += ', '.join([ '%s: %s' % val for val in self.errors.items()])
77
+        return ret
78
+
58
     def render(self, request):
79
     def render(self, request):
80
+        self.log()
59
         from .interface.template.loader import TemplateLoader
81
         from .interface.template.loader import TemplateLoader
60
         loader = TemplateLoader()
82
         loader = TemplateLoader()
61
         tpl_vars = {
83
         tpl_vars = {

Loading…
Cancel
Save