diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc
index 409a1cd59daec061038e61d83a5be85fe90bdb5e..8358e8fa0e4935cf090f2d43fd77f754952ef137 100644
--- a/preprocessor/ModFile.cc
+++ b/preprocessor/ModFile.cc
@@ -276,12 +276,11 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all
               << "%" << endl
               << "global_initialization;" << endl
               << "diary off;" << endl
-              << "warning_old_state = warning;" << endl
-              << "warning off;" << endl
-              << "delete " << basename << ".log;" << endl
-              << "warning warning_old_state" << endl
               << "logname_ = '" << basename << ".log';" << endl
-              << "diary " << basename << ".log" << endl;
+              << "if exist(logname_, 'file')" << endl
+              << "    delete(logname_)" << endl
+              << "end" << endl
+              << "diary(logname_)" << endl;
 
   cout << "Processing outputs ...";