gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog cygnal/cygnal.cpp libbase/log.c... [relea


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog cygnal/cygnal.cpp libbase/log.c... [release_0_8_2_rc1]
Date: Fri, 22 Feb 2008 11:25:08 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Branch:         release_0_8_2_rc1
Changes by:     Sandro Santilli <strk>  08/02/22 11:25:08

Modified files:
        .              : ChangeLog 
        cygnal         : cygnal.cpp 
        libbase        : log.cpp log.h 

Log message:
        Have LogFile open a log file only on demand.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&only_with_tag=release_0_8_2_rc1&r1=1.5711.2.9&r2=1.5711.2.10
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cygnal.cpp?cvsroot=gnash&only_with_tag=release_0_8_2_rc1&r1=1.21&r2=1.21.2.1
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.cpp?cvsroot=gnash&only_with_tag=release_0_8_2_rc1&r1=1.63&r2=1.63.2.1
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.h?cvsroot=gnash&only_with_tag=release_0_8_2_rc1&r1=1.65.2.2&r2=1.65.2.3

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5711.2.9
retrieving revision 1.5711.2.10
diff -u -b -r1.5711.2.9 -r1.5711.2.10
--- ChangeLog   22 Feb 2008 10:06:18 -0000      1.5711.2.9
+++ ChangeLog   22 Feb 2008 11:25:05 -0000      1.5711.2.10
@@ -1,3 +1,10 @@
+2008-02-22 Sandro Santilli <address@hidden>
+
+       * cygnal/cygnal.cpp: don't call LogFile::openLog explicitly,
+         it should be done automatically now.
+       * libbase/log.{cpp,h}: don't open a log file if not needed
+         (open on demand).
+
 2008-02-22  Rob Savoye  <address@hidden>
 
        * libamf/amf.cpp: Eliminate warnings.

Index: cygnal/cygnal.cpp
===================================================================
RCS file: /sources/gnash/gnash/cygnal/cygnal.cpp,v
retrieving revision 1.21
retrieving revision 1.21.2.1
diff -u -b -r1.21 -r1.21.2.1
--- cygnal/cygnal.cpp   19 Feb 2008 19:20:48 -0000      1.21
+++ cygnal/cygnal.cpp   22 Feb 2008 11:25:07 -0000      1.21.2.1
@@ -140,11 +140,13 @@
 
     crcfile.loadFiles();
 
+#if 0 // this should be automatic
     if (crcfile.getDebugLog().size()) {
        dbglogfile.openLog(crcfile.getDebugLog());
     } else {
        dbglogfile.openLog("/tmp/cygnal-dbg.log");
     }
+#endif
     
     if (crcfile.verbosityLevel() > 0) {
         dbglogfile.setVerbosity(crcfile.verbosityLevel());

Index: libbase/log.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/log.cpp,v
retrieving revision 1.63
retrieving revision 1.63.2.1
diff -u -b -r1.63 -r1.63.2.1
--- libbase/log.cpp     20 Feb 2008 09:38:54 -0000      1.63
+++ libbase/log.cpp     22 Feb 2008 11:25:07 -0000      1.63.2.1
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: log.cpp,v 1.63 2008/02/20 09:38:54 bwy Exp $ */
+/* $Id: log.cpp,v 1.63.2.1 2008/02/22 11:25:07 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
@@ -410,20 +410,11 @@
        :
        _state(CLOSED),
        _stamp(true),
-       _write(true)
+       _write(false)
 {
-    std::string loadfile;
-
-
     RcInitFile& rcfile = RcInitFile::getDefaultInstance();
-    //rcfile.dump();
     _write = rcfile.useWriteLog();
-    loadfile = rcfile.getDebugLog();
-    if ( loadfile.empty() ) loadfile = DEFAULT_LOGFILE;
 
-    // TODO: expand ~ to getenv("HOME") !!
-
-    openLog(loadfile);
 }
 
 LogFile::~LogFile()
@@ -431,21 +422,42 @@
        if (_state == OPEN) closeLog();
 }
 
+bool
+LogFile::openLogIfNeeded ()
+{
+    if (_state != CLOSED) return true;
+    if (!_write) return false;
+
+    RcInitFile& rcfile = RcInitFile::getDefaultInstance();
+
+    std::string loadfile = rcfile.getDebugLog();
+    if ( loadfile.empty() ) loadfile = DEFAULT_LOGFILE;
+
+    // TODO: expand ~ to getenv("HOME") !!
+
+    return openLog(loadfile);
+}
 
 bool
 LogFile::openLog (const std::string& filespec)
 {
-    boost::mutex::scoped_lock lock(_ioMutex);
-    if (_state == OPEN) {
+    // NOTE:
+    // don't need to lock the mutex here, as this method
+    // is intended to be called only by openLogIfNeeded,
+    // which in turn is called by operator<< which is called
+    // by the public log_xxx functions that log themselves
+
+    if (_state != CLOSED) {
+       cout << "Closing previously opened stream" << endl;
         _outstream.close ();
         _state = CLOSED;
     }
 
     // Append, don't truncate, the log file
-    _outstream.open (filespec.c_str(), std::ios::app); // ios::out
-    if( ! _outstream ) {
+    _outstream.open (filespec.c_str(), std::ios::app|std::ios::out); // 
ios::out
+    if( _outstream.fail() ) {
        // Can't use log_error here...
-        std::cerr << "ERROR: can't open debug log file " << filespec << " for 
appending." << std::endl;
+        cout << "ERROR: can't open debug log file " << filespec << " for 
appending." << endl;
         return false;
     }       
 
@@ -480,7 +492,6 @@
     // Ignore the error, we don't care
     unlink(_filespec.c_str());
     _filespec.clear();
-    _logentry.clear();
 
     return true;
 }
@@ -492,23 +503,26 @@
 LogFile&
 LogFile::operator << (const std::string &s)
 {
+    // NOTE: _state will be == INPROGRESS right
 
-    _logentry = timestamp();
-    _logentry += ": ";
+    if (_stamp == true && (_state != INPROGRESS) )
+    {
+       std::string ts = timestamp();
 
-    if (_stamp == true && (_state == IDLE || _state == OPEN))
+        if (_verbose) cout << ts << ": " << s;
+        if (openLogIfNeeded())
     {
+               _outstream << ts << ": " << s;
+       }
         _state = INPROGRESS;
-        if (_verbose) cout << _logentry  << s;
-        if (_write) _outstream << _logentry << s;
     }
     else
     {
         if (_verbose) cout  << s;
-        if (_write) _outstream << s;   
+        if (openLogIfNeeded()) {
+               _outstream << s;   
+       }
     }
-
-    _logentry.append(s);
 
     return *this;
 }
@@ -520,7 +534,7 @@
 
     if (_verbose) cout << endl;
 
-    if (_write)
+    if (openLogIfNeeded())
     {
         _outstream << endl;;
         _outstream.flush();

Index: libbase/log.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/log.h,v
retrieving revision 1.65.2.2
retrieving revision 1.65.2.3
diff -u -b -r1.65.2.2 -r1.65.2.3
--- libbase/log.h       21 Feb 2008 14:30:38 -0000      1.65.2.2
+++ libbase/log.h       22 Feb 2008 11:25:07 -0000      1.65.2.3
@@ -84,18 +84,6 @@
     ///
     void log(const std::string& msg);
     
-    //fileState getState () { return _state; }
-
-    //const std::string& getEntry() { return _logentry; }
-    
-    /// Open the specified file to write logs on disk
-    //
-    /// Locks _ioMutex to prevent race conditions accessing _outstream
-    ///
-    /// @return true on success, false on failure
-    ///
-    bool openLog(const std::string& filespec);
-
     /// Remove the log file
     //
     /// Does NOT lock _ioMutex (should it?)
@@ -155,6 +143,26 @@
     
 private:
 
+    /// Open the specified file to write logs on disk
+    //
+    /// Locks _ioMutex to prevent race conditions accessing _outstream
+    ///
+    /// @return true on success, false on failure
+    ///
+    bool openLog(const std::string& filespec);
+
+    /// \brief
+    /// Open the RcInitFile-specified log file if log write
+    /// is requested. 
+    //
+    /// This method is called before any attempt to write is made.
+    /// It will return true if the file was opened, false if wasn't
+    /// (either not requested or error).
+    ///
+    /// On error, will print a message on stderr
+    ///
+    bool openLogIfNeeded();
+
     // Use getDefaultInstance for getting the singleton
     LogFile ();
 
@@ -183,8 +191,6 @@
 
     std::string                 _filespec;
 
-    std::string                 _logentry;
-
     /// For the ostream << operator
     friend std::ostream & operator << (std::ostream &os, LogFile& e);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]