gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog libbase/log.cpp libbase/log.h


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog libbase/log.cpp libbase/log.h
Date: Wed, 20 Feb 2008 09:38:55 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/02/20 09:38:55

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

Log message:
                * libbase/log.{cpp,h}: General cleanup: pass strings by const
                  reference. Drop overloaded operators for LogFile class in 
favour
                  of the template that was already there. Remove unused Verbose 
class.
                  Comment out apparently unused but possible useful methods 
                  getEntry() and getState(). Drop unused variables. Write the 
same
                  to stdout as to logfile; move filtering of debug messages to 
the
                  logging functions. Add but comment out new boost::format 
logging
                  functions.
        
        It probably isn't the time to add boost::format just before a release, 
so all the new methods are commented out. That also gives time for discussion 
before any definite changes get made (or not). A boost::format typedef or 
perhaps better a macro LOG boost::format(_(x)); would make logging calls 
shorter and more likely to be passed to gettext.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5697&r2=1.5698
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.cpp?cvsroot=gnash&r1=1.62&r2=1.63
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/log.h?cvsroot=gnash&r1=1.64&r2=1.65

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5697
retrieving revision 1.5698
diff -u -b -r1.5697 -r1.5698
--- ChangeLog   20 Feb 2008 05:17:19 -0000      1.5697
+++ ChangeLog   20 Feb 2008 09:38:54 -0000      1.5698
@@ -1,3 +1,14 @@
+2008-02-20 Benjamin Wolsey <address@hidden>
+
+       * libbase/log.{cpp,h}: General cleanup: pass strings by const
+         reference. Drop overloaded operators for LogFile class in favour
+         of the template that was already there. Remove unused Verbose class.
+         Comment out apparently unused but possible useful methods 
+         getEntry() and getState(). Drop unused variables. Write the same
+         to stdout as to logfile; move filtering of debug messages to the
+         logging functions. Add but comment out new boost::format logging
+         functions.
+
 2008-02-19  Rob Savoye  <address@hidden>
 
        * doc/C/gnash.xml: Beat back into a semblance of shape. Still
@@ -7,8 +18,8 @@
 2008-02-19 Benjamin Wolsey <address@hidden>
 
        * libbase/log.{h,cpp}: drop log_msg.
-       * everywhere: replace unspecific log_msg with appropriate log call; 
mainly
-         log_debug but occasionally error, parse or security.
+       * everywhere: replace unspecific log_msg with appropriate log call;
+         mainly log_debug but occasionally error, parse or security.
 
 2008-02-19  Rob Savoye  <address@hidden>
 

Index: libbase/log.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/log.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -b -r1.62 -r1.63
--- libbase/log.cpp     19 Feb 2008 19:20:50 -0000      1.62
+++ libbase/log.cpp     20 Feb 2008 09:38:54 -0000      1.63
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: log.cpp,v 1.62 2008/02/19 19:20:50 bwy Exp $ */
+/* $Id: log.cpp,v 1.63 2008/02/20 09:38:54 bwy Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
@@ -29,6 +29,7 @@
 #include <fstream>
 #include <string>
 #include <cstring>
+//#include <boost/format.hpp>
 
 #if defined(_WIN32) && defined(WIN32)
 // Required for SYSTEMTIME definitions
@@ -39,24 +40,17 @@
 # include <unistd.h>
 #endif
 
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-#include <libxml/xmlreader.h>
 #include <ctime>
-/* #define BOOST_HAS_THREADS 1
-   This should be set by boost itself.
-*/
-
 
 #include "log.h"
 
-using namespace std;
-
+using std::cout;
+using std::endl;
 
 namespace gnash {
 
 // static data to be shared amongst all classes.
-ofstream LogFile::_console;
+//ofstream LogFile::_console;
 int LogFile::_verbose = 0;
 bool LogFile::_actiondump = false;
 bool LogFile::_parserdump = false;
@@ -132,8 +126,8 @@
 }
 
 // FIXME: localize these, so they print local regional timestamps.
-ostream&
-timestamp(ostream& x) {
+std::ostream&
+timestamp(std::ostream& x) {
     time_t t;
     char buf[10];
 
@@ -145,7 +139,7 @@
 }
 
 
-string
+std::string
 timestamp() {
 
     time_t t;
@@ -158,11 +152,9 @@
     std::stringstream ss;
     ss << getpid() << "] " << buf;
     return ss.str();
-    //string sbuf = buf;
-    //return sbuf;
 }
 
-ostream& datetimestamp(ostream& x) {
+std::ostream& datetimestamp(std::ostream& x) {
     time_t t;
     char buf[20];
 
@@ -206,10 +198,18 @@
     va_end (ap);
 }
 
+//void
+//logTrace(const boost::format& fmt)
+//{
+//    dbglogfile.log(N_("TRACE"), fmt.str());
+//}
+
 void
 log_debug(const char* fmt, ...)
 {
 
+    if (dbglogfile.getVerbosity() < DEBUGLEVEL) return;
+
     va_list ap;
     char tmp[BUFFER_SIZE];
 
@@ -227,6 +227,13 @@
     va_end (ap);
 }
 
+//void
+//logDebug(const boost::format& fmt)
+//{
+//    if (dbglogfile.getVerbosity() < DEBUGLEVEL) return;
+//    dbglogfile.log(N_("DEBUG"), fmt.str());
+//}
+
 void
 log_action(const char* fmt, ...)
 {
@@ -243,6 +250,15 @@
     dbglogfile.setStamp(stamp);
 }
 
+//void
+//logAction(const boost::format& fmt)
+//{
+//    bool stamp = dbglogfile.getStamp();
+//    dbglogfile.setStamp(false);
+//    dbglogfile.log(fmt.str());
+//    dbglogfile.setStamp(stamp);
+//}
+
 void
 log_parse(const char* fmt, ...)
 {
@@ -259,6 +275,12 @@
     va_end (ap);
 }
 
+//void
+//logParse(const boost::format& fmt)
+//{
+//    dbglogfile.log(fmt.str());
+//}
+
 // Printf-style error log.
 void
 log_error(const char* fmt, ...)
@@ -275,6 +297,12 @@
     va_end (ap);
 }
 
+//void
+//logError(const boost::format& fmt)
+//{
+//    dbglogfile.log(N_("ERROR"), fmt.str());
+//}
+
 void
 log_unimpl(const char* fmt, ...)
 {
@@ -290,6 +318,12 @@
     va_end (ap);
 }
 
+//void
+//logUnimpl(const boost::format& fmt)
+//{
+//    dbglogfile.log(N_("UNIMPLEMENTED"), fmt.str());
+//}
+
 void
 log_security(const char* fmt, ...)
 {
@@ -305,6 +339,12 @@
     va_end (ap);
 }
 
+//void
+//logSecurity(const boost::format& fmt)
+//{
+//    dbglogfile.log(N_("SECURITY"), fmt.str());
+//}
+
 void
 log_swferror(const char* fmt, ...)
 {
@@ -320,6 +360,12 @@
     va_end (ap);
 }
 
+//void
+//logSWFError(const boost::format& fmt)
+//{
+//    dbglogfile.log(N_("MALFORMED SWF"), fmt.str());
+//}
+
 void
 log_aserror(const char* fmt, ...)
 {
@@ -335,14 +381,14 @@
     va_end (ap);
 }
 
-const char *
-LogFile::getEntry(void)
-{
-    return _logentry.c_str();
-}
+//void
+//logASError(const boost::format& fmt)
+//{
+//    dbglogfile.log(N_("ACTIONSCRIPT ERROR"), fmt.str());
+//}
 
 void
-LogFile::log(const char* msg)
+LogFile::log(const std::string& msg)
 {
     boost::mutex::scoped_lock lock(_ioMutex);
 
@@ -351,7 +397,7 @@
 }
 
 void
-LogFile::log(const char* label, const char* msg)
+LogFile::log(const std::string& label, const std::string& msg)
 {
     boost::mutex::scoped_lock lock(_ioMutex);
 
@@ -360,14 +406,13 @@
 }
 
 // Default constructor
-LogFile::LogFile (void)
+LogFile::LogFile ()
        :
        _state(CLOSED),
        _stamp(true),
-       _write(true),
-       _trace(false)
+       _write(true)
 {
-    string loadfile;
+    std::string loadfile;
 
 
     RcInitFile& rcfile = RcInitFile::getDefaultInstance();
@@ -381,6 +426,12 @@
     openLog(loadfile);
 }
 
+LogFile::~LogFile()
+{
+       if (_state == OPEN) closeLog();
+}
+
+
 bool
 LogFile::openLog (const std::string& filespec)
 {
@@ -391,7 +442,7 @@
     }
 
     // Append, don't truncate, the log file
-    _outstream.open (filespec.c_str(), ios::app); // ios::out
+    _outstream.open (filespec.c_str(), std::ios::app); // ios::out
     if( ! _outstream ) {
        // Can't use log_error here...
         std::cerr << "ERROR: can't open debug log file " << filespec << " for 
appending." << std::endl;
@@ -434,242 +485,30 @@
     return true;
 }
 
-/// \brief print a char
-LogFile&
-LogFile::operator << (char x)
-{
-    if (_verbose) {
-       cout << x;
-    }
-
-    if (_write) {
-       _outstream << x;
-    }
-
-    _state = INPROGRESS;
-
-  return *this;
-}
-
-/// \brief print a long
-LogFile&
-LogFile::operator << (long x)
-{
-    if (_verbose) {
-       cout << x;
-    }
-
-    if (_write) {
-       _outstream << x;
-    }
-
-    _state = INPROGRESS;
-
-  return *this;
-}
-
-/// \brief print an unsigned integer
-LogFile&
-LogFile::operator << (unsigned int x)
-{
-    if (_verbose) {
-       cout << x;
-    }
-
-    if (_write) {
-       _outstream << x;
-    }
-
-    _state = INPROGRESS;
-
-    return *this;
-}
-
-/// \brief print an unsigned long
-LogFile&
-LogFile::operator << (unsigned long x)
-{
-    if (_verbose) {
-       cout << x;
-    }
-
-    if (_write) {
-       _outstream << x;
-    }
-
-    _state = INPROGRESS;
-
-    return *this;
-}
-
-/// \brief print a float
-LogFile&
-LogFile::operator << (float x)
-{
-    if (_verbose > 0) {
-       cout << x;
-    }
-
-    if (_write) {
-       _outstream << x;
-    }
-
-    _state = INPROGRESS;
-
-  return *this;
-}
-
-/// \brief print a double
-LogFile&
-LogFile::operator << (double &x)
-{
-    if (_verbose) {
-       cout << x;
-    }
-
-    if (_write) {
-       _outstream << x;
-    }
-    _state = INPROGRESS;
-
-    return *this;
-}
-
-/// \brief print an integer
-LogFile&
-LogFile::operator << (int x)
-{
-
-    if (_verbose) {
-       cout << x;
-    }
-
-    if (_write) {
-       _outstream << x;
-    }
-
-    _state = INPROGRESS;
-
-    return *this;
-}
-
-/// \brief print a pointer
-LogFile&
-LogFile::operator << (void *ptr)
-{
-    if (_verbose) {
-       cout << ptr;
-    }
-
-    if (_write) {
-       _outstream << ptr;
-    }
-
-    _state = INPROGRESS;
+/// \brief print a string
+///
 
-    return *this;
-}
 
-/// \brief print an STL string
 LogFile&
 LogFile::operator << (const std::string &s)
 {
-    if (_verbose) {
-       cout << s;
-    }
-
-    if (_write) {
-       _outstream << s;
-    }
-
-    _state = INPROGRESS;
-
-    return *this;
-}
-
-/// \brief print a const char * string
-///
-/// This function is more complex than the other logging functions
-/// because it has hooks to look for the TRACE: keyword for logging
-/// function calls. We always want these to be logged to the disk
-/// file, but optionally printed to the terminal window.
-///
-/// Since the tracing functions use varargs, they always become a
-/// const char * string after processing the arguments. That means we
-/// can look for the keyword to determine what to do.
-LogFile&
-LogFile::operator << (const char *str)
-{
-    string c(str);
 
     _logentry = timestamp();
     _logentry += ": ";
 
-    // See if we have the TRACE keyword
-    if (strstr(str, N_("DEBUG: "))) {
-       _trace = true;
-    }
-
-    if (_stamp == true && (_state == IDLE || _state == OPEN)) {
+    if (_stamp == true && (_state == IDLE || _state == OPEN))
+    {
        _state = INPROGRESS;
-       if (_trace) {
-           if (_verbose >= TRACELEVEL) {
-               cout << _logentry  << c;
+        if (_verbose) cout << _logentry  << s;
+        if (_write) _outstream << _logentry << s;
            }
-       } else {
-           if (_verbose) {
-               cout << _logentry  << c;
-           }
-       }
-       if (_write) {
-           _outstream << _logentry << c;
-       }
-    } else {
-       if (_trace) {
-           if (_verbose >= TRACELEVEL) {
-               cout << c;
-           }
-       } else {
-           if (_verbose) {
-               cout << c;
-           }
-       }
-       if (_write) {
-           _outstream << c;
-       }
-    }
-    _logentry += c;
-
-    return *this;
-}
-
-LogFile&
-LogFile::operator << (unsigned char const *c)
-{
-    _logentry = timestamp();
-    _logentry += ": ";
-
-    if (c == -0) {
-      return *this;
+    else
+    {
+        if (_verbose) cout  << s;
+        if (_write) _outstream << s;   
     }
 
-    if (_stamp == true && (_state == IDLE || _state == OPEN)) {
-       _state = INPROGRESS;
-       if (_verbose) {
-           cout << _logentry  << c;
-       }
-       if (_write) {
-           _outstream << _logentry << c;
-       }
-    } else {
-       if (_verbose) {
-           cout << c;
-       }
-       if (_write) {
-           _outstream << c;
-       }
-    }
-    _logentry += (const char*)c;
+    _logentry.append(s);
 
     return *this;
 }
@@ -678,23 +517,16 @@
 LogFile&
 LogFile::operator << (std::ostream & (&)(std::ostream &))
 {
-    if (_trace) {
-       if (_verbose) {
-           cout << endl;
-       }
-    } else {
-       if (_verbose) {
-           cout << endl;
-       }
-    }
 
-    if (_write) {
+    if (_verbose) cout << endl;
+
+    if (_write)
+    {
        _outstream << endl;;
        _outstream.flush();
     }
 
     _state = IDLE;
-    _trace = false;
 
     return *this;
 }

Index: libbase/log.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/log.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -b -r1.64 -r1.65
--- libbase/log.h       19 Feb 2008 19:20:50 -0000      1.64
+++ libbase/log.h       20 Feb 2008 09:38:55 -0000      1.65
@@ -32,12 +32,12 @@
 #define N_(String) gettext_noop (String)
 
 #include "rc.h" // for IF_VERBOSE_* implementation
-//#include "tu_config.h"
 
 #include <fstream>
 #include <sstream>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
+//#include <boost/format.hpp>
 
 // the default name for the debug log
 #define DEFAULT_LOGFILE "gnash-dbg.log"
@@ -50,14 +50,7 @@
 extern std::ostream& stampoff(std::ostream& x);
 extern std::ostream& timestamp(std::ostream& x);
 extern std::ostream& datetimestamp(std::ostream& x);
-#define TRACELEVEL 2
-
-class DSOLOCAL Verbose {
-    int level;
-public:
-    Verbose(int l) { level = l; }
-    friend std::ostream& operator<<(std::ostream&, Verbose&);
-};
+#define DEBUGLEVEL 2
 
 // This is a basic file logging class
 class DSOEXPORT LogFile {
@@ -65,18 +58,14 @@
 
     static LogFile& getDefaultInstance();
 
-    ~LogFile(void) {
-       if (_state == OPEN) {
-           closeLog();
-       }
-    }
+    ~LogFile();
 
-    enum file_state {
+    enum fileState {
        CLOSED,
        OPEN,
        INPROGRESS,
        IDLE
-    } _state;
+    };
 
     /// Intended for use by log_*(). Thread-safe (locks _ioMutex)
     //
@@ -86,18 +75,18 @@
     /// @param msg
     ///                The message string ie: "bah" for "ERROR: bah"
     ///
-    void log(const char* label, const char* msg);
+    void log(const std::string& msg, const std::string& msg);
 
     /// Intended for use by log_*(). Thread-safe (locks _ioMutex)
     //
     /// @param msg
     ///                The message to print
     ///
-    void log(const char* msg);
+    void log(const std::string& msg);
     
-    file_state GetState (void) { return _state; }
+    //fileState getState () { return _state; }
 
-    const char *getEntry(void);
+    //const std::string& getEntry() { return _logentry; }
     
     /// Open the specified file to write logs on disk
     //
@@ -111,87 +100,95 @@
     //
     /// Does NOT lock _ioMutex (should it?)
     ///
-    bool removeLog(void);
+    bool removeLog();
 
     /// Close the log file
     //
     /// Locks _ioMutex to prevent race conditions accessing _outstream
     ///
-    bool closeLog(void);
+    bool closeLog();
 
     // accessors for the verbose level
-    void setVerbosity (void) {
+    void setVerbosity () {
        _verbose++;
     }
+
     void setVerbosity (int x) {
        _verbose = x;
     }
-    int getVerbosity (void) {
+
+    int getVerbosity () {
        return _verbose;
     }
     
     void setActionDump (int x) {
        _actiondump = x;
     }
-    int getActionDump (void) {
+
+    int getActionDump () {
        return _actiondump;
     }
     
     void setParserDump (int x) {
        _parserdump = x;
     }
-    int getParserDump (void) {
+
+    int getParserDump () {
        return _parserdump;
     }
     
     void setStamp (bool b) {
        _stamp = b;
     }
-    bool getStamp (void) {
+
+    bool getStamp () {
        return _stamp;
     }
+
     void setWriteDisk (bool b) {
        _write = b;
     }
-    bool getWriteDisk (void) {
+
+    bool getWriteDisk () {
        return _write;
     }
     
 private:
 
     // Use getDefaultInstance for getting the singleton
-    LogFile (void);
+    LogFile ();
 
+    /// Mutex for locking I/O during logfile access.
     boost::mutex _ioMutex;
 
-    static std::ofstream _console;
+    /// Stream to write to stdout.
     std::ofstream       _outstream;
+
+    /// How much output is required: 2 or more gives debug output.
     static int          _verbose;
+
+    /// Whether to dump all SWF actions
     static bool                 _actiondump;
+
+    /// Whether to dump parser output
     static bool                 _parserdump;
+
+    /// The state of the log file.
+    fileState _state;
+
     bool                _stamp;
+
+    /// Whether to write the log file to disk.
     bool                _write;
-    bool                _trace;
+
     std::string                 _filespec;
+
     std::string                 _logentry;
+
+    /// For the ostream << operator
     friend std::ostream & operator << (std::ostream &os, LogFile& e);
 
-    LogFile& operator << (char x);
-    LogFile& operator << (int x);
-    LogFile& operator << (long x);
-    LogFile& operator << (unsigned int x);
-    LogFile& operator << (unsigned long x);
-    // These both resolve to an unsigned int.
-    // LogFile& operator << (size_t x);
-    // LogFile& operator << (time_t x);
-    LogFile& operator << (float x);
-    LogFile& operator << (double &x);
-    LogFile& operator << (bool x);
-    LogFile& operator << (void *);
-    LogFile& operator << (const char *);
-    LogFile& operator << (unsigned char const *);
     LogFile& operator << (const std::string &s);
-//     LogFile& operator << (const xmlChar *c);
     LogFile& operator << (std::ostream & (&)(std::ostream &));
 
     /// Print anything that can be printed on a stringstream
@@ -227,6 +224,7 @@
 /// or log_swferror for that.
 ///
 DSOEXPORT void log_error(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logError(const boost::format& fmt);
 
 /// Log a message about unimplemented features.
 //
@@ -235,6 +233,7 @@
 /// implement those features of Flash.
 ///
 DSOEXPORT void log_unimpl(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logUnimpl(const boost::format& fmt);
 
 /// Use only for explicit user traces
 //
@@ -242,12 +241,14 @@
 /// ASHandlers.cpp for ActionTrace
 ///
 DSOEXPORT void log_trace(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logTrace(const boost::format& fmt);
 
 /// Log debug info
 //
 /// Used for function entry/exit tracing.
 ///
 DSOEXPORT void log_debug(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logDebug(const boost::format& fmt);
 
 /// Log action execution info
 //
@@ -257,6 +258,7 @@
 /// at runtime.
 ///
 DSOEXPORT void log_action(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logAction(const boost::format& fmt);
 
 /// Log parsing information
 //
@@ -266,9 +268,11 @@
 /// at runtime.
 ///
 DSOEXPORT void log_parse(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logParse(const boost::format& fmt);
 
 /// Log security information
 DSOEXPORT void log_security(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logSecurity(const boost::format& fmt);
 
 /// Log a malformed SWF error
 //
@@ -281,6 +285,7 @@
 /// at runtime.
 ///
 DSOEXPORT void log_swferror(const char* fmt, ...) GNUC_LOG_ATTRS;
+//DSOEXPORT void logSWFError(const boost::format& fmt);
 
 /// Log an ActionScript error
 //
@@ -293,7 +298,7 @@
 /// at runtime.
 ///
 DSOEXPORT void log_aserror(const char* fmt, ...) GNUC_LOG_ATTRS;
-
+//DSOEXPORT void logASError(const boost::format& fmt);
 
 
 // Define to 0 to completely remove parse debugging at compile-time
@@ -364,7 +369,7 @@
     }
 
     ~__Host_Function_Report__(void) {
-       if (LogFile::getDefaultInstance().getVerbosity() >= TRACELEVEL+1) {
+       if (LogFile::getDefaultInstance().getVerbosity() >= DEBUGLEVEL+1) {
            log_debug("returning");
        }
     }




reply via email to

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