text stringlengths 0 2.35k |
|---|
• Challenges of switching from one operating system to another |
• Terminal commands and interrupt behavior on Windows and Mac |
• Clipboard management and history tools |
• Editing and post-production process for podcasts |
**Mat Ryer:** Hello, and welcome to Go Time. I'm Mat Ryer. Today we're talking about logging; something we all do, no need to be embarrassed about it... But are we doing it right? Are we logging the right things, are we logging them to the right place? We're gonna find out today. |
Joining me - Jon Calhoun, of course. Hello, Jon. |
**Jon Calhoun:** Hey, Mat. How are? |
**Mat Ryer:** Not bad, mate. Not bad. How has your week been so far? |
**Jon Calhoun:** Pretty good so far. |
**Mat Ryer:** Yeah, it's Tuesday, isn't it, so I shouldn't really ask that question. Silly. Never mind... I hope the rest of the week is as good as yesterday. We're also joined by Ed Welch, who is a swell fella who's been two kinds of engineer and two kinds of manager, and will do any job, as long as he's having fun. H... |
**Ed Welch:** Hey, Mat. Thanks for having me. |
**Mat Ryer:** Absolute pleasure. So yeah, logging. We all, I think, know what logging is, but let's just be clear - logging... What is it? |
**Ed Welch:** The fun part about logging is it's probably the first thing that everybody does when they start writing software. Everybody's first intro into running a program is usually a Hello World, which is at least in my opinion a form of logging. So it's probably the most common way, the most ubiquitous way that w... |
**Mat Ryer:** Yeah. Sometimes I'll have -- in the beginning, when I'm writing something, I'll have lots and lots of logging going on, because like you say, it's a great way to see what's going on and get some insights. It's like a really easy, simple way to do that. But usually, I'll go and kind of clear that all out a... |
**Ed Welch:** \[04:14\] You're probably ahead of most. I think that largely people when they write a log statement, it's probably there forever. I'm not sure how often people really go back to scrutinize what they logged. So I would certainly think that you're gonna gain from that; having more valuable log messages and... |
**Jon Calhoun:** I'm imagining some of your scenarios are writing logs to help debug stuff... And if you're anything like me, there's probably some time where you catch yourself doing a sanity check of like "We're in this function", just because you're like "Is the code actually getting to this point where it's suppose... |
**Mat Ryer:** Yeah, I tend to do that if I'm marking bits. I'll just put monkey, or like monkey2, monkey3. So that's probably why I go through and remove the log statements. But also, if I'm doing test-driven development, I will tend to log a bit less, really, unless there's a specific kind of tricky behavior, somethin... |
**Ed Welch:** I inherited a codebase a few years back, where -- |
**Mat Ryer:** Congratulations. From an old uncle? |
**Ed Welch:** Yeah, it was really -- \[laughs\] |
**Mat Ryer:** An old uncle died? "I'll leave this codebase to Ed..." |
**Ed Welch:** Yeah, let's go with that. So my uncle left me this sweet codebase, and he was very -- I don't know, thorough and consistent... Every function call had a log line at the beginning that would say the name of the function, and the entry, and then the values that were passed in, and then an exit. And to be ho... |
So I think my learning from that had more to do with "Maybe don't log monkey1 and monkey2", instead log something like "Here's where I am and here's the state at the time. Here's some values." Because that particularly ended up being useful, trying to understand why something was or wasn't working. It's like, "It got t... |
There's a lot of tools that exist now that maybe make that easier, like debuggers and tracing, and even in your tests... But there's certainly an element of logs are generally always available, and so having some (at least) checkpoints through a process that give you insight into that process. |
**Mat Ryer:** Yeah, one trick that reminds me of, that does work for me - if I've got a program where there's quite a bit of logging going on, I'll do a thing where I log out a load of hyphens, just some dashes, and then in Go defer immediately the same thing... And that's a neat way of wrapping up really the in and ou... |
That works if you've just got one instance of the program running, which you normally do in dev... But it doesn't work if you've got multiple instances running, really, does it? |
**Ed Welch:** \[07:45\] I think it becomes -- one of the things that I'm gonna give people advice on logging is that the more context you can put in the log line, the more useful it is. Whether or not you have access to the hostname, and if your logging application or frameworks or systems introduce that at another lev... |
**Mat Ryer:** Then I wonder, should you standardize the format then, if you're gonna be using these logs in this way? Because obviously, it's just a string, isn't it? You can just print out anything you like from your program. Should we be strict about what format we're printing in? |
**Ed Welch:** Probably... It's kind of a hard problem, whether or not you have control over the logs from some of your applications or not... If you're building your own app, you're writing your own logs, having some consistency is always helpful. |
One of the things that I think are interesting about log lines is the battle between the humans and the machines. We're talking about humans looking at log lines, but it's not uncommon now that log lines go into analytics, and other systems, security... So having the format be structured becomes really important for ho... |
Arguably, having a visual format that's easy to parse for humans is true, too. Commonly, I would say JSON is maybe what you would find the most... It's probably not my first pick for a structured format, because I think it's harder for humans to read; it's very easy for machines to read. And specifically, JSON becomes ... |
So one of the things when you're typically viewing a log line is it will exist on horizontal space on your screen, and then vertical space as your number of log. So if you try to pretty-print a JSON object in order to be able to view it, you then turn one log line into line tens, or hundreds, so now you've optimized ve... |
There's an alternative that I like a lot, that's common in Go probably more than I've seen in other langauges, logfmt. So having key-value pairs that are separated by a space, basically, log format, if you're not Mat? |
**Mat Ryer:** Yeah. |
**Ed Welch:** I know how much you like fmt... |
**Mat Ryer:** I did like it. I wasn't gonna comment, but yeah. I'm pleased you said it. Fmt. Logfmt. |
**Ed Welch:** So it's kind of an interesting compromise on machine parsability and human readability. But ultimately, having structure does become really important, because almost guaranteed you're gonna need some tool to help you parse those logs, or strictly, you're gonna parse them with a machine for other purposes. |
**Mat Ryer:** Yeah. See, JSON would also probably encourage you to put more complex objects in, whereas with logfmt - we're talking key-value pairs there. |
**Ed Welch:** Yeah. Which is a nice thing too, so I generally tell people -- I don't have a problem with JSON logging; it's in fact the easiest and most approachable for most logging frameworks. I would highly recommend keeping a flat structure as a practice though, right? Just do key-value pairs in JSON. |
**Jon Calhoun:** I think part of it definitely comes down to how you're logging affects how you're gonna consume it... Because I know the first time I ever used JSON logging, it was game-changing in the sense of like "Oh, I can filter on these things, and it'll make my life a lot easier." But you're right, the first ti... |
**Ed Welch:** \[12:17\] Yeah. The other reason to keep the object flat -- because you're right, the tooling that exists out there usually facilitates this, but it also introduces in a lot of cases another query language. So to manipulate JSON documents, you usually need to use -- I like JQ, JMESPath, or some other quer... |
I think the more you can keep that structure flat, I think the happier you would generally be... And if you need a complex nested object, is the log line the right place for storing that information? Maybe a sniff test... We won't go as far as sanity test yet. |
**Mat Ryer:** No. |
**Jon Calhoun:** Thinking about it that way - you said some things are better fit for a database... Do you consider things written in a database to potentially be logs? An example I can give is I was building a web server once, and I forget why, but for some reason we wanted a way to actually record web requests, and t... |
**Mat Ryer:** Yeah, but that's kind of structured logging, isn't it? |
**Jon Calhoun:** It had that feel to me of like - you entered a function, and then when you exit the function, you're kind of like "These are the things that happened." And that's roughly what we were doing; we were like "We need to store this somewhere where we can query it and actually look at the data and try to do ... |
**Ed Welch:** It's really fascinating in the sense that it touches a little bit on the types of logging that we see, too. That falls a little bit into the category that are more like event logs, or access logs, or they're very specific things that happen, that have useful contexts. I guess the question there that I fin... |
The other types of logging that we kind of started talking about are more like what people introduce when they're writing code. So this is the stuff that helps me understand if my application is working, or where it's working, or how it's working... Maybe even just the sort of overall lifecycle of the program itself in... |
The only advice that I could give around this, in some experiences that I've had, is don't make your primary logging in terms of what gives you visibility into your application stored in the same thing that you need to run -- so like don't store those logs in the database, because what happens is when you have trouble ... |
**Mat Ryer:** \[15:59\] Or if your database -- if there's an error, then it logs that there's an error, but it can't log to the database, so that's an error... \[laughs\] |
**Ed Welch:** Yeah. It's very useful. I've seen in older software systems that I've worked with before that systems that exist today for aggregating working with logs - it was pretty common to store logs in the database, but then when you had trouble with the database, which was usually the thing you had the most troub... |
**Jon Calhoun:** Yeah. A lot of that probably comes down to like the lifecycle of the product, too... Where I tend to see that type of approach being - not okay, but kind of okay, is if you have like a two-person startup and they're just trying to slap something together and get it up and going, then you kind of cut so... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.