mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 03:05:38 -05:00
Improve JS logging (#743)
This PR tries to improve and rationalize what we log. Key points:
- introduce `logger.ts`: each file/component is encouraged to use the logger instead of writing directly to `console.*`
* the logger automatically prepend a prefix like `[py-config]`, `[py-env]` which make it easier to understand where a certain message is printed from
* it provide a central place where to add more features in the future. E.g., I can imagine having a config setting to completely silence the logs (not implemented yet)
- use the new loggers everywhere
- write to `.info()` instead of `.log()`. The idea is to keep `console.log` free, so that for the users it's easier to tell apart their own messages and the pyscript ones
- generally improve what we log. This is an endless exercise, but I tried to print more things which are useful to understand what's going on and in which order the various things are executed, and remove prints which were clearly debugging leftovers
This commit is contained in:
@@ -24,30 +24,30 @@ class TestBasic(PyScriptTest):
|
||||
Check that they py-script tags are executed in the same order they are
|
||||
defined
|
||||
"""
|
||||
# NOTE: this test relies on the fact that pyscript does not write
|
||||
# anything to console.info. If we start writing to info in the future,
|
||||
# we will probably need to tweak this test.
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>import js; js.console.info('one')</py-script>
|
||||
<py-script>js.console.info('two')</py-script>
|
||||
<py-script>js.console.info('three')</py-script>
|
||||
<py-script>js.console.info('four')</py-script>
|
||||
<py-script>import js; js.console.log('one')</py-script>
|
||||
<py-script>js.console.log('two')</py-script>
|
||||
<py-script>js.console.log('three')</py-script>
|
||||
<py-script>js.console.log('four')</py-script>
|
||||
"""
|
||||
)
|
||||
assert self.console.info.lines == ["one", "two", "three", "four"]
|
||||
assert self.console.log.lines == [
|
||||
self.PY_COMPLETE,
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
"four",
|
||||
]
|
||||
|
||||
def test_escaping_of_angle_brackets(self):
|
||||
"""
|
||||
Check that py-script tags escape angle brackets
|
||||
"""
|
||||
# NOTE: this test relies on the fact that pyscript does not write
|
||||
# anything to console.info. If we start writing to info in the future,
|
||||
# we will probably need to tweak this test.
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>import js; js.console.info(1<2, 1>2)</py-script>
|
||||
<py-script>js.console.info("<div></div>")</py-script>
|
||||
<py-script>import js; js.console.log(1<2, 1>2)</py-script>
|
||||
<py-script>js.console.log("<div></div>")</py-script>
|
||||
"""
|
||||
)
|
||||
assert self.console.info.lines == ["true false", "<div></div>"]
|
||||
assert self.console.log.lines == [self.PY_COMPLETE, "true false", "<div></div>"]
|
||||
|
||||
Reference in New Issue
Block a user