The Asocial

Pimp My Code, issue 2

Exabit and his team give a new life to a Python logger

Article date April 24, 2016
Category internet

Previously on Pimp My Code: muennich got his brand new sxiv repository pimped. Now he’s enjoying GNU Guile and GNU Build System, and fetches images directly from the Internet.

Today Victor Frankenstein comes to visit logbook and its owners.

Victor: Yo, now we’re going to visit logbook’s authors who aren’t totally happy with their library. Here they are, on github – let’s knock.

The door opens, Roman shows up and looks shocked.

Roman: Is it you? Is it really you? OMG, OMG! I can’t believe it!

Victor: Hell yeah, nice to see you Roman! I heard you need some help with your code, is that right?

Roman: Aah, yes! It’s so old, I’ve actually got it from my grandma.

Victor: Let’s see what you have there!

Roman: Sure, here it is. It’s pretty much in the same condition as it was when I’ve got it, I’ve only tried to cover it with tests occasionally, to keep it going, you know.

Victor: Oh, I see. Plenty of tests you’ve got there. Hey, who are those fellows?

Roman: Those are my comrades, we usually write and use logbook together. That’s Armin and George, they’ve actually done most of the tinkering.

Armin and George: Hello Victor!

Victor: Hey!

Roman: And here are Ronny, Daniel, Kenneth, Valentine, and others. Actually they’ve sent a note to you in the first place, asking for help.

Victor: Well, good friends you have there! Now tell me guys, what do you want to see changed about this library?

Armin: See all those tests? We’ve collected plenty of those with time.

Victor: Yeah, we definitely should clean those up. What else?

George: You know how logging is supposed to inform you about errors? But when there’s an error in logging, what’s especially easy to get in these Python libraries, you kind of get screwed – hence all those tests. I don’t know, but maybe something can be done about it?

Victor: That’s tricky, but our mechanic will take a look at it – we’ll figure something out. Okay, guys, I’m getting it to our garage – see you later!

Logbook authors: Yaay!

Victor arrives to the garage, El Hackerozo doesn’t approve of what Victor has brought in this time.

El Hackerozo: Come on, man, is it Python? What are we supposed to do with it? Does it look like we got space around here to set up any additional virtual environments?

Victor: It’s not that bad, it was maintained.

El Hackerozo: Seriously? Look at that test suite, it barely prevents the whole library from collapsing into an infinite loop.

Victor: Look, it only proves that we’re the only ones who can help them out! Let’s see what we can fix here, okay?

Victor explains other details and the team begins planning.

Victor: So, I figured that their logger needs logging. We’ll reuse the existing mechanics for that, making it recursive – just increasing the threshold on each level to make it self-terminate to avoid infinite loops. But something still needs to be done about how it looks. Also don’t forget about those tests!

El Hackerozo: Okay, I can repaint the icon completely, perhaps add some flames to make it move faster, and lint the code a bit.

Victor: Let’s do this!

The team works on it for hours. The test suite looks really gross after being extracted from the main code tree, guys pack it into big black bags.

Victor: Let’s see what we’ve got here!

Before

Before

After

After

Victor: Now is the time to show it to our clients!

El Hackerozo plays with a part of the eradicated tests.

The logbook authors come in, the team presents the work:

Yo dawg!

I heard you like logging. Every logger logs. But not every logger is logging what it’s logging while it’s logging. So we’ve put logging into your logger, to log what it’s logging while it’s logging!

While that gets logged, it also logs what it’s logging – recursively. But it also terminates! No more silent errors in your logging.

Hold on, hold on! That’s not the only thing we’ve improved! Your icon has been updated with screaming new design: flame vinyl that reflects its performance, bookmark, more expensive wood and converted to SVG from plain old boring PNG! While it’s new, we’ve tried to preserve its soul – so it will remind you of all those good times from the previous life of your nifty little library.

Why don’t you try to zoom it in and out? See, it’s vector, no pixels! That’s the latest technologies right here, just for you!

We had to perform some heavy cleaning to get rid of those rusty tests you’ve collected in it, but see – no tests anymore! Don’t be afraid of bugs anymore: with this beauty, you can write terabyte after terabyte of logs, without a need to pause. Did I mention that it accelerates from 0 to 100 MB/s in 3 seconds? Be careful with this babe!

All your favorite handlers are still there, of course. Just pick one and take a stab!

Roman: OMG, OMG! Is it really our logbook?!

Armin: Ahh, look at this beauty!

George: Whoo-hoo!

Victor: Yeah, yeah, do you even recognize your old library?

Valentine: Holy beep! Is it logging?

Victor: Yeah, we’ve put logging into your logger! Wanna see it in action?

Daniel: Heck yeah!

Victor: Observe!

Ronny: I can’t believe it, you’ve actually made it to log what it’s logging!

El Hackerozo: Right, no more silent errors, and no need in those rusty tests. Do you like the new looks?

Frazer: It’s awesome! Can you take a photo of me with it?

Victor: You also get our badge, indicating that your project has been officially pimped. We’ve also cleaned up all the inferior badges you’ve had there!

Ronny: This is awesome! Thank you so much, Pimp My Code!

Raphaël: Holy beep, guys, all the handlers are still there!

Victor: That’s right. We figured you like them.

Roman: Thank you!

Victor: It was Pimp My Code on The Asocial, see you next time!