[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog cygnal/cygnal.cpp libbase/log.c...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog cygnal/cygnal.cpp libbase/log.c... |
Date: |
Fri, 22 Feb 2008 11:24:38 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/02/22 11:24:37
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&r1=1.5722&r2=1.5723
http://cvs.savannah.gnu.org/viewcvs/gnash/cygnal/cygnal.cpp?cvsroot=gnash&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.cpp?cvsroot=gnash&r1=1.63&r2=1.64
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.h?cvsroot=gnash&r1=1.67&r2=1.68
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5722
retrieving revision 1.5723
diff -u -b -r1.5722 -r1.5723
--- ChangeLog 22 Feb 2008 09:59:56 -0000 1.5722
+++ ChangeLog 22 Feb 2008 11:24:36 -0000 1.5723
@@ -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.22
diff -u -b -r1.21 -r1.22
--- cygnal/cygnal.cpp 19 Feb 2008 19:20:48 -0000 1.21
+++ cygnal/cygnal.cpp 22 Feb 2008 11:24:37 -0000 1.22
@@ -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.64
diff -u -b -r1.63 -r1.64
--- libbase/log.cpp 20 Feb 2008 09:38:54 -0000 1.63
+++ libbase/log.cpp 22 Feb 2008 11:24:37 -0000 1.64
@@ -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.64 2008/02/22 11:24:37 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.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- libbase/log.h 21 Feb 2008 14:24:09 -0000 1.67
+++ libbase/log.h 22 Feb 2008 11:24:37 -0000 1.68
@@ -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);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog cygnal/cygnal.cpp libbase/log.c...,
Sandro Santilli <=