Skip to content

Commit 9a998f9

Browse files
committed
Tiny FAQ.
1 parent 64bab3c commit 9a998f9

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

README.md

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,52 @@ INFO:≫ Call: __main__.add(5, 5)
2323
INFO:≪ Call done: __main__.add() took 0.00ms: 10
2424
```
2525

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).
2929

3030
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.
3233

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.
3738

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

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+
4072
## Options
4173

4274
The `log_calls()` decorator is simple with reasonable defaults but is also fully
@@ -64,14 +96,6 @@ custom `log_func` to override that.
6496
Also by default, it shows values using `quote_if_needed()`, which is brief and very
6597
readable. You can pass in a custom `repr_func` to change that.
6698

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-
7599
## Usage
76100

77101
Here is a more complex example with tallies:

0 commit comments

Comments
 (0)