10 ms·
My favorite use-case for AI is writing logs
- cosmicgadget 1y agoAutomates a tedious, time-consuming task. Easy to catch and correct failures. Love it. My only concern is (other than maybe verbosity) is of my log writing moments are opportunities to briefly reflect on what I have written, and maybe catch problems early.
- specproc 1y agoYeah, the areas AI has provided real value to me are the simple things: logging, docstrings and cli stuff being the best examples. I can throw up a basic sketch, focusing on the code, and get it to add the quality stuff after.
- interroboink 1y agoThe thing I like here is that it runs locally. I use Vim keyword completion[1] a lot for next-word completion. It does a broadly similar sort of "look at surrounding code to offer good suggestions" thing (no LLM stuff, of course). It's wrong often, but it's useful enough that it saves me time overall, I feel. So, this sounds to me like an expanded version of that, more or less. I think I'd prefer an AI future with lots of little focused models running locally like this rather than the "über models in the cloud" approach. Or at least having such options is nice. [1] https://vim.fandom.com/wiki/Any_word_completion https://vim.fandom.com/wiki/Any_word_completion There's also omni-completion, a bit more advanced: https://vim.fandom.com/wiki/Omni_completion https://vim.fandom.com/wiki/Omni_completion
- spiralcoaster 1y ago> The amount of cognitive overhead in this deceptively simple log is several levels deep: you have to first stop to type logger.info (or is it logging.info? I use both loguru and logger depending on the codebase and end up always getting the two confused.) Then, the parentheses, the f-string itself, and then the variables in brackets. Now, was it your_variable or your_variable_with_edits from five lines up? And what’s the syntax for accessing a subset of df.head again? What you're describing is called: programming. This can't be serious. What about the cognitive overhead of writing a for loop? You have to remember what's in the array you're iterating over, how that array interacts with maybe other parts of the code base, and oh man, what about those pesky indices! Does it start at 0 or 1? I can't take it! AI save me!
- BoiledCabbage 1y ago> What you're describing is called: programming. Is that the part of programming that you enjoy? Remembering logger vs logging? For me I enjoyed the technical chalenges, the design, solving customer problems all of that. But in the end, focus on the parts you love.
- okayishdefaults 1y agoThis is a sign that the user hasn't taken the time to set up their tools. You should be able to type log and have it tab complete because your editor should be aware of the context you're in. You don't need a fuzzy problem solver to solve non-fuzzy problems.
- bitpush 1y ago> user hasn't taken the time to set up their tools The user, infact, has setup a tool for the task - an "AI model", unless you're saying one tool is better than others.
- deleted 1y ago[deleted]
- sodality2 1y agoThen it's a real bad case of using the LLM hammer thinking everything is a nail. If you're truly using transformer inference to auto fill variables when your LSP could do that with orders of magnitude less power usage, 100% success rate (given it's parsed the source tree and knows exactly what variables exist, etc), I'd argue that that tool is better. Of course LLMs can do a lot more than variable autocomplete. But all of the examples given are things that are removing cognitive overhead that probably won't exist after a little practice doing it yourself.
- chrisweekly 1y agoThis. Set up your dev env and pay attention to details and get it right. Introducing probabilistic codegen before doing that is asking for trouble before you even really get started accruing tech debt.
- cratermoon 1y agoAOP solved this 30 years ago, though.
- nvader 1y agoI'd like to consult the HN hive mind on an tangential point. Does anyone else here dislike loguru on appearance? I don't have a well-articulated argument for why I don't like it, but it subconsciously feels like a tool that is not sharp enough. Was looking for evidence, either way, honestly. The author is using loguru here and I've run into it for a number of production deployments. Anyone have experiences to share?
- nxpnsv 1y agoIt looks great out of the box, has fancy colors (if you want them). It is easier to configure than logging and you don't need a lot go get_logger stuff. It does log rotation, and you has lazy formatted {} comments `logger.info("x={x:.2f}", x)`. It is better for threading/multiproc, handles exceptions better. And it is fast. I like it on appearance.
- alanbernstein 1y agoNever heard of it before this, but it looks nice. Some tools are better ergonomic than sharp?
- deleted 1y ago[deleted]
- greatgib 1y agoLoguru sucks very badly! I would advise you not to use it. It is like trying to not do like everyone else, but still doing in a terribly wrong way ... For example the backtrace try to be cooler for display but are awful, and totally not appropriate to pipe in monitoring systems like Sentry. In the same way, as you can see in the article, that is the only logging library that doesn't accept the standard %-string syntax to use instead its own shitty syntax based on format.
- nxpnsv 1y agoThe {} syntax is better, and more similar to f-strings. And you don't have to use that backtrace. I use it to send json for some batch jobs, or have it write to google cloud logger for gcp jobs. Are you holding it wrong?
- greatgib 1y agoIt's totally subjective that it is better. It's not like it can "execute code" inline like f-string. Just the replacement character is the same, end of the comparison. And any way the point is that more that it totally breaks the general convention for no valid reason. It's not even optional. For gcp jobs you can just output the structured log in the standard output so I don't see the purpose here. There are other structured logging libraries if this is what you need. For the backtrace yes, because logging.exception will be broken by default and all tools that process the backtrace automatically like sentry. And again, for no valid reason except than "look, my traceback looks so much cooler on my screen because I added crap and new lines when printing it"...
- nxpnsv 1y agoI don’t care too much about % vs {} . I have stuff where i need nice logs locally, and structured logs in batch, for me loguru made that easy. I don’t think it’s a terrible thing at all, but you do you :)
- spencer-p 1y agoI appreciate how the author highlighted the python domain-specific tricks like dropping imports and rewriting tabs/spaces. It's good to be reminded that even with "large" language models you can get better results with quality over quantity.
- lblume 1y agoFrom how I read it dropping imports happens for every language.
- arscan 1y agoAn aside, but it’s quite unfortunate that logger.info and logging.info are automatically linkified because of the .info TLD in this case. I don’t recommend clicking on those links.
- Spivak 1y agoPython programmers, don't use f-strings for your logs. # yes logger.info("Super log %s", var) # no logger.info(f"Super log {var}") I know, it's not as nice looking. But the advantage is that the logging system knows that regardless of what values var takes that it's the same log. This is used by Sentry to aggregate the same logs together. Also if the variable being logged also happens to contain a %s then the f-string version will throw an exception. It doesn't matter because f-strings are so fast but the % method is also lazy and doesn't interpolate/format if it's not going to be logged. Maybe in the future we'll get to use template strings for this.
- bbkane 1y agoThanks for the reasons! I've been using f-strings because they're easy to keep track of, but you make really good arguments (I hadn't thought of Sentry/similar systems using %s to aggregate logs)
- nxpnsv 1y agoWell if you use loguru (and really you should, it is awesome) you would use, `logger.info("Super log {var}", var=var)` (possibly without the keys). It is also lazy and works better for structured logs.
- suriya-ganesh 1y agoThis tracks with how I've been doing my debug logs. I ask the model to create tons of logs for a specific function and make sure there's an emoji in the beginning to make it unique (I know HN hates emojis). Best thing of all, I can just say delete all logs with emojis and my patch is ready. Magical usage of LLMs
- Disposal8433 1y agoDo you use a debugger?
- suriya-ganesh 1y agoI do, but logs are better.
- Guid_NewGuid 1y agoThe use of AI for this seems somewhat overkill, one could just use a language and environment that is aware of whether `logger` or `logging` is available, and what variables are in scope. We have tools that allow us to treat programming as more than guessing the next character at random. Rather they allow you to offload tracking this context to the machine in a reliable way, typed languages and auto complete. I do wonder if this is part of the divide in how useful one finds LLMs currently. If you're already using languages which can tell you what expressions are syntactically valid while you type rather than blowing up at runtime the idea a computer can take some of the cognitive overhead is less novel.
- gbalduzzi 1y agoI think we are overcomplicating this a bit. Typing "log" and tab to accept the auto complete is faster than writing the whole log yourself. When you need to add a bunch of log statement, this tool makes the activity faster and less tedious. Is it a technological breakthrough? No Does it save hours of developer time each day? No Is it nice to have? Hell yeah
- fudged71 1y agoTangential, but making the logs understandable by the LLM is also very useful
- TZubiri 1y agoI once wrote a simple python program that logged all execution, self inspected code and printed code and variables as output. Then I learned why programs don't do that by default. Not to be snarky, but when you become more experienced you will figure out that logging is just writing to permanent storage, one of the most basic blocks of programming, you don't need a dependency for that, writing to disk should be as natural as breathing air, you can do print("var",var). That's it. If you are really anal you can force writing to a file with a print argument or just a posix open and write call. No magic, no remembering, no blogpost. Just done, and next.
- whyenot 1y ago> My favorite use-case for AI is writing logs You mean like this? [2025-07-17 18:05] Pallet #3027 stacked: Coast‐live oak, 16" splits, 0.22 cord. [2025-07-17 18:18] Moisture check → 14 % (prime burning condition). [2025-07-17 18:34] Special request tagged: “Larina—aromatic madrone, please!” [2025-07-17 18:59] Squirrel incident logged: one (1) cheeky Sciurus griseus absconded with wedge. ...or something more like this? Base-10 (log10) handy values -------------------------------- x log10(x) ------------------ 2 0.3010 e 0.4343 10 1.0000 42 1.6232 1000 3.0000 1e6 6.0000
- spapas82 1y agoThis is interesting, I like the way jetbrains is using the local models for auto completion. Do you know if there's a similar solution for vscode?
- andutu 1y agoOn the one hand writing logs can be tedious. Essentially logs are breadcrumbs signifying when significant state changes have logically taken place. From what I've seen, logs are added after every few lines and I always fantasized about creating a language where logging is "automatic". On the other hand, writing logs is a skill worth mastering. Wrote too many and when a service crashes you have to shift through lots of noise and potentially miss the signal. I once went down a rabbit hole trying to root cause an issue in a Gunicorn application that had custom health check logic in it. An admin worker would read health check state from a file that worker threads wrote to. Sometimes a race condition would occur, in which an error log would be emitted. The thing was, this error wasn't fatal and was a red herring for why the service actually crashed. Of instead it would have been logged at the debug level a lot of time would have been saved. Fine let LLMs write code but take logging seriously!!!
- physicles 1y agoTab autocomplete in Cursor is surprisingly good at guessing what I want to log when I type slog.Info. I’m enjoying that time save. I agree with K&R about debuggers: when writing services that you need to debug in prod, you live and die by your logs. That said, sometimes an interactive debugger is faster than adding logs, like when you’re not sure about the precise call stack that leads to a given point, or there’s a bunch of stuff you need to keep track of and adding logs for all of it is tedious. But pretty quickly you can hit a point where you’re wasting more time in the debugger than it would’ve taken to add those logs…
- nxpnsv 1y agoIt does well but also sometimes gets it completely wrong but plausible looking. Together, we managed to make several quite intricate bugs. About two months in, I actually don't think my coding speed increased much from using Cursor - and I just can't take "Perfect, ..." "You're absolutley right, ..." - even with custom rules to supress it, it just can't help itself.
- Animats 1y agoUsually, people use AI for reading logs, looking for interesting events or patterns. That goes way back. Microsoft was using it to classify and group similar crash dumps back in the 1990s. Rust lets you write a default debug print for each struct, and will generate one if asked. So you don't have to write out all the fields yourself. That's enough to do the annoying part of the job.
- djmips 1y agoMicrosoft was using 'AI' in the 90s?
- badsectoracula 1y agoAI and ML aren't new, they were already well established by the 90s. For example the book from which i first learned about neural networks[0] was written in 1997. [0] https://www.cs.cmu.edu/~tom/mlbook.html https://www.cs.cmu.edu/~tom/mlbook.html
- Animats 1y agoClassifiers go back that far.
- closewith 1y agoExpert systems and decision trees were AI in the '90s. Remember, it's only AI until it works.
- MrStonedOne 1y ago[dead]
- neuroelectron 1y agoAn example of the output would be very helpful
- swiftcoder 1y agoProgrammer apparently never learned about "import ... as" syntax, adopts fuzzy LLM autocomplete instead. News at 11
- swiftcoder 1y agoAnd look... I do get it. I have to switch between rust/typescript/python on the regular, and 3x sets of quirky syntax is a lot to keep in working memory. I'd rather simplify our software stacks than accept that an autocomplete that lies to me is the only tractable solution, though
- MagicMoonlight 1y agoI thought this was going to be about an AI which actually writes useful logs for your program. Eg if it crashes, it explains in normal language what happened.
- pandemic_region 1y ago> I’ve been a happy JetBrains customer for a long time now, and it’s because they ship features like this. The Goland and Pycharm experience must be radically different from the Java experience then.
- voidUpdate 1y agoVisual studio added the single line autocomplete thing a while back and it lasted about 2 days before i turned it off because it was frequently wrong and just got in the way. I often use the double tab template insert feature, but that would often accept the incorrect autocomplete instead, so i had to delete it and try again
- specproc 1y agoTotally agree, this behaviour is maddening. I set a hotkey to toggle completions, made it useful again.
- i_niks_86 1y agoCould full-line code completion and smarter log inference change how developers approach debugging and monitoring altogether? If so, how?
- andrelaszlo 1y agoI would have flagged that they're logging their Redis URL, if I was reviewing this. Most of the time this includes credentials. Normally I think it's a bit rude to criticize the code of blog posts, bit I thought it was relevant here for these reasons: "I often don’t even remove when I’m done debugging because they’re now valuable in prod" - think about where your production credentials end up. Most of the time, logging them won't hurt, just like keeping your password on a post-it doesn't hurt most of the time. The arguments about letting an AI reduce the mental overhead is compelling, but this shows one of the (often mentioned) risks: you didn't write it so you didn't consider the implications. Or maybe the author did consider it, and has a lot of good arguments for why logging it is perfectly safe. I often get pushback from other devs about stuff like this, for example: - We're the only ones with access to the logs (still, no reason to store credentials in the logs) - The Redis URL only has an IP, no credentials. (will we remember to update this log line when the settings.redis_url changes?) - We only log warnings or higher in production (same argument as above) Maybe I should stop worrying and learn to love AI? Human devs do the same thing, after all?
- BiteCode_dev 1y agoI have a /addlogs claude command just for that. Logging is mostly boiler plate, I'm glad I can outsource it.
- WhyNotHugo 1y agoYou should not use f-strings for logging, because that performs all the formatting _before_ the logging module determines if the log needs to be printed. You want the formatting overhead to happen only for logs that will get printed. You can’t achieve that with f-strings, just use normal logging calls. It kinda speaks bad of the auto-completion that it suggests such anti-pattern.
- HAMSHAMA 1y agoYou can do this with the new t strings! They’re like f strings, but a template instead. https://peps.python.org/pep-0750/ https://peps.python.org/pep-0750/
- mbanerjeepalmer 1y agoLLM-written code is typically over-commented and under-logged. So much so that I've given up pleading with them to stop commenting and start logging. Instead I say 'Great, now that you've written the code please replace the comments with logs.'
- yason 1y agoPeople, in their excitement to play with or write cool tools to automate boring details in the programming process, often underestimate the value of boring grunt work. While what you're doing consciously is something simple you're simultaneously also mucking about in your codebase in the "spinal cord level", or spending quality time with your creation. It's times like those when bigger/other things often click together the first time all the while you're doing something that's seemingly just grunt work.
- ButOneDuck 1y agoI get that writing logs can be incredibly frustrating, but most of the time people are looking at logs because either something went wrong, or they have a hunch that the program is misbehaving and they're looking for a clean sign or signal that they are on the right track. If I've spent multiple hours on someones broken piece of code, the last thing I want to be thinking is "did some non-deterministic chat-bot write this?", "are these logs even internally consistent?", "Why does this log mention code that doesn't exist?". I get that is most devs least favorite part, but logs and errors are supposed to be unshakable, ground-truth understandings, things that point you to the light in a dark room of broken spaghetti code and misunderstandings. Think about this from a users or a testers perspective, can you imagine the compounding frustration you would experience? To be chasing a skein of understanding through wall of text that you only mostly understand, to find out that the hunch was based on a red-herring by a dev who wasn't bothered to help you in return. Not to mention the amount of non-bugs you are generating for yourself in the future, we already have bug bounties being swarmed by LLM-gen faux-bugs, how is anyone supposed to reason about real bugs if the logs are only tangentially related to the truth?
- marcellus23 1y ago> "did some non-deterministic chat-bot write this?", "are these logs even internally consistent?", "Why does this log mention code that doesn't exist?". This is the same complaint about all AI-generated code, the simple answer to which is, review the code yourself before committing. Or if it's a real project, it'll get reviewed by someone else anyway, same as any other code that could have a mistake in it.