--- vlogger	2005-03-18 15:43:34.000000000 +0100
+++ vlogger	2013-01-06 17:38:21.092186188 +0100
@@ -380,6 +380,7 @@
         if ( $vhost =~ m#[/\\]# ) { $vhost = "default" }
         $vhost =~ /(.*)/o;
         $vhost = $1;
+        $vhost = 'default' unless $vhost;
 
         if ( $OPTS{'i'} ) {
             $reqsize = $this_line[1] + $this_line[2];
@@ -418,15 +419,24 @@
                 delete( $logs{$key} );
             }
 
-            # check if directory is there
-            unless ( -d "${vhost}" ) {
-                mkdir("${vhost}");
+            # first look if the directories (vhost + template definition) exist
+            # if not - create them (ward@pong.be, 2003-03-22)
+            my $templatedir = time2str("${vhost}/$TEMPLATE", time());
+            my $templatefile = substr($templatedir,rindex($templatedir,'/'));
+            $templatedir = substr($templatedir,0,rindex($templatedir,'/'));
+            if (!(-d $templatedir)) {
+              my @path = split(/\//,$templatedir);
+              foreach (@path) {
+                my $dir = $_;
+                if (!(-d $dir)) {
+                  mkdir($dir) || die "Can't create $dir (part of $templatedir): $!\n";
             }
-
+                die "Can't cd to $dir: $!\n" unless chdir($dir);
+              }
+            }
+            chdir('/');
             # open the file using the template
-            open $vhost, ">>${vhost}/" . time2str( $TEMPLATE, time() )
-              or die ( "can't open $LOGDIR/${vhost}/"
-                . time2str( $TEMPLATE, time() ) );
+            open $vhost, ">>/$templatedir/$templatefile" or die ("can't open $LOGDIR/$templatedir/$templatefile");
 
             # autoflush the handle unless -a
             if ( !$OPTS{'a'} ) {
@@ -453,7 +463,7 @@
             $log_line =~ s/^\S*\s+//o;
         }
 
-        if ( $reqsize =~ m/\d|/ && $reqsize > 0 ) {
+        if ( $reqsize =~ m/^\d*$/ && $reqsize > 0 ) {
             $tracker{$vhost} += $reqsize;
         }
 
