Mercurial > libervia-web
annotate src/browser/sat_browser/logging.py @ 995:f88325b56a6a
server: dynamic pages first draft:
/!\ new dependency: autobahn
This patch introduce server part of dynamic pages.
Dynamic pages use websockets to establish constant connection with a Libervia page, allowing to receive real time data or update it.
The feature is activated by specifying "dynamic = true" in the page.
Once activated, page can implement "on_data" method which will be called when data are sent by the page.
To send data the other way, the page can use request.sendData.
The new "registerSignal" method allows to use an "on_signal" method to be called each time given signal is received, with automatic (and optional) filtering on profile.
New renderPartial and renderAndUpdate method allow to append new HTML elements to the dynamic page.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 03 Jan 2018 01:10:12 +0100 |
parents | fd4eae654182 |
children | f2170536ba23 |
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 |
964
fd4eae654182
misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
5 # Copyright (C) 2011-2017 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 |