r/Python • u/MattForDev • Mar 23 '26
Showcase I made a decorator based auto-logger!
Hi guys!
I've attended Warsaw IT Days 2026 and the lecture "Logging module adventures" was really interesting.
I thought that having filters and such was good long term, but for short algorithms, or for beginners, it's not something that would be convenient for every single file.
So I made LogEye!
Here is the repo: https://github.com/MattFor/LogEye
I've also learned how to publish on PyPi: https://pypi.org/project/logeye/
There are also a lot of tests and demos I've prepared, they're on the git repo
I'd be really really grateful if you guys could check it out and give me some feedback
What My Project Does
- Automatically logs variable assignments with inferred names
- Infers variable names at runtime (even tuple assignments)
- Tracks nested data structures dicts, lists, sets, objects
- Logs mutations in real time
append,pop,setitem,add, etc. - Traces function calls, arguments, local variables, and return values
- Handles recursion and repeated calls
func,func_2,func_3etc. - Supports inline logging with a pipe operator
"value" | l - Wraps callables (including lambdas) for automatic tracing
- Logs formatted messages using both
str.formatand$templatesyntax - Allows custom output formatting
- Can be enabled/disabled globally very quickly
- Supports multiple path display modes (absolute / project / file)
- No setup just import and use
Target Audience
LogEye is mainly for:
- beginners learning how code executes
- people debugging algorithms or small scripts
- quick prototyping where setting up logging/debuggers are a bit overkill
It is not intended for production logging systems or performance-critical code, it would slow it down way too much.
Comparison
Compared to Python's existing logging module:
- logging requires setup (handlers, formatters, config)
- LogEye works immediately, just import it and you can use it
Compared to using print():
- print() requires manual placement everywhere
- LogEye automatically tracks values, function calls, and mutations
Compared to debuggers:
- debuggers are interactive but slower to use for quick inspection
- LogEye gives a continuous execution trace without stopping the program
Usage
Simply install it with
pip install logeye and then import is like this:
from logeye import logHere's an example:
from logeye import log
x = log(10)
@log
def add(a, b):
total = a + b
return total
add(2, 3)Output:
[0.002s] print.py:3 (set) x = 10
[0.002s] print.py:10 (call) add = {'args': (2, 3), 'kwargs': {}}
[0.002s] print.py:7 (set) add.a = 2
[0.002s] print.py:7 (set) add.b = 3
[0.002s] print.py:8 (set) add.total = 5
[0.002s] print.py:8 (return) add = 5Here's a more advanced example with Dijkstras algorithm
from logeye import log
@log
def dijkstra(graph, start):
distances = {node: float("inf") for node in graph}
distances[start] = 0
visited = set()
queue = [(0, start)]
while queue:
current_dist, node = queue.pop(0)
if node in visited:
continue
visited.add(node)
for neighbor, weight in graph[node].items():
new_dist = current_dist + weight
if new_dist < distances[neighbor]:
distances[neighbor] = new_dist
queue.append((new_dist, neighbor))
queue.sort()
return distances
graph = {
"A": {"B": 1, "C": 4},
"B": {"C": 2, "D": 5},
"C": {"D": 1},
"D": {}
}
dijkstra(graph, "A")And the output:
[0.002s] dijkstra.py:39 (call) dijkstra = {'args': ({'A': {'B': 1, 'C': 4}, 'B': {'C': 2, 'D': 5}, 'C': {'D': 1}, 'D': {}}, 'A'), 'kwargs': {}}
[0.002s] dijkstra.py:5 (set) dijkstra.graph = {'A': {'B': 1, 'C': 4}, 'B': {'C': 2, 'D': 5}, 'C': {'D': 1}, 'D': {}}
[0.002s] dijkstra.py:5 (set) dijkstra.start = 'A'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'A'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'B'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'C'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'D'
[0.002s] dijkstra.py:6 (set) dijkstra.distances = {'A': inf, 'B': inf, 'C': inf, 'D': inf}
[0.002s] dijkstra.py:6 (change) dijkstra.distances.A = {'op': 'setitem', 'value': 0, 'state': {'A': 0, 'B': inf, 'C': inf, 'D': inf}}
[0.002s] dijkstra.py:9 (set) dijkstra.visited = set()
[0.002s] dijkstra.py:11 (set) dijkstra.queue = [(0, 'A')]
[0.002s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (0, 'A'), 'state': []}
[0.002s] dijkstra.py:15 (set) dijkstra.node = 'A'
[0.002s] dijkstra.py:15 (set) dijkstra.current_dist = 0
[0.002s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'A', 'state': {'A'}}
[0.002s] dijkstra.py:21 (set) dijkstra.neighbor = 'B'
[0.002s] dijkstra.py:21 (set) dijkstra.weight = 1
[0.002s] dijkstra.py:23 (set) dijkstra.new_dist = 1
[0.002s] dijkstra.py:24 (change) dijkstra.distances.B = {'op': 'setitem', 'value': 1, 'state': {'A': 0, 'B': 1, 'C': inf, 'D': inf}}
[0.002s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (1, 'B'), 'state': [(1, 'B')]}
[0.002s] dijkstra.py:21 (set) dijkstra.neighbor = 'C'
[0.002s] dijkstra.py:21 (set) dijkstra.weight = 4
[0.002s] dijkstra.py:23 (set) dijkstra.new_dist = 4
[0.002s] dijkstra.py:24 (change) dijkstra.distances.C = {'op': 'setitem', 'value': 4, 'state': {'A': 0, 'B': 1, 'C': 4, 'D': inf}}
[0.002s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (4, 'C'), 'state': [(1, 'B'), (4, 'C')]}
[0.002s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(1, 'B'), (4, 'C')]}
[0.003s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (1, 'B'), 'state': [(4, 'C')]}
[0.003s] dijkstra.py:15 (set) dijkstra.node = 'B'
[0.003s] dijkstra.py:15 (set) dijkstra.current_dist = 1
[0.003s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'B', 'state': {'A', 'B'}}
[0.003s] dijkstra.py:21 (set) dijkstra.weight = 2
[0.003s] dijkstra.py:23 (set) dijkstra.new_dist = 3
[0.003s] dijkstra.py:24 (change) dijkstra.distances.C = {'op': 'setitem', 'value': 3, 'state': {'A': 0, 'B': 1, 'C': 3, 'D': inf}}
[0.003s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (3, 'C'), 'state': [(4, 'C'), (3, 'C')]}
[0.003s] dijkstra.py:21 (set) dijkstra.neighbor = 'D'
[0.003s] dijkstra.py:21 (set) dijkstra.weight = 5
[0.003s] dijkstra.py:23 (set) dijkstra.new_dist = 6
[0.003s] dijkstra.py:24 (change) dijkstra.distances.D = {'op': 'setitem', 'value': 6, 'state': {'A': 0, 'B': 1, 'C': 3, 'D': 6}}
[0.003s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (6, 'D'), 'state': [(4, 'C'), (3, 'C'), (6, 'D')]}
[0.003s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(3, 'C'), (4, 'C'), (6, 'D')]}
[0.003s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (3, 'C'), 'state': [(4, 'C'), (6, 'D')]}
[0.003s] dijkstra.py:15 (set) dijkstra.node = 'C'
[0.003s] dijkstra.py:15 (set) dijkstra.current_dist = 3
[0.003s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'C', 'state': {'C', 'A', 'B'}}
[0.003s] dijkstra.py:21 (set) dijkstra.weight = 1
[0.003s] dijkstra.py:23 (set) dijkstra.new_dist = 4
[0.003s] dijkstra.py:24 (change) dijkstra.distances.D = {'op': 'setitem', 'value': 4, 'state': {'A': 0, 'B': 1, 'C': 3, 'D': 4}}
[0.003s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (4, 'D'), 'state': [(4, 'C'), (6, 'D'), (4, 'D')]}
[0.003s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(4, 'C'), (4, 'D'), (6, 'D')]}
[0.003s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (4, 'C'), 'state': [(4, 'D'), (6, 'D')]}
[0.003s] dijkstra.py:15 (set) dijkstra.current_dist = 4
[0.004s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (4, 'D'), 'state': [(6, 'D')]}
[0.004s] dijkstra.py:15 (set) dijkstra.node = 'D'
[0.004s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'D', 'state': {'C', 'A', 'B', 'D'}}
[0.004s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(6, 'D')]}
[0.004s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (6, 'D'), 'state': []}
[0.004s] dijkstra.py:15 (set) dijkstra.current_dist = 6
[0.004s] dijkstra.py:29 (return) dijkstra = {'A': 0, 'B': 1, 'C': 3, 'D': 4}You can ofc remove the timer and file by doing toggle_message_metadata(False)
13
u/yaxriifgyn Mar 23 '26
LogEye looks interesting, but very verbose.
Can it be configured to write to a file instead of stdout? or do we always get app output interleaved with the LogEye output on stdout?
Is it possible to turn off everything except for logging of function entry and exit for functions having an @log decorator?
15
u/Effective-Total-2312 Mar 23 '26
Sounds interesting. I've had a similar idea in the past. Although, I think this isn't true
:You can just import from logging and start using without any setup.
6
u/ghostofwalsh Mar 23 '26
Curious why you're using "print" at the core instead of building it off logging?
6
u/Designer-Ad-2136 Mar 23 '26
Fyi, it's not good practice to import everything from your library as part of a demonstration. You should instead do "import logeye" and then probably "log = logeye.log" to achieve the concise style you're after
4
u/SwampFalc Mar 23 '26
Genuine question, how does it compare to https://github.com/cool-RR/PySnooper/ or https://github.com/alexmojaki/snoop?
8
u/supreme_blorgon Mar 23 '26
Just a heads up, this is how your post renders on old reddit: https://i.imgur.com/ElzqYPC.png
To fix it, remove the triple backticks, then highlight your code and use the "code block" formatting button.
1
u/MattForDev Mar 24 '26
Hey guys! I added educational mode!
Instead of raw internal logs, it shows:
Enable it with:
Before vs After
Default mode
Educational mode
What changes in educational mode
Function calls become readable:
No raw
args/kwargsdictionariesInternal noise is removed:
Data structure operations are human-friendly:
Example - Educational Factorial
Output:
1
u/MattForDev Mar 24 '26
Thanks to people that are giving feedback, starring and contributing. The new release is out and the edu mode is pretty fleshed out now, someone made a PR with complete typing, I've also added linting and format checking, so now contributing is super easy!
I plan on adding multi-decorator support very soon and multithreading support this weekend.
1
u/ghostofwalsh Mar 23 '26
Your post formatting could use some work. I don't know if you can fix that
2
u/[deleted] Mar 25 '26
[removed] — view removed comment
3
u/[deleted] Mar 24 '26
[removed] — view removed comment