diff --git a/services/fileindexer/fileindexerconfig.cpp b/services/fileindexer/fileindexerconfig.cpp
index c2af538..dbbf149 100644
--- a/services/fileindexer/fileindexerconfig.cpp
+++ b/services/fileindexer/fileindexerconfig.cpp
@@ -320,4 +320,9 @@ bool Nepomuk::FileIndexerConfig::suspendOnPowerSaveDisabled() const
     return m_config.group( "General" ).readEntry( "disable suspend on powersave", false );
 }
 
+bool Nepomuk::FileIndexerConfig::isDebugModeEnabled() const
+{
+    return m_config.group( "General" ).readEntry( "debug mode", false );
+}
+
 #include "fileindexerconfig.moc"
diff --git a/services/fileindexer/fileindexerconfig.h b/services/fileindexer/fileindexerconfig.h
index 7f94722..3870a86 100644
--- a/services/fileindexer/fileindexerconfig.h
+++ b/services/fileindexer/fileindexerconfig.h
@@ -139,6 +139,13 @@ namespace Nepomuk {
          */
         bool shouldFileBeIndexed( const QString& fileName ) const;
 
+        /**
+         * Check if the debug mode is enabled. The debug mode is a hidden
+         * configuration option (without any GUI) that will make the indexer
+         * log errors in a dedicated file.
+         */
+        bool isDebugModeEnabled() const;
+
     Q_SIGNALS:
         void configChanged();
 
diff --git a/services/fileindexer/indexer/indexer.cpp b/services/fileindexer/indexer/indexer.cpp
index 7007364..a7e5436 100644
--- a/services/fileindexer/indexer/indexer.cpp
+++ b/services/fileindexer/indexer/indexer.cpp
@@ -78,6 +78,7 @@ public:
     StoppableConfiguration m_analyzerConfig;
     StrigiIndexWriter* m_indexWriter;
     Strigi::StreamAnalyzer* m_streamAnalyzer;
+    QString m_lastError;
 };
 
 
@@ -99,17 +100,17 @@ Nepomuk::Indexer::~Indexer()
 }
 
 
-void Nepomuk::Indexer::indexFile( const KUrl& url, const KUrl resUri, uint mtime )
+bool Nepomuk::Indexer::indexFile( const KUrl& url, const KUrl resUri, uint mtime )
 {
-    indexFile( QFileInfo( url.toLocalFile() ), resUri, mtime );
+    return indexFile( QFileInfo( url.toLocalFile() ), resUri, mtime );
 }
 
 
-void Nepomuk::Indexer::indexFile( const QFileInfo& info, const KUrl resUri, uint mtime )
+bool Nepomuk::Indexer::indexFile( const QFileInfo& info, const KUrl resUri, uint mtime )
 {
     if( !info.exists() ) {
-        kDebug() << info.filePath() << " does not exist";
-        return;
+        d->m_lastError = QString::fromLatin1("'%1' does not exist.").arg(info.filePath());
+        return false;
     }
     
     d->m_analyzerConfig.setStop( false );
@@ -140,9 +141,12 @@ void Nepomuk::Indexer::indexFile( const QFileInfo& info, const KUrl resUri, uint
     else {
         analysisresult.index(0);
     }
+
+    d->m_lastError = d->m_indexWriter->lastError();
+    return d->m_lastError.isEmpty();
 }
 
-void Nepomuk::Indexer::indexStdin(const KUrl resUri, uint mtime)
+bool Nepomuk::Indexer::indexStdin(const KUrl resUri, uint mtime)
 {
     d->m_analyzerConfig.setStop( false );
     d->m_indexWriter->forceUri( resUri );
@@ -153,6 +157,14 @@ void Nepomuk::Indexer::indexStdin(const KUrl resUri, uint mtime)
                                            *d->m_streamAnalyzer );
     Strigi::FileInputStream stream( stdin, QFile::encodeName(resUri.toLocalFile()).data() );
     analysisresult.index( &stream );
+
+    d->m_lastError = d->m_indexWriter->lastError();
+    return d->m_lastError.isEmpty();
+}
+
+QString Nepomuk::Indexer::lastError() const
+{
+    return d->m_lastError;
 }
 
 #include "indexer.moc"
diff --git a/services/fileindexer/indexer/indexer.h b/services/fileindexer/indexer/indexer.h
index 4a604bd..e3c63cc 100644
--- a/services/fileindexer/indexer/indexer.h
+++ b/services/fileindexer/indexer/indexer.h
@@ -53,7 +53,7 @@ namespace Nepomuk {
          * Index a single local file or folder (files in a folder will
          * not be indexed recursively).
          */
-        void indexFile( const KUrl& url, const KUrl resUri, uint mtime = 0 );
+        bool indexFile( const KUrl& url, const KUrl resUri, uint mtime = 0 );
 
         /**
          * Index a single local file or folder (files in a folder will
@@ -61,13 +61,15 @@ namespace Nepomuk {
          * as the above except that it saves an addditional stat of the
          * file.
          */
-        void indexFile( const QFileInfo& info, const KUrl resUri, uint mtime=0 );
+        bool indexFile( const QFileInfo& info, const KUrl resUri, uint mtime=0 );
 
         /**
          * Index a file whose contents are provided via standard input.
          */
-        void indexStdin( const KUrl resUri, uint mtime=0 );
+        bool indexStdin( const KUrl resUri, uint mtime=0 );
         
+        QString lastError() const;
+
     private:
         class Private;
         Private* const d;
diff --git a/services/fileindexer/indexer/main.cpp b/services/fileindexer/indexer/main.cpp
index 72d373a..ebf778a 100644
--- a/services/fileindexer/indexer/main.cpp
+++ b/services/fileindexer/indexer/main.cpp
@@ -1,7 +1,7 @@
 /*
    This file is part of the Nepomuk KDE project.
    Copyright (C) 2010-11 Vishesh Handa <handa.vish@gmail.com>
-   Copyright (C) 2010 Sebastian Trueg <trueg@kde.org>
+   Copyright (C) 2010-2011 Sebastian Trueg <trueg@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@
 
 #include <QtCore/QCoreApplication>
 #include <QtCore/QDir>
+#include <QtCore/QTextStream>
 
 #include <KDebug>
 #include <KUrl>
@@ -45,7 +46,7 @@ int main(int argc, char *argv[])
                          "1.0",
                          ki18n("NepomukIndexer indexes the contents of a file and saves the results in Nepomuk"),
                          KAboutData::License_LGPL_V2,
-                         ki18n("(C) 2011, Vishesh Handa"));
+                         ki18n("(C) 2011, Vishesh Handa, Sebastian Trueg"));
     aboutData.addAuthor(ki18n("Vishesh Handa"), ki18n("Current maintainer"), "handa.vish@gmail.com");
     aboutData.addCredit(ki18n("Sebastian Trüg"), ki18n("Developer"), "trueg@kde.org");
     
@@ -69,8 +70,14 @@ int main(int argc, char *argv[])
 
     if( args->count() == 0 ) {
         Nepomuk::Indexer indexer;
-        indexer.indexStdin( uri, mtime );
-        return 0;
+        if( !indexer.indexStdin( uri, mtime ) ) {
+            QTextStream s(stdout);
+            s << indexer.lastError();
+            return 1;
+        }
+        else {
+            return 0;
+        }
     }
     else if( args->isSet("clear") ) {
         Nepomuk::clearIndexedData( args->url(0) );
@@ -79,8 +86,14 @@ int main(int argc, char *argv[])
     }
     else {
         Nepomuk::Indexer indexer;
-        indexer.indexFile( args->url(0), uri, mtime );
-        kDebug() << "Indexed data for" << args->url(0);
-        return 0;
+        if( !indexer.indexFile( args->url(0), uri, mtime ) ) {
+            QTextStream s(stdout);
+            s << indexer.lastError();
+            return 1;
+        }
+        else {
+            kDebug() << "Indexed data for" << args->url(0);
+            return 0;
+        }
     }
 }
diff --git a/services/fileindexer/indexer/nepomukindexwriter.cpp b/services/fileindexer/indexer/nepomukindexwriter.cpp
index b13cc25..6f30a80 100644
--- a/services/fileindexer/indexer/nepomukindexwriter.cpp
+++ b/services/fileindexer/indexer/nepomukindexwriter.cpp
@@ -238,6 +238,8 @@ public:
 
     // Some services may need to force a specific resource uri
     QUrl resourceUri;
+
+    QString lastError;
 };
 
 
@@ -528,7 +530,10 @@ void Nepomuk::StrigiIndexWriter::finishAnalysis( const AnalysisResult* idx )
     job->setAutoDelete(false);
     job->exec();
     if( job->error() ) {
-        kDebug() << job->errorString();
+        d->lastError = job->errorString();
+    }
+    else {
+        d->lastError.clear();
     }
 
     // cleanup
@@ -564,3 +569,9 @@ void Nepomuk::StrigiIndexWriter::forceUri(const QUrl& uri)
 {
     d->resourceUri = uri;
 }
+
+
+QString Nepomuk::StrigiIndexWriter::lastError() const
+{
+    return d->lastError;
+}
diff --git a/services/fileindexer/indexer/nepomukindexwriter.h b/services/fileindexer/indexer/nepomukindexwriter.h
index 75cadbb..5a70dce 100644
--- a/services/fileindexer/indexer/nepomukindexwriter.h
+++ b/services/fileindexer/indexer/nepomukindexwriter.h
@@ -26,6 +26,7 @@
 
 class KUrl;
 class QUrl;
+class QString;
 
 namespace Nepomuk {
 
@@ -74,6 +75,11 @@ namespace Nepomuk {
 
         void forceUri( const QUrl & uri );
 
+        /**
+         * Retrieve the last error that occurred or an empty string if there was none.
+         */
+        QString lastError() const;
+
     private:
         class Private;
         Private* d;
diff --git a/services/fileindexer/indexscheduler.cpp b/services/fileindexer/indexscheduler.cpp
index 8d6893e..4fecc2f 100644
--- a/services/fileindexer/indexscheduler.cpp
+++ b/services/fileindexer/indexscheduler.cpp
@@ -38,6 +38,7 @@
 #include <KDebug>
 #include <KTemporaryFile>
 #include <KUrl>
+#include <KStandardDirs>
 
 #include "resource.h"
 #include "resourcemanager.h"
@@ -167,6 +168,11 @@ Nepomuk::IndexScheduler::IndexScheduler( QObject* parent )
       m_indexingDelay( 0 ),
       m_currentIndexerJob( 0 )
 {
+    // remove old indexing error log
+    if(FileIndexerConfig::self()->isDebugModeEnabled()) {
+        QFile::remove(KStandardDirs::locateLocal("data", QLatin1String("nepomuk/file-indexer-error-log")));
+    }
+
     m_cleaner = new IndexCleaner(this);
     connect( m_cleaner, SIGNAL(finished(KJob*)), this, SLOT(slotCleaningDone()) );
     m_cleaner->start();
diff --git a/services/fileindexer/nepomukindexer.cpp b/services/fileindexer/nepomukindexer.cpp
index d89a6b8..9588c99 100644
--- a/services/fileindexer/nepomukindexer.cpp
+++ b/services/fileindexer/nepomukindexer.cpp
@@ -21,6 +21,7 @@
 
 #include "nepomukindexer.h"
 #include "util.h"
+#include "fileindexerconfig.h"
 
 #include "resource.h"
 
@@ -30,30 +31,30 @@
 #include <KStandardDirs>
 
 #include <QtCore/QFileInfo>
+#include <QtCore/QFile>
+#include <QtCore/QTextStream>
 
 
 Nepomuk::Indexer::Indexer(const KUrl& localUrl, QObject* parent)
     : KJob(parent),
-      m_url( localUrl ),
-      m_exitCode( -1 )
+      m_url( localUrl )
 {
 }
 
 Nepomuk::Indexer::Indexer(const QFileInfo& info, QObject* parent)
     : KJob(parent),
-      m_url( info.absoluteFilePath() ),
-      m_exitCode( -1 )
+      m_url( info.absoluteFilePath() )
 {
 }
 
 void Nepomuk::Indexer::start()
 {
     const QString exe = KStandardDirs::findExe(QLatin1String("nepomukindexer"));
-    m_process = new KProcess( this );
-    m_process->setProgram( exe, QStringList() << m_url.toLocalFile() );
-
     kDebug() << "Running" << exe << m_url.toLocalFile();
 
+    m_process = new KProcess( this );
+    m_process->setProgram( exe, QStringList() << m_url.toLocalFile() );
+    m_process->setOutputChannelMode(KProcess::OnlyStdoutChannel);
     connect( m_process, SIGNAL(finished(int)), this, SLOT(slotIndexedFile(int)) );
     m_process->start();
 }
@@ -62,8 +63,13 @@ void Nepomuk::Indexer::start()
 void Nepomuk::Indexer::slotIndexedFile(int exitCode)
 {
     kDebug() << "Indexing of " << m_url.toLocalFile() << "finished with exit code" << exitCode;
-    m_exitCode = exitCode;
-
+    if(exitCode == 1 && FileIndexerConfig::self()->isDebugModeEnabled()) {
+        QFile errorLogFile(KStandardDirs::locateLocal("data", QLatin1String("nepomuk/file-indexer-error-log"), true));
+        if(errorLogFile.open(QIODevice::Append)) {
+            QTextStream s(&errorLogFile);
+            s << m_url.toLocalFile() << ": " << QString::fromLocal8Bit(m_process->readAllStandardOutput()) << endl;
+        }
+    }
     emitResult();
 }
 
diff --git a/services/fileindexer/nepomukindexer.h b/services/fileindexer/nepomukindexer.h
index 5b14787..51930ba 100644
--- a/services/fileindexer/nepomukindexer.h
+++ b/services/fileindexer/nepomukindexer.h
@@ -78,7 +78,6 @@ namespace Nepomuk {
     private:
         KUrl m_url;
         KProcess* m_process;
-        int m_exitCode;
     };
 }
 
