10 ms·
Do Not Log
- cr3ative 5y ago(2020). Not this article again. Observability is crucial in reducing time-to-resolution in incidents. I would much rather have to debug a chatty system than one which says nothing yet fails monitoring checks.
- hartator 5y agoIsn’t Sentry just fancy logging at the end of the day?
- deleted 5y ago[deleted]
- masklinn 5y agoAFAIK it's mostly intended as a way to generate tickets: hard errors go into sentry, and the logs can be used as breadcrumbs, but it's not intended to help you diagnose e.g. how and why a business process did something wrong (unless it ended up crashing I guess).
- nightpool 5y agoYes, ultimately I think that's the stronger underlying argument that the author fails to make clearly—when you log something, it needs to be in a machine-readable format so that you can aggregate that data and gain value from it, and you need a system set up to deal with it on the other end. For example, on Heroku I have access to the wonderful Librato log connector, which makes metrics as easy as `stdout.write("my-metric-name=#{whatever}")`. I would also call that a form of "fancy logging"—now my logs are automatically connected to a graphing and alerting system, with a very long retention period. Sentry is the same way—instead of logging something into the aether, you have structured data (the error payload) that's connected to a system that can bug you about errors and help you aggregate the common sources of failure. Unstructured logging can occasionally be useful, but most of the time it's just not much more than noise.
- goodpoint 5y agoWorse: unreliable in case of network issues. When you might need your logs the most.
- bob1029 5y agoOur approach is to accumulate logs on the grain of individual user work items - one SQLite database per. This has several benefits, the largest of which being that you only look at log files when a thing logically goes wrong, and every entry you see pertains to that exact activity. The other benefit is that these logs get purged at the same grain as the work items being cleaned up. Successful items are purged quickly, exception items can be kept perpetually. So, the implication for us is to log with a lot of verbosity with the expectation that we are probably never going to see any of it, but also with the knowledge that a ton of helpful debug lines will be available when it does all go wrong. Stack traces are not enough for us, we need to know exactly what communications occurred between us and external systems over time to figure out many issues. We do maintain a global log file, but this is mostly just service start/stop entries and other administrative actions.
- shadowgovt 5y agoThis basic philosophy looks very similar to Google's Dapper request tracing system. Since it's impossible to log every request at their scale, they have various scaling controls for dropping requests from the trace or summarizing them (which can be overridden when a trace goes exceptional).
- delusional 5y agoI've had this discussion at lot too. My basic argument always ends up boiling down to "Don't make the software do anything you don't have a use for". If you want to log something, you better have some sort of plan for how that line is going to be used, and a line in some stream somewhere has to be the best way to get that outcome. That's usually enough argument for people that I get to not have a logger statement in the catch. Frankly it's a religious thing. No one really wants to have the argument, and the best you can hope for is a sigh of defeat.
- deleted 5y ago[deleted]
- pryelluw 5y ago“Use better tools instead: like error and business monitorings with alerts” I don’t quite understand the alternatives. However, I do agree that logging is a side effect and should be done in specific ways. That does not mean that you should remove all of it. A little goes a long way.
- nimbius 5y agosort of related, but id say limited logging for things like fail2ban. youll need a rolling 24-72 hour window to identify threats at least...unless im missing something?
- einpoklum 5y agotl;dr: Mostly click-bait. ------- > I either want a quick notification about some critical error with everything inside, or I want nothing: a peaceful morning with tea and youtube videos. There’s nothing in between for logging. 1. No, there's lots in between. 2. You should be able set the log severity threshold, and hopefully the log verbosity threshold (e.g. with/without stack trace and other information). 3. We don't just log failures.
- rightbyte 5y ago> 3. We don't just log failures. Ye just log everything. You mostly don't know in advance where the error will be anyway. The author seem clueless. Don't log but use a Cloud $$$ SaaS for monitoring? Really? And then he goes on to argue that the code should just not fail. Like, "write good code".
- smikhanov 5y agoCorrect. The “try-catch-log” example from the article is so trivial that it can be used to support any argument really.
- kfsdfjdf 5y agoI have no idea what the authors qualifications are. There have been uncountable cases where a GOOD log trail has been the difference between a 20 hour journey through a code base and a short stop to immediately discovering the problem. Common failure points should be logged, especially when they are deeply nested, or they involve complex hard-to-diagnose processes. Overlogging is just as bad. But to say "do not log" and then suggest using services like sentry or datadog instead is really reaching around your nose to touch your face. You're doing yourself a disservice by lacking the final bit of correlation - the approximate location and nature of the failure. There have been times when I've been on a service so complex that just building a harness to reproduce the case takes hours or days. Not everything is a nice, clean, small and simple microservice where you only have N guesses at where the problem could originate. On a large enough, or old enough, service the upper bound could approach N! very quickly. I'm not sure why this was posted to HN as it seems like a very low-quality ranty post by someone whom I'm not sure has ever worked on a large enough project where it becomes non-obvious what the origin of some error alerts are.
- smikhanov 5y ago> what authors qualifications are The author is definitely not very qualified, yes.
- masklinn 5y ago> Overlogging is just as bad. It really is not: you can trim overlogging, you can't add missing logs. Now one thing I am very much in favor of, but which I didn't see anywhere in TFA, is the ability to dynamically instrument instances (add or remove log points). It's not necessarily easy to know what to log or not to log. With "normal" logging adding new log points is a complicated process (they're static so you have to introduce them, ensure they're correct, and then go through whatever deployment process you have), so there's a natural tendency to overlog because if you underlog you may miss critical information. In systems where the capability exists, instrumenting log points "from the outside" without having to update the program being observed is much better, not only does it let you refine your logging more easily, it also lets you brutally increase logging density (possibly locally) without downtime.
- bullen 5y agoI agree and push this to it's logical conclusion: logging is for development (test) only, on live I have everything hard routed to my mail, if something fails I'll know about it and be encouraged to fix it because I set it on a 24 hour reset. + Instead of wearing my SSDs down, it wears my mail providers. The real solution is to make both automated and manual feedback extremely easy, for example send crashdumps without asking and have a forum connected to the users account where you redirect the user upon a crash. Just like downgrading my GPU to a 1030, so I cannot play stupid games; this is a motivational trick to curb me into making things better! Apparently I'm also somewhat of a masochist.. :S
- fuzzy2 5y agoHow is using Sentry (or whatever) not adding complexity? How is Sentry not introducing side effects? How is using Sentry magically creating information about why a business operation failed? Does Sentry even know your business operation failed? It doesn’t, unless you tell it. How is Sentry not I/O-bound? (That’s right, they abstracted that away, like a good logging framework does, too.) In the end, to integrate Sentry and get actually useful information for monitoring, you have to do the same work you’d do for logging. Except now you’re tied to Sentry. Want some other service? Good luck. Do log. And then send the log messages to Sentry or whatever you’re using, too. Also, do overlog. It can be hard or impossible to attach a debugger to the deployed application. But you can always turn the log level up to 11 and then reconstruct what happened from the log messages.
- konschubert 5y agoI think what the post is trying to say is that you should let your exception bubble up. And then catch it at the highest level, including all the stack trace. And then maybe send it to sentry, or log it, put it on data dog. But don't catch exceptions all over your application code. I have a related mental model for this: When you crash, crash loudly.
- masklinn 5y agoThat, however, does not at all work when exceptions are part of the "normal" process and should be ignored or cleanly retried (having spent a while interacting with github, if you take the entire thing down every time github replies with an error and log that to sentry, your sentry instance will last all of 5mn before you have to declare bankruptcy or just plonk the alters and ignore everything). But in that case you probably still want to know about these failures, so you can review them from time to time, or see if there are upticks in failure frequency.
- Veuxdo 5y agoExceptions should not be normal by definition.
- jmartrican 5y agoOh i see you are logging exceptions caught in try/catch blocks... easy, remove the logging then just refactor that code to not have any exceptions by accounting for every possible situation. Then in 2 years when you are done, you can proceed to the other try/catch block.
- dj_mc_merlin 5y agoThis is inane. Logging has been a thing since the stone ages of software engineering. The first thing you do in any environment is set up a debug log of some kind. You can make as many error states unreachable as you can, but what the hell do you do when there's an error anyway? Psychically debug the process? edit: how are you going to communicate information as to why something crashed to your colleagues who do not understand certain parts of the system as well as you? A stack trace is not effective at expressing intent. Explaining yourself in logs helps people triage more efficiently.
- tantalor 5y ago> the second one is IO-bound impure one Not necessarily, e.g., you can buffer in memory, and write to storage later. > loggers can fail and break your app Anything can fail and break your app. Weak point.
- shadowgovt 5y agoI think the point is "logging isn't free" (in fact, that might make for a better title for the blog post). A lot of devs think of logging as free; it's easy, it's almost always something that's either global-scope or standard library, and it's the first obvious solution to inspect internal program state when the program misbehaves. But logs are a subsystem and adding any subsystem to your code increases your risk surface (for both crashes and privacy violations). Took an operating systems class in college where the first thing the prof drilled into us was "Don't debug with printf. You're going to want to. It's the thing you're most accustom to having written application code. But you're writing an operating system now. If you have a memory overrun, is the first thing you want to do really allocating a kilobyte of stack to mangle strings and determine if you need localization support to tell yourself something's wrong with memory? By the time the output gets emitted to console, the memory you want to inspect will be a blasted wasteland." As an example of how logging can break... > you can buffer in memory, and write to storage later You may as well not have logged then if the failure issue is a segfault; your program context will collapse before the buffer is output.
- angarg12 5y agoWhat if logging is part of your business logic?
- calvinmorrison 5y agoGreat point about using business metrics to notice real customer problems, but when you have to find out _why_ those metrics are off, logging is helpful. This reeks of functional programmer brain. The world is not immutable. the world is weird. Your systems will interact with other systems that don't always quite work. Sometimes, their systems are wrong, or update without your knowledge, or theres other issues in routing, networking and whatever else. Logging errors like "I can't resolve this domain" is more helpful than "my customers can't use this integration and business is at zero"
- alex_suzuki 5y agoEven if logging does not give you a complete picture of the exact run-time state of the system or the context in which the error happened, I’d be damned if I’d willingly deprive myself of a logged error. At least you know where it happened. Invaluable first clue IMHO.
- Sirupsen 5y agoWatch someone good at Splunk debug a production incident and you'll forever do good logging before you do anything else. Also, this [1] is doing logging right. Completely underutilized. [1]: https://stripe.com/blog/canonical-log-lines https://stripe.com/blog/canonical-log-lines
- marginalia_nu 5y agoI don't get why people get so theological about logging. If logs bring you some sort of value, then log away. If they don't, then don't. In some domains you absolutely crucially need logs, in others they're largely a waste of time. Logging is probably the most foolproof way to extract debugging information from your application. The killer feature of logging is that standard out very rarely breaks, no matter how bad things get it works. It will work from the moment the application starts, it will work in an OOM situation, will work if your network switch is on fire, when the DNS records are wrong and your technicians can't even enter the building, it will work no matter how bad things are. If logging does somehow fail, then that is on you, in that scenario you have fucked up your architecture somehow.
- deleted 5y ago[deleted]
- pm90 5y agoMost applications today run as replica sets (k8s pods/VM asgs) so log aggregators are another interesting part of the problem. Most shops are moving to saas logging for log collection which presents another failure mode: your logs are only as reliable as the saas provider. It is true however that looking at the individual replica, application logs should be very reliable.
- rbanffy 5y ago> log aggregators are another interesting part of the problem. And then you hope you are not logging to a logging service that'll try to execute something that was logged.
- waffletower 5y agoDefinite up vote here. Theological is the perfect word for this. It would be helpful if the author substituted the word "blog" for the word "log" in the article, and took the new meanings that result seriously.
- geocar 5y ago> I don't get why people get so theological about logging. Because the reason to log is about people, not about technology. There's no technical reason to make logs: Just don't make bugs, and you won't need the logs to find out what went wrong because nothing will have gone wrong. Go to the beach! This is hard though, and bugs happen for all sorts of reason that have nothing to do with the programmer making a mistake-- the customer can be unsatisfied because they didn't know what they wanted. Programmers learn very early in their career to distrust the requirements, because they know that saying but that's what the ticket says gets them nowhere besides an argument: They have to do what the business/customer meant. Put another way, the user doesn't want logs: The user wants to know if everything is okay or not, and presumably they have some way to figure that out, but if it isn't working correctly (or they merely think it isn't), the programmer will probably want those logs to help them. In many environments, the loop is larger than just those two people, there's QA support people, and internal experts/operators, and triage, and all of those people are going to have different needs from those logfiles. People might also have a second use for those logs involving anticipation of failures and tracking capacity. So there are a lot of non-technical, non-functional needs for logs, and once you understand this, it may be a little easier to understand why people would have almost rabid opinions about what those logs should look like (or if they can get the cure they need another way, what they might prefer instead of logs) > [standard out] will work in an OOM situation If you use write() which doesn't allocate memory, that's almost true, but if you use printf() it might allocate memory, and it might not work in an OOM anyway depending on what "standard out" actually is. > will work if your network switch is on fire, when the DNS records are wrong and your technicians can't even enter the building And yes you can write logs that nobody will ever be able to read, but what's the point of that? When your manufacturing plant is a smoldering rubble, someone is going to want to launch an expedition for those hard drives and try and figure out what caused millions (or potentially billions) of dollars in damages, so if you just wrote everything to standard output and washed your hands of the rest, you might have to find another job anyway. I've been programming for over three decades at this point, and I'm convinced there is no "easy one-size-fits-all answer" to whether to log or not, or if to log, how to log, so I find it useful to learn about this bit of theology so that I'm better equipped to talk to others about this, and maybe convince them of my opinions.
- jspash 5y agoWhen writing something that feels like it could break, or when dealing with unknown external APIs, I like to add an exception handler to _all_ new methods with a TODO and expiry date 3 months from now. Then on clean up days, if an exception wasn't triggered in that time frame, just remove the catch block. Perhaps I'm being too cautious (or too naive)? But it's saved my skin a few times. The only thing that I don't like about this technique is that the 3 month period is arbitrary. But it works well enough for me.
- deleted 5y ago[deleted]
- lucasyvas 5y agoSentry, in this case, is just a form of logging. So I don't agree with the premise of the article. Sure, prefer to eliminate error scenarios instead of allowing/logging them, but to me that has nothing to do with logging - the approach that doesn't handle errors is just bad code.
- jbreiding 5y agoLogging should be treated as a source for events. Most log collecting solutions have ways of producing metrics and alerts from logs. It takes more discipline to be able to understand why a metric or alert happened without supporting logs. Sourcing logs from multiple services, including dependencies, allow for creating more intelligent metrics. Treat logs as a stream of events rather than noise created by developers and logs become more useful.
- pm90 5y agoStrong disagree on this. Logs should serve a single purpose of allowing developers to introspect issues with their applications. If you want to generate an event stream, a more flexible and stable architecture would be to emit events deliberately. Imagine you build all sorts of dashboards and Workflows on top of logs or log based metrics and the dev team changes the structure of the logs or just stops logging. Suddenly all your analytics is out of whack; this is because you created a hidden dependency.
- jbreiding 5y agoI’m not sure about hidden dependency if the metrics break immediately. Important metrics should have alerts when absent or change unexpectedly. Communication and the decision to depend on the logs as a source of metrics would be key to keeping these systems connected and functioning. Taking a dependence on logs based metrics without communicating that is the failing here. The same breakage could happen by depending on the event being emitted and a developer changing the event structure. Communication and understanding helps both scenarios, not duplicating the effort by emitting logging for debugging, events for auditing and metrics for business.
- herodotus 5y agoLogging can be useful during development, but PLEASE get rid of it for deployment. The usefulness of my own logging while working at Apple was severely diminished by the sheer volume of logs from other frameworks where (I guess) removing the log message was considered to be of low priority. Just as an example: on my pure production M1 I see thousands (really) of this completely useless log message: PPSocialHighlightStorage: Constructed social attribution has missing data: (null) What is that message doing in shipping software? It cannot possibly help anyone.
- outworlder 5y ago> What is that message doing in shipping software? It cannot possibly help anyone. Correct. Those low level messages should not be present in 'production' environments _unless requested_. The ability to log extra info for debugging is fine. Doing that by default isn't. (User-visible) Warnings and errors only please. Can always dig more and turn up verbosity if needed.
- thrower123 5y agoAbsolutely not. Logs are all you're ever likely to get from most production deployments when you need to debug an issue.
- outworlder 5y agoMetrics? Distributed tracing? APM? Many production deployments have far better tools that don't involve grepping every service in the chain.
- waffletower 5y agoYour theology doesn't fit every use case. However, I wouldn't mind the potential benefits of a thoughtful culling of extraneous logging in MacOS.
- spaetzleesser 5y agoLogs are most likely the only data you can get about problems with deployed software. They have saved my ass many times.
- tzs 5y agoFor anyone else wondering what the heck "Sentry" is, I'm guessing it is this: https://sentry.io/welcome/ https://sentry.io/welcome/ If the author is reading this, the Sentry-related link you have in the article [1] is currently giving the readthedocs.io 404 page. Same for the "docs on logging" link about 4 sentences earlier [2]. [1] https://stories.readthedocs.io/en/latest/contrib/sentry/ https://stories.readthedocs.io/en/latest/contrib/sentry/ [2] https://stories.readthedocs.io/en/latest/debugging/ https://stories.readthedocs.io/en/latest/debugging/
- faeriechangling 5y agoI don’t understand the authors point at all >don’t use logging, use business monitoring Okay, if revenues suddenly drop 50% - then what? Where does the problem lie and once it’s discovered how can we alert on a recurrence of the same issue and fix the issue? Presuming the underlying issue cannot be trivially permanently remediated. The author seems to see logging as essentially making excessive alert noise inevitable when logs are meant to just be collected somewhere and scanned for exceptions known to cause incidents. Then when that exception happens at the same time revenues fall 50%… there you have it? The authors observations are mostly valid but their conclusions just don’t make sense. The observation you shouldn’t ping an admin every time a log generates an error doesn’t mean “don’t log”
- fatnoah 5y agoThe author's premise seems to boil down to 1) don't have errors and 2) "simply" make sure that your APM system has sufficient context to identify what went wrong. Of course, both of those are pretty impossible and they ignore the similarity between creating a constant flow of information for later use (logging) and creating a constant flow of information for monitoring (not logging). I could go on and on here. The "real" point seems to be that logging should be useful and consistent, which I agree with.
- vanusa 5y agoThis post is full of holes and simplistic reasoning; I'll just pick one instance: Logging is a side effect Right -- inside of a pure function, logging is probably not a great idea. But in other parts of your code (that are already generating "side effects" -- because you know, that's what software does) -- it can be not such a bad idea.
- laurent123456 5y agoClick bait title and rather poor content.
- ddek 5y agoThat's a no from me on every point of this argument. I don't really like logging, and I think some ecosystems do it better than others (nod-cough), but this article doesn't actually make anyones lives easier. Logging each exception vs logging nothing is a false dichotomy. I'm not sure anyone whose suggested fudging a 'Result' type in a language without sum types has ever done so, or at least stuck around afterwards. I'd like to be equally condescending in my answer to 'is my team ready for logging side effects?'. The fact that a distributed log aggregation, storage, and visualisation framework has a docker-compose file no more complex than a well configured SQL database does not terrify me.
- vpfaulkner 5y agoI agree that using error monitoring service like Sentry, Rollbar, Bugsnag, etc. is better than a naked log for "exceptional" situations. They provide a lot of nice features including alerting, additional debugging info, the ability to mark bugs as fixed, etc. I also agree that too many log statements can actually be counterproductive by providing a lot of noise. But the idea that logs have no value is silly. Every developer writes bugs and will run into situations where the code is behaving differently than they thought in production. Being able to follow the logs to understand what happened is extremely valuable.
- 015a 5y agoI agree; but I think it'll take years, if ever, to change this culture. Logging is a byproduct of a past time; everything is a file, stdout is a file, lets persist that file, now we have multiple replicas, lets collect the file into a multi-terabyte searchable database. The biggest downside: Its WILDLY expensive. Large orgs often have an entire team dedicated to maintaining logging (ELK) infrastructure. This price-tag inevitably leads to bikeshedding on backend teams about how to "reduce the amount we're logging" or "cleaning up the logs" or "structuring them to be more useful". Outside of development, they are so rarely useful. Yet inevitably someone will say: "you're just not structuring your logs correctly." Maybe that's true; similarly, I don't find vim to be a highly productive editing experience. Maybe I just don't have the thousands of extensions it would take to make it so. Or maybe You're stuck in the past and ignoring two decades of tooling improvement. Both can be true. I'm phrasing this as a false dichotomy, because in many teams: it is. Logging is easy; its built-in to most languages; so devs log. The information we need is in the system; its a needle in a haystack, but the needle is there. We log when a request comes in, when it hits pertinent functions, when its finished, how its finished, the manager says: "just look at the logs". Instead of "what better tooling can we make an investment in so future investigations of this nature don't take a full day." For starters: Tracing. Tracing systems should be built-in to EVERY LANGUAGE, just like console.log. We have a standard [1] sponsored by the Linux Foundation and supported by every major trace ingestion system. This is not a problem of camps and proprietary systems; its a problem of culture. I should be able to call a nodejs stdlib function at startup, specify where I want traces to go, sampling rate, etc, and immediately get every single function call instrumented. Its literally just highly-structured-by-default logging! Dump the spans to stdout by default! Our log ingestion systems can read each line, determine if its a span, if so route to trace ingestion, otherwise route to log ingestion. This is a critical step because it asserts that tracing is actually a very powerful tool that everyone needs to learn, like logging. Everyone knows about logging. Why? console.log. Its there, it gets used. Tracing right now is relegated to a subculture of "advanced diagnostics"; you gotta adopt a tracing provider, bring in dependencies, learn each implementation of OpenTracing, authenticate to send traces over HTTP... as a community, we should normalize just "dump traces like you dump logs, to stdout", have a formatter to make them nice to use in development, and now all that instrumentation work that any dev is capable of utilizing (just like console.log) "just works" in production. [1] https://opentracing.io/ https://opentracing.io/
- 999900000999 5y agoWhy not mention log levels ?
- schiho 5y agoIt’s very domain specific. We log everything, no one looks at it, but when things go south that’s when we do the investigative work. I say “log everything” you might need it later
- spaetzleesser 5y agoSame here. I have had plenty of cases where the logs allowed diagnosing incredibly difficult problems.
- skinkestek 5y agoNorwegians have a story about two wives quarreling about who has the dumbest husband and they decide to try. So one tells her husband he's about to die and is dying and finally dead and while he originally objects she is so persistent that he ends up alive but perfectly silent in his own funeral, that is - until his neighbor comes in in his birthday suit after his wife has made him a stylish suit of the same kind that the emperor got. At that point the supposedly dead guy can't manage it anymore and cries out laughing at his neighbor coming naked in his funeral. Sometimes I seriously wonder if some of the stuff that gets posted here is that kind of stuff. Edit, a translation of the full story, "Stupid Men and Trolls for Wives": https://everything2.com/title/Stupid+Men+and+Trolls+for+Wives https://everything2.com/title/Stupid+Men+and+Trolls+for+Wive...
- jodrellblank 5y agoI hate logs; when something is broken, logs are the last place I want to look when they ought to be the first. The end troubleshooter suffers from the same problem as Electron, i.e. making developer lives easier by logging everything, and if that makes other people's lives harder who cares. It's like someone going to a hospital emergency room and the triage asks what's wrong hoping to get "slipped on ice, possible broken hip" but instead gets a five hundred thousand line report of "blood oxygen level nominal" "Ow! bumped shoulder into doorframe" "Counting body arms still 2 present" "PANIC: hasn't got a card for that birthday tomorrow" "HELP! heard on TV show earlier" "Counting body arms: still 2 present" "NOT FOUND error when looking in drawer for spoon used one from dishwasher instead" "Counting body arms still 2 present" "Result 0xDEADBEEF from procedure defined in D:\dev\2016\src\folder\inside_joke.h" "Counting body arms: arms not found. Retrying in 10uS" "Counting body arms: arms not found. Retrying in 10uS" "Counting body arms: arms not found. Retrying in 10uS" "Counting body arms: arms not found. Retrying in 10uS" "Counting body arms still 2 present". Oh well, you say, that would help the developers divine the internal state of the system. ... but they're asleep right now because they're too good for on-call work. Isn't it kind of them to provide you with log messages which is easier for them than carefully making things which work well? Oh and they won't divine the internal state of the system until after you've determined if it's a bug, reported it, and their PM has prioritised it. Until then, hopefully the tech support department knows that counting body arms stops working properly when balance is lost. I suggest that logs are mostly useful when they indicate some general flaw like "can't contact server" and less so in other situations, similar to survivorship bias: planes returning from missions with bulletholes need reinforcing in the places with no bulletholes, those are the ones which stop the plane flying when hit. Or similar to the principle that robust systems have weirder problems, because the easy problems have been designed away. Similarly, the places you've carefully built with logging are the ones which you've spend enough time on that they'll probably work. The places where faults will come from are the unloved unlogged rotting parts, or the unexpected interactions between systems. [davnicwil's "make writing more fun" article yesterday said not to head off a bunch of tedious nitpicking, so I won't, just assume trivial dismissals have been headed off as necessary].
- jdmichal 5y agoI feel like a lot of the complaint here is why logging systems typically have levels? I use the following philosophy. Typically PROD would run at WARNING or maybe INFO, and never at DEBUG unless there's something happening that we can't figure out how to reproduce locally. DEBUG is really for local analysis, in which case you don't really care about overlogging. While ERROR level logging should immediately generate alerts, it's still useful to watch metrics on the WARNING level to see if something is potentially heading towards ERROR-level failure. ERROR / FATAL: The application failed to execute the business operation. WARNING: The application had an issue executing the business operation, but has a fallback -- for instance, retrying. Might still result in an ERROR later, if the fallback operation fails. INFO: Document the successful exit of business operations and decisions. This typically helps you determine where in the process the failure occurred, and what might need to be repaired if you decide to manually rollback the operation. DEBUG: Document the entrance of business operations and decisions, along with any additional technical operations, decisions, and values that might be relevant.
- fatnoah 5y agoIn a past life, I spent a lot of time aligning and instrumenting log levels across a SaaS product. We used similar levels. DEBUG - Only useful for developers and QA looking to understand exactly what happened and why on a per-request basis. INFO - Provide information about the current state of the system. This was our production Log Level WARNING - Something happened that will likely require action at some point in the near future, but not immediately. i.e. Approaching quota limits, temporary conditions we can work around, etc. ERROR - Something unexpected happened and should be looked at soon if only a one-off or immediately if consistent. SEV 1 or 2 depending. FATAL - Conditions prevent the system from being able to operate correctly. Generally a complete and catastrophic failure that will not resolve on its own, such as missing dependencies, invalid configuration, etc.
- 015a 5y agoThis makes sense, in a "theory" sort of way. The reality I've far too often ran into is: something is logged as debug, production is set to info+, something rare happens, and we don't have the logging to diagnose it because it was being logged at debug. So we swap it out for an info log, or raise the global logging level of production, but we still can't diagnose it because the rare event happened in the past; we just hope it happens again, or we spend hours trying to blindly figure out the conditions which caused it to happen without the information to actually reproduce. Eventually management gets fed up, and authorizes debug+ ingestion. The logging bill doubles, but at least we can "solve it" with money (the log stream is twice as noisy, and half as performant, but at least we have the data right?) A lower-level problem surfacing here: As engineers, we decide on a log level when we write the code. Its in response to expected system behavior; not actual system behavior. In comparison, a better solution would be: surface logs only when behavior betrays expectation. I don't want that debug line in 99% of requests, but for a 5xx request? I do. Logging systems are horribly unsuited for this, because it requires (1) a context (the request), (2) correlation between different execution points in the context (only log if later the request ends in 5xx), and (3) delaying log output (or ingestion) until that correlation is completed. We have a solution which does this out-of-the-box: Tracing. Tracing is designed to be sampled, and trace ingestion systems all have a "sampling" function designed to identify and surface only "interesting" or "anomalous" traces (if you want).
- slaymaker1907 5y agoStrongly disagree with this. I would rather have an excess of useless logs with the important ones than be missing the important logs. My motto is that so long as the logs don't break your performance budget, log away. However, do take care to keep logs easily searchable and filterable. If needed, you can even have certain logs go to separate places so that you can have the most important logs in one place and more detailed logging in another. However, in that case it is usually best to have one set of logs be a superset of another to avoid needing to join across the logs.
- jksmith 5y agoThis is a pretty narrow scope for what logging provides. Or maybe the definitions of logging and telemetry should be kept separate. Whatever the case, some type of data collection system should be in place to examine the deltas between iterations of time in operational and developmental systems. Don't dis logging because log4j has too much of a surface. Small footprint logging is still useful. Comes off a bit as xor thinking. Thank god for jazz music. The off notes and in-between notes create the most interesting sounds that expand the thinking.
- ronenlh 5y agoI’ve seen too many times logs used as assertions in tests.
- jansommer 5y agoExcellent article! Something I've been wanting to write myself for years. Love the first example: try ... catch(ex), log(ex). I've seen numerous developers do this and it's always unnecessary unless you can't catch exceptions globally. Just log all uncaught exceptions in something like Sentry, or a file for that matter, via a global exception handler. It's not about eliminating all possible exceptions, it's to avoid writing a bunch of boilerplate, since every line of code could potentially fail at some point. In the rare cases where some additional context is needed besides what is always added such as the current user, then of course, log away, but write a long comment about why the exception is caught just to be logged.
- sesm 5y agoCatching exceptions higher up the stack changes the control flow of a program.
- jansommer 5y agoWhat? Perhaps in some programming languages, but catching exceptions globally in C# works just fine.
- sesm 5y agoSorry, maybe my wording was too abstract. What I wanted to say: if you remove a catch statement in the middle of the function, then all the code after the catch statement will not be executed if an exception is thrown.
- jansommer 5y agoI think the abstract stuff you're talking about is caught exceptions. I'm talking about catching exceptions where the only purpose is logging: > Just log all uncaught exceptions in something like Sentry, or a file for that matter, via a global exception handler.
- 5y ago
- sesm 5y agoIs the author serious or it’s some kind of post-irony?
- liuyipei 5y agoSo easy. Simply don't have errors and bugs.
- munro 5y agotry: do_something_complex(*args, **kwargs) except MyException as ex: logger.log(ex) Basically this method is a giant @TODO, which does make sense in some cases. Either it's unknown at the present moment what a piece of data will look like (like scraping, or some poorly undocumented API); or the developer just doesn't have enough time and will deal with it later, which you can laugh at, but it can make a lot of sense when looking at the higher level goals of the project, our time is limited. I usually do this at the top level of a batch job, where you don't want it to halt the entire job. Or for a GUI app, but then also launch some sort of notification to the user / reload the app. Basically whatever makes the most sense in the context for accounting for something you didn't account for.
- dilyevsky 5y agoGood thinking - just eliminate all logging then when you get a sentry stack trace just mark the ticket as “not reproducible” when it’s not possible to recover what went wrong with the code from that.
- tablespoon 5y agoI think it's pretty safe to say when someone says to never in any circumstance use a common tool, they're almost certainly wrong. This article is so riddled with weird assumptions and wrong advice that I have to seriously question the author's practical experience.
- fnord123 5y agoSorry in advance for shoehorning Rust into a separate conversation... The new meta in Rust is to lift out loggers and replace the concept with tracing. There is a `tracing` package where you can setup spans like in OpenTelemetry but it also supports the logger macros so you can attach log messages to the spans. To consume this you add a subscriber configured at server startup to send structured logging to a Json logger, or ship them to a Jaeger endpoint. Or sentry, as suggested in the article. https://www.lpalmieri.com/posts/2020-09-27-zero-to-production-4-are-we-observable-yet/ https://www.lpalmieri.com/posts/2020-09-27-zero-to-productio...
- vpp32 5y agoThe company website the author works as CTO does not load... And it tells something...
- olliej 5y agoThis seems to be saying "don't log useless info". Yes, that makes sense. It doesn't hurt if you do, but sure I'll take that. But then says anything that is important enough to log should notify you. You don't want to be notified for every spurious network connection, login failure, etc or you will be drowning in notifications. So you realize you want to queue up those notifications so you can filter them. Congratulations you have now just recreated logging :-/
- gwbas1c 5y agoAnecdote about log4net, a popular .Net logging library: Once, when working on a shipping desktop application, we got to the point where we had to care about performance. When we turned on a CPU usage trace, the highest CPU consumer by a few orders of magnitude was the logger. That surprised everyone, so we dug in a little deeper. Turns on log4net's default behavior is to calculate a complete stack trace for every logging statement, even if the stack trace isn't being logged. Now, there may be good reasons to log a stack trace now and then, especially if you're trying to diagnose a difficult-to-reproduce bug. But, it's trivial to calculate the stack trace yourself. When we reconfigured log4net to not calculate stack traces, our CPU usage lowered dramatically. Lesson learned: Don't ship code with obscure features enabled that are performance pigs. There's no reason to calculate stack traces on each logging statement when the stack trace isn't being logged.
- anticristi 5y agoWhat about logging for "unknown unknowns"? For example, too many login failures may indicate an attack. Having an early warning for a breach is -- IMHO -- worth all the performance in the world. Here is how I recommend to perform regular log reviews: https://elastisys.io/compliantkubernetes/ciso-guide/log-review/ https://elastisys.io/compliantkubernetes/ciso-guide/log-revi...
- telotortium 5y agoGoogle SRE here. Don't follow this article literally - as great as monitoring (which I take to mean metrics that you can use to plot graphs) is, you'll never have defined as many monitoring metrics as you want, and logging can contain a much greater level of detail for each event, which allows you to reconstruct the course of an incident after the fact (allowing you to solve the incident much faster than trying to figure out how to reproduce it). Also, in regulated environments, logging has the advantage that it can contain data that's too sensitive to be recorded long-term, even with ACL checks, since debug logs are generally retained for only a short time (few days or so). You generally want your graphs to be able to use data from farther back than that (up to a year). The best article that encompasses the Google logging philosophy is https://apenwarr.ca/log/20190216 https://apenwarr.ca/log/20190216 Other points: - Don't log to a synchronized file if possible - log either to the network or at least to RAM (which can be emptied to the network in the background). - For the overlogging problem, get a logging library that rate-limits your logging for DEBUG/INFO level events, ideally rate limiting by call site. - For Java, it's very convenient to be able to instrument code at runtime to add and remove logpoints.
- gHosts 5y agoLogs are there for those WTF!? Moments. When something unexpected happen and you don't know what. When you need a clue any clue. Logs are there for observability, so you can get those, "Oh wow! Cool!" moments when you see something that you never knew. If you never make a mistake, or if you know your external systems and uses perfectly.... Don't log. If you're a mortal that gets surprises... log.