diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc
index 7bd8eb1c792642dfea507cdbddfdf6f4f1b89c07..f681b4b1141149155e6cf9c08166afef46badb60 100644
--- a/preprocessor/ModFile.cc
+++ b/preprocessor/ModFile.cc
@@ -263,12 +263,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 ...";