Skip to content

Commit 0780ab6

Browse files
committed
📝 [Doc] README: update example with latest feature, and upgrade to v1.2.9
1 parent 287371a commit 0780ab6

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ python example.py
1919
See: [example.py](https://github.com/Hansimov/tclogger/blob/main/example.py)
2020

2121
```python
22-
import sys
23-
from pathlib import Path
24-
25-
sys.path.insert(0, str(Path(__file__).parent / "src"))
26-
2722
import tclogger
2823
import time
2924

3025
from datetime import timedelta
26+
from pathlib import Path
3127
from zoneinfo import ZoneInfo
3228

3329
from tclogger import TCLogger, logger, TCLogstr, logstr, colored, decolored
@@ -41,6 +37,7 @@ from tclogger import TCLogbar, TCLogbarGroup
4137
from tclogger import brk, brc, brp
4238
from tclogger import int_bits, max_key_len, chars_len
4339
from tclogger import chars_slice
40+
from tclogger import attrs_to_dict
4441

4542

4643
def test_logger_verbose():
@@ -332,6 +329,33 @@ def test_temp_indent():
332329
logger.mesg("no indent")
333330

334331

332+
def test_attrs_to_dict():
333+
logger.note("> Logging attrs of logger:")
334+
attrs_dict = attrs_to_dict(logger)
335+
logger.mesg(dict_to_str(attrs_dict), indent=2)
336+
337+
logger.note("> Logging attrs of example:")
338+
# a obj which allows to add attributes
339+
obj = type("AnyObject", (), {})()
340+
obj.dict_val = {
341+
"hello": "world",
342+
"now": get_now_str(),
343+
"list": [1, 2, 3, [4, 5], "6"],
344+
"nested": {"key1": "value1", "key2": "value2", "key_3": {"subkey": "subvalue"}},
345+
"中文Key": "中文Value",
346+
}
347+
obj.int_val = 12345
348+
obj.float_val = 3.0
349+
obj.bool_val = True
350+
obj.str_val = "Hello World"
351+
obj.none_val = None
352+
obj.list_val = [1, 2, 3, 4, 5]
353+
obj.list_dict_val = [{"k1": "v11", "k2": "v2"}, {"k1": "v21"}, {"k2": "v22"}]
354+
obj.tuple_val = (1, 2, 3, "4", {"5": 6})
355+
obj_attrs_dict = attrs_to_dict(obj)
356+
logger.mesg(dict_to_str(obj_attrs_dict), indent=2)
357+
358+
335359
if __name__ == "__main__":
336360
test_logger_verbose()
337361
test_run_timer_and_logger()
@@ -352,4 +376,5 @@ if __name__ == "__main__":
352376
test_math()
353377
test_str_slice()
354378
test_temp_indent()
379+
test_attrs_to_dict()
355380
```

example.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,25 +340,25 @@ def test_attrs_to_dict():
340340

341341

342342
if __name__ == "__main__":
343-
# test_logger_verbose()
344-
# test_run_timer_and_logger()
345-
# test_now_and_timezone()
346-
# test_dt_to_str()
347-
# test_color()
348-
# test_case_insensitive_dict()
349-
# test_dict_get_and_set()
350-
# test_dict_to_str()
351-
# test_align_dict_list()
352-
# test_list_of_dicts()
353-
# test_file_logger()
354-
# test_logbar()
355-
# test_logbar_group()
356-
# test_logbar_total()
357-
# test_logbar_verbose()
358-
# test_decorations()
359-
# test_math()
360-
# test_str_slice()
361-
# test_temp_indent()
343+
test_logger_verbose()
344+
test_run_timer_and_logger()
345+
test_now_and_timezone()
346+
test_dt_to_str()
347+
test_color()
348+
test_case_insensitive_dict()
349+
test_dict_get_and_set()
350+
test_dict_to_str()
351+
test_align_dict_list()
352+
test_list_of_dicts()
353+
test_file_logger()
354+
test_logbar()
355+
test_logbar_group()
356+
test_logbar_total()
357+
test_logbar_verbose()
358+
test_decorations()
359+
test_math()
360+
test_str_slice()
361+
test_temp_indent()
362362
test_attrs_to_dict()
363363

364364
# python example.py

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "tclogger"
3-
version = "1.2.8"
3+
version = "1.2.9"
44
authors = [
55
{ name="Hansimov" },
66
]

0 commit comments

Comments
 (0)