Skip to content

Commit d997eef

Browse files
committed
Update readme.
1 parent 9df4806 commit d997eef

File tree

2 files changed

+63
-18
lines changed

2 files changed

+63
-18
lines changed

README.md

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
11
# funlog
22

3-
`funlog` is a tiny but useful package that offers a few Python decorators to log
4-
function calls, with good control over what gets logged and when.
3+
`funlog` is a tiny but useful package that offers a few Python decorators to log or
4+
tally function calls, with good control over what gets logged and when.
5+
6+
## Why Decorator Logging?
57

68
We all do quick print debugging sometimes.
7-
Sometimes this is via log statements or other times simply with print(). Logging
8-
decorators are a nice compromise between the simplicity of print debugging with more
9-
complex or careful log statements.
9+
Sometimes this is via log statements or other times simply with `print()`.
10+
11+
Logging decorators are a nice compromise between the simplicity of print debugging with
12+
more complex or careful log statements:
13+
14+
```python
15+
@log_calls()
16+
def add(a, b):
17+
return a + b
18+
```
19+
20+
Then in the logs you will have:
21+
```
22+
INFO:≫ Call: __main__.add(5, 5)
23+
INFO:≪ Call done: __main__.add() took 0.00ms: 10
24+
```
25+
26+
In addition to logging function calls, `funlog` decorators also time the function call
27+
and can log arguments briefly but clearly, abbreviating arguments like long strings or
28+
dataclasses.
29+
30+
The decorator is simple with reasonable defaults but is also fully customizable with
31+
optional arguments to the decorator.
32+
You can control whether to show arg values and return values:
33+
34+
- `show_args` to log the function arguments (truncating at `truncate_length`)
35+
36+
- `show_return_value` to log the return value (truncating at `truncate_length`)
37+
38+
By default both calls and returns are logged, but this is also customizable:
39+
40+
- `show_calls_only=True` to log only calls
41+
42+
- `show_returns_only=True` to log only returns
43+
44+
- `show_timing_only=True` only logs the timing of the call very briefly
45+
46+
If `if_slower_than_sec` is set, only log calls that take longer than that number of
47+
seconds.
48+
49+
By default, uses standard logging with the given `level`, but you can pass in a custom
50+
`log_func` to override that.
1051

11-
In addition to logging function calls, `funlog` also times the function call and logs
12-
arguments briefly but clearly, abbreviating arguments like long strings or dataclasses.
52+
By default, it shows values using `quote_if_needed()`, which is brief and very readable.
53+
You can pass in a custom `repr_func` to change that.
1354

14-
The decorator is simple but fully customizable with optional arguments.
15-
You can log only slow calls, log only calls or only returns or only call timings, or
16-
tally calls and log them later.
55+
I'm publishing it standalone since I have found over the years I frequently want to drop
56+
it into projects. It's often even easier to use than quick print debugging.
1757

18-
I'm publishing it standalone since I often like to drop this into projects.
19-
It's often even faster than quick print-debugging and it lets you do very lightweight
20-
profiling by getting when certain functions are taking a lot of time and tallies of
21-
function calls and runtimes per function after a program runs a while or at exit.
58+
It also lets you do very lightweight profiling by having warnings in production when
59+
certain functions are taking a lot of time.
60+
Finally, is easy to get tallies of function calls and runtimes per function after a
61+
program runs a while or at exit.
2262

2363
It deliberately has **zero dependencies** and is a single file with ~500 lines of code.
2464

src/funlog/funlog.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ def log_calls(
249249
Decorator to log function calls and returns and time taken, with optional display of
250250
arguments and return values.
251251
252-
You can control whether to show arg values and return values with `show_args` and
253-
`show_return_value` (truncating at `truncate_length`).
252+
You can control whether to show arg values and return values:
253+
254+
- `show_args` to show the function arguments (truncating at `truncate_length`)
255+
- `show_return_value` to show the return value (truncating at `truncate_length`)
254256
255257
By default both calls and returns are logged, but this is also customizable:
256258
@@ -261,8 +263,11 @@ def log_calls(
261263
If `if_slower_than_sec` is set, only log calls that take longer than that number of
262264
seconds.
263265
264-
By default, uses standard logging with the given `level`, but you can pass in a a custom
265-
`log_func` to override that. By default shows values using `quot
266+
By default, uses standard logging with the given `level`, but you can pass in a custom
267+
`log_func` to override that.
268+
269+
By default, it shows values using `quote_if_needed()`, which is brief and very readable.
270+
You can pass in a custom `repr_func` to change that.
266271
"""
267272

268273
def to_str(value: Any) -> str:

0 commit comments

Comments
 (0)