Blog

Todays Work is Tomorrow’s Raw Material

I saw this on Quora a while ago, and have been meaning to share it:

Software is one of the very few things where yesterday’s work output is most of today’s raw material. If you dig one ditch poorly, so what? You move on. But you can’t move on from a bad night’s coding. Your mistakes stick with you until you clean them up. Most people don’t, which is why a lot of software projects are a morass of bugs, messy code, and chaos, yielding low productivity and terrible morale.

-William Pietri on Quora

It’s good food for thought about technical debt. It doesn’t always make business-sense to go spend the time to clean up all the technical debt right away, but sooner or later it catches up with you if you continue to work on the same code-base.

How to Use Indy 10 Imap Intercept function for Logging

It took me a while to track down enough information to figure out how to use Imap.Intercept to log raw IMAP client/server communication to troubleshoot an SSL account issue, so thought I’d share a basic code snippet on how to have IMAP log to disk the communications.

var
idLogFile1 : TidLogFile;
begin
IMAP := TIdIMAP4.Create(nil);

idLogFile1 := TidLogFile.Create(nil);
idLogFile1.Filename := 'C:\temp\imaplog.txt';
idLogFile1.active := True;

IMAP.Intercept := idLogFile1;

//...
end;

Log4D Basic FileLogger Example

Since there is lacking on “getting started” documentation for Log4D, I thought a basic example might be helpful to others who might be intimidated about getting started with logging to a file in Delphi. Log4D is very simple, and similar to other Log4J related logging packages but lacks basic “getting started” documentation.

I used XE4 Starter for this. At the time of this writing, I and others have submitted some patches to fix the compile errors in Log4D affecting XE4, but they have not been merged in yet. For the quick fix to make it compile in whatever recent version of Delphi you have, see my previous post, my previous post.

First, create a project. I created a VCL application project for this example, because I’m not writing console applications so it’d be easier to copy and paste from 😉

Open the .dproj file (right click on the .exe name in the Project Manager and select “view source”) and add the highlighted lines:

<pre>
program Log4DbasicExample;</code>

uses
Vcl.Forms,
Log4D,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

var
Logger : TLogLogger;
begin

TLogBasicConfigurator.Configure;
TLogLogger.GetRootLogger.Level := All;
Logger := TLogLogger.GetLogger('myLogger');
Logger.addAppender(TLogFileAppender.Create('filelogger','log4d.log'));

Logger.Debug('initializing logging example program');

Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
</pre>

When you run this application, it will create a log file called log4d.log in the directory the .exe file is in. Good enough for quick logging and debugging. Not adequate for production code.

Anywhere else in the project you need to log something, now it’s easy. I added one button to my VCL form, and double clicked the button to add an onClick handler, and then updated my VCL form unit as follows:

unit Unit1;

interface

uses
  Log4D, 
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  TLogLogger.GetLogger('myLogger').Debug('Button 1 clicked!');
end;

end.

If you’re doing a bunch of logging in one part of your code, you probably don’t want to use the chaining syntax because calling GetLogger repeatedly is unnecessary overhead. Instead store the Logger in a variable:

procedure TForm1.Button2Click(Sender: TObject);
var
  Logger : TLogLogger;
begin
  Logger := TLogLogger.GetLogger('myLogger');
  Logger.Debug('Button 2 clicked!');
end;

Well, there you have it. Basic, just enough to get started example. Because next time I want to add logging to a different project, I’m sure I will have completely forgotten how to do it and what and where I added my code.

File-Logging in Delphi

I wanted to do some quick logging to help me understand some code flow in Delphi. But having the Starter Edition of Delphi was crimping my style! Starter Edition doesn’t include the Event Log Viewer to see the output from OutputDebugString() while running in the debugger.

So I kept coming back to “I really just need to get over the learning curve and set up a ‘proper’ logging tool like Log4J”, a tool I’d used for Java projects in times long past. StackOverflow suggested Log4D and Log4Delphi as good possible candidates.

After reviewing both packages, I decided to go with Log4D.

Log4D seemed a bit simpler in that everything you need for basic logging is in one .pas file and one .inc file. I can see advantages both ways as a developer, but for just get me some logging quick, only having to add two files rather than a handful, and only needing one new unit in the uses statement simplifies some things.

Neither one had been updated in the last few years, so when you’re talking about “make this compile in a current version of Delphi” it looked like similar level of work.

Log4Delphi claims to be “loosely based on” Log4J. Log4D claims to be a direct port of Log4J.

Log4Delphi appears to be fairly well documented, whereas Log4D has almost no documentation. And while usually I prefer to go with the well-documented version, I felt like the simplicity of one file would make it worth seeing if I could muddle through the lacking documentation to make Log4D work. A few Delphi experts on StackOverflow swear by Log4D.

There were two compile errors I had to fix to make Log4D compile on XE4:

The IFDEF around Contnrs is missed by newer versions of Delphi, so you need to add {$DEFINE DELPHI5_UP} to the end of the .inc file (or in the .pas file works too). And ShortDateFormat needed to change to FormatSettings.ShortDateFormat

That’s the bare minimum fix, a better fix that maintains backwards compatibility isn’t a whole lot harder See my StackOverflow Discussion here about fixing the IFDEF so “and above”. And the ShortDateFormat issue, just needs another IFDEF around the FormatSettings for XE+.

The only basic “how to get this up and running” example of Log4D I could find online was this one blog entry. It needed a couple changes to compile (“Trace” wasn’t one of the log levels in the downloaded Log4D package). And then a little more puzzling together from the code and documentation for Log4Delphi and Log4J to make a file logger. I’ll write more about those changes in my next post ;-).

Night at the Museum

Today we attempted to build “Night at the Museum”, Lego City set 60008 using our existing lego bricks. It’s a bit more…colorful…but the same basic shape.

Here’s how it came out:

 

More Minions

12319544184_d0c0a9b69d_320

Batman Minion by Elspeth De Montes

Her Superhero Minion Gallery includes the likenesses of Superman, Spiderman, The Incredible Hulk, and Wolverine. They are based on the Bricks Ben minion design, which is pretty complicated and uses a lot of studs not on top building techniques.

 

dsc02273

LegoTessa has a video of how to build her minions. These ones are a bit smaller and look quite doable without having to order a whole pile of bricks from pick-a-brick.

 

 

10041 Main Street

Today we are building the car shop from set 10041 Main Street (2003)

carstore

Continue reading 10041 Main Street

Double Decker Bus

This takes a LOT of windows…but it’s worth it, it was a pretty cool one to make…and no weird parts!

313

From set 313 “London Bus” from 1966 Continue reading Double Decker Bus

Taxicab

From set “LEGO City Train Station” 7937. You will need the entire instruction booklet 1 (of 2) for this model.

71TFYm48ljL._SL1500_

I picked this model to build, because it uses a bunch of “modern” car-parts we got from pick-a-brick and build-a-car.

4259673   4521778    4260124

But it did require one unusual part we didn’t have for the front bumper, which I blogged about yesterday.

So, here’s how it came out:

P1000608

I didn’t have any of those rounded roof pieces that is sloped up higher in the middle to accommodate minifig heads, so I had to add a row of flat bricks below the roof to give more clearance for heads.

 

 

Taxicab Alternate Grille & Bumper

Since I didn’t have one of these in my collection, I had to make an alternate bumper and grille.

4264898

Notice how the back of this piece has a slight curve so the wheels don’t hit it? That made my first prototype not work at all, and it took a couple tries to get a design that really worked. When I made this model, I tried different bumper styles in the front and back, but this one worked better.

car grill_1_0_0_0_1_0_0_0_1_5_2550_300_DPI_1

 

 

Parts List

grilleparts

Building Steps

car grill_page_1

download as printable pdf