Index: /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/ViewLogPage.html
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/ViewLogPage.html	(revision 2754)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/ViewLogPage.html	(revision 2755)
@@ -10,4 +10,8 @@
             <a wicket:id="home">AdminHome</a>
         </div>
+	<p>
+	    <span wicket:id="logLabel">Showing final X bytes (or less) of total N in componentregistry.log:</span><br />
+	    [<a wicket:id="logDownloadLink">Download entire log file</a>]
+	</p>
         <textarea cols="150" rows="50"  wicket:id="logText" >log text</textarea>
     </body>
Index: /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/ViewLogPage.java
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/ViewLogPage.java	(revision 2754)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/ViewLogPage.java	(revision 2755)
@@ -1,15 +1,15 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
 package clarin.cmdi.componentregistry.frontend;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
-import org.apache.commons.io.FileUtils;
+import java.io.RandomAccessFile;
+import java.text.NumberFormat;
 import org.apache.log4j.FileAppender;
 import org.apache.log4j.Logger;
 import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.form.TextArea;
+import org.apache.wicket.markup.html.link.DownloadLink;
 import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.model.Model;
@@ -17,31 +17,76 @@
 /**
  *
+ * @author Twan Goosen <twan.goosen@mpi.nl>
  * @author paucas
  */
 public class ViewLogPage extends SecureAdminWebPage {
 
-    public ViewLogPage(final PageParameters pageParameters) throws IOException {
-        super(pageParameters);
-        addLinks();
-
-        File file = getLogFile();
-        String content = FileUtils.readFileToString(file, "UTF-8");
-        add(new TextArea("logText", new Model(content)));
+    public ViewLogPage(final PageParameters pageParameters) {
+	super(pageParameters);
+	addLinks();
+	addLogFileContent();
     }
 
     private void addLinks() {
-        add(new Link("home") {
+	add(new Link("home") {
+	    @Override
+	    public void onClick() {
+		setResponsePage(AdminHomePage.class);
+	    }
+	});
+    }
 
-            @Override
-            public void onClick() {
-                setResponsePage(AdminHomePage.class);
-            }
-        });
+    private void addLogFileContent() {
+	final int tailSize = 1000000; // Megabyte
+
+	final NumberFormat numberFormat = NumberFormat.getIntegerInstance();
+	numberFormat.setGroupingUsed(true);
+
+	final File logFile = getLogFile();
+	if (logFile != null) {
+	    try {
+		final RandomAccessFile raLogFile = geFileTail(logFile, tailSize);
+		final String content = getLogFileContent(raLogFile);
+
+		add(new Label("logLabel", String.format("Showing final %s bytes (or less) of total %s in %s:", numberFormat.format(tailSize), numberFormat.format(raLogFile.length()), logFile)));
+		add(new TextArea("logText", new Model(content)));
+
+		add(new DownloadLink("logDownloadLink", logFile));
+	    } catch (IOException ioEx) {
+		add(new Label("logLabel", "Could not read from log file. See error message below."));
+		add(new TextArea("logText", new Model(ioEx.getMessage())));
+	    }
+	}
+    }
+
+    private String getLogFileContent(final RandomAccessFile randomAccessFile) throws IOException {
+	String currentLine;
+	StringBuilder contentBuilder = new StringBuilder();
+	while ((currentLine = randomAccessFile.readLine()) != null) {
+	    contentBuilder.append(currentLine).append("\n");
+	}
+	String content = contentBuilder.toString();
+	return content;
+    }
+
+    private RandomAccessFile geFileTail(File logFile, int tailLength) throws IOException, FileNotFoundException {
+	// Skip to tail of file
+	final RandomAccessFile raLogFile = new RandomAccessFile(logFile, "r");
+	final long startPosition = raLogFile.length() - tailLength;
+	if (startPosition > 0) {
+	    raLogFile.seek(startPosition);
+	    // Read until end of line so we don't end up halfway some random line
+	    raLogFile.readLine();
+	}
+	return raLogFile;
     }
 
     private File getLogFile() {
-        FileAppender appender = (FileAppender) Logger.getRootLogger().getAppender("ROOT");
-        File logFile = new File(appender.getFile());
-        return logFile;
+	// Get file from appender
+	final FileAppender appender = (FileAppender) Logger.getRootLogger().getAppender("ROOT");
+	if (appender != null) {
+	    return new File(appender.getFile());
+	}
+	return null;
     }
 }
