Mercurial > libervia-web
annotate browser/sat_browser/logging.py @ 1213:889e8d07e957 0.7.0
0.7.0 « La Commune » release
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 24 Jul 2019 20:43:11 +0200 |
parents | 2af117bfe6cc |
children |
rev | line source |
---|---|
440
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
1144 | 5 # Copyright (C) 2011-2019 Jérôme Poisson <goffi@goffi.org> |
440
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 """This module configure logs for Libervia browser side""" |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from __pyjamas__ import console |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from constants import Const as C |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
443
diff
changeset
|
23 from sat.core import log # XXX: we don't use core.log_config here to avoid the impossible imports in pyjamas |
440
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 class LiberviaLogger(log.Logger): |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 def out(self, message, level=None): |
497
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
29 try: |
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
30 console |
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
31 except: |
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
32 # XXX: for older Firefox version, the displayed error is "libervia_main ReferenceError: console is not defined" |
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
33 # but none of the following exception class is working: ReferenceError, TypeError, NameError, Exception... |
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
34 # it works when you don't explicit a class, tested with Firefox 3.0.4 |
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
35 print message |
516b06787c1a
browser_side: fix logging issue with older firefox version (e.g. 3.0.4)
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
36 return |
440
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 if level == C.LOG_LVL_DEBUG: |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 console.debug(message) |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 elif level == C.LOG_LVL_INFO: |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 console.info(message) |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 elif level == C.LOG_LVL_WARNING: |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 console.warn(message) |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 else: |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 console.error(message) |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 def configure(): |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 fmt = '[%(name)s] %(message)s' |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 log.configure(C.LOG_BACKEND_CUSTOM, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 logger_class = LiberviaLogger, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 level = C.LOG_LVL_DEBUG, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 fmt = fmt, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 output = None, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 logger = None, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 colors = False, |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 force_colors = False) |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 # FIXME: workaround for Pyjamas, need to be removed when Pyjamas is fixed |
88461e9c3e47
browser_side (log): move logging configuration in a "logging" module + use custom backend with console.debug/info/etc output.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 LiberviaLogger.fmt = fmt |