@@ -23,20 +23,52 @@ INFO:≫ Call: __main__.add(5, 5)
23
23
INFO:≪ Call done: __main__.add() took 0.00ms: 10
24
24
```
25
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 .
26
+ In addition to logging function calls, ` funlog ` decorators can log arguments briefly but
27
+ clearly, abbreviating arguments like long strings or dataclasses and also time the
28
+ function call (and logs it in a friendly way in milliseconds or seconds) .
29
29
30
30
I'm publishing it standalone since I have found over the years I frequently want to drop
31
- it into projects. It's often even easier to use than quick print debugging.
31
+ it into projects. It's often even easier to write than a quick print debugging statement
32
+ or a single log statement.
32
33
33
- In addition to logging calls, it lets you do very lightweight profiling by having
34
- warnings in production when certain functions are take more than a specified amount of
35
- time. Finally, you can use the decorators to get tallies of function calls and runtimes
36
- per function after a program runs a while or at exit.
34
+ In addition to logging calls, it lets you do * very* simple profiling by having warnings
35
+ in production when certain functions are take more than a specified amount of time.
36
+ Finally, you can use the decorators to get tallies of function calls and runtimes per
37
+ function after a program runs a while or at exit.
37
38
38
39
It deliberately has ** zero dependencies** and is a single file with ~ 500 lines of code.
39
40
41
+ ## Installation
42
+
43
+ Add the [ ` funlog ` ] ( https://pypi.org/project/funlog/ ) package to your environment in the
44
+ usual way with ` pip install funlog ` , ` poetry add funlog ` , or ` uv add funlog ` .
45
+
46
+ Or if for some reason you prefer not to change the dependencies of your project at all,
47
+ just copy the single file [ ` funlog.py ` ] ( /src/funlog/funlog.py ) .
48
+
49
+ ## Mini FAQ
50
+
51
+ - ** Isn't it better to do real logging?** It's not much different from regular logging;
52
+ think of these decorators as simply as a syntactic convenience.
53
+ The biggest benefit is it's less typing a log statement: it handles the name of the
54
+ function, the args and return values, etc and it also truncates values so large values
55
+ aren't logged by accident.
56
+
57
+ - ** Doesn't this create tons of spam in your logs?** This is no different from regular
58
+ logging. It only will if you use it on functions that are called a lot.
59
+ It tends to be useful either for higher-level functions (like making an LLM call that
60
+ takes a few seconds and consumes resources anyway) or with the ` if_slower_than_sec `
61
+ option so it only logs unexpectedly slow calls.
62
+
63
+ - ** Is this just a poor version of tracing?** The goal is to be as simple as possible,
64
+ even useful on little command-line apps.
65
+ If you're wanting proper visibility into function calls on production cloud-deployed
66
+ apps, you probably want something more powerful, like OpenTelemetry.
67
+
68
+ - ** What about when you only want to log sometimes, not on every call?** Probably just
69
+ use a regular log statement.
70
+ Or only log tallies or use the ` if_slower_than_sec ` option.
71
+
40
72
## Options
41
73
42
74
The ` log_calls() ` decorator is simple with reasonable defaults but is also fully
@@ -64,14 +96,6 @@ custom `log_func` to override that.
64
96
Also by default, it shows values using ` quote_if_needed() ` , which is brief and very
65
97
readable. You can pass in a custom ` repr_func ` to change that.
66
98
67
- ## Installation
68
-
69
- Add the [ ` funlog ` ] ( https://pypi.org/project/funlog/ ) package to your environment in the
70
- usual way with ` pip install funlog ` , ` poetry add funlog ` , or ` uv add funlog ` .
71
-
72
- Or if for some reason you prefer not to change the dependencies of your project at all,
73
- just copy the single file [ ` funlog.py ` ] ( /src/funlog/funlog.py ) .
74
-
75
99
## Usage
76
100
77
101
Here is a more complex example with tallies:
0 commit comments