summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2004-06-22 10:36:11 (UTC)
committer mickeyl <mickeyl>2004-06-22 10:36:11 (UTC)
commit9cff98cb70d8e3a69cefe718bf02720134c10bca (patch) (side-by-side diff)
tree750f086afefc20e05b5860bf3065697cb75f98ab /libopie2
parent526031c34fff4e789b05fddbd7effe83ef057361 (diff)
downloadopie-9cff98cb70d8e3a69cefe718bf02720134c10bca.zip
opie-9cff98cb70d8e3a69cefe718bf02720134c10bca.tar.gz
opie-9cff98cb70d8e3a69cefe718bf02720134c10bca.tar.bz2
introduce numeric constants for the odebug output destinations
Diffstat (limited to 'libopie2') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp12
-rw-r--r--libopie2/opiecore/odebug.h7
2 files changed, 13 insertions, 6 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp
index 3bffdd0..d8dfe26 100644
--- a/libopie2/opiecore/odebug.cpp
+++ b/libopie2/opiecore/odebug.cpp
@@ -100,107 +100,107 @@ struct DebugBackend {
void debug( unsigned short level, unsigned int, const QString& data );
private:
void debugFile( const QString&, const QString& data );
void debugMsgB( const QString&, const QString& data );
void debugShel( const QString&, const QString& data );
void debugSysl( int, const QString& );
void debugSock( const QString&, const QString& data );
QCString line( const QString&, const QString& data );
bool m_opened : 1;
QFile *m_file;
QHostAddress m_addr;
int m_port;
QSocketDevice *m_sock;
short m_outp;
};
void DebugBackend::debug(unsigned short level, unsigned int, const QString& data) {
//qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data );
// ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an
// ML: example use. I think it's not necessary to implement such a strategy here.
// ML: Comments?
int priority = 0;
QString caption;
QString lev;
switch( level )
{
case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break;
case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break;
case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break;
default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." );
case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break;
}
if (!oApp && (m_outp == 1)) {
qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" );
m_outp = 2; // need an application object to use MsgBox
}
// gcc 2.9x is dumb and sucks... can you hear it?
//QString areaName = (oApp) ? oApp->appName() : "<unknown>";
QString areaName;
if ( oApp ) areaName = oApp->appName();
else areaName = "<unknown>";
switch( m_outp ) {
- case -1: // ignore
+ case ODEBUG_IGNORE:
return;
- case 0: // File
+ case ODEBUG_FILE:
return debugFile( areaName, data );
- case 1: // Message Box
+ case ODEBUG_MSGBOX:
return debugMsgB( areaName, data );
- case 2:
+ case ODEBUG_STDERR:
return debugShel( areaName,data );
- case 3: // syslog
+ case ODEBUG_SYSLOG:
return debugSysl( priority, data );
- case 4: // socket
+ case ODEBUG_SOCKET:
return debugSock( areaName, data );
}
}
inline void DebugBackend::debugFile(const QString& area, const QString& data) {
/* something went wrong with the file don't bother.. */
if ( m_opened && !m_file )
return;
else if ( !m_opened ) {
m_opened = true;
m_file = new QFile( OGlobalSettings::debugOutput() );
if (!m_file->open( IO_WriteOnly | IO_Append ) ) {
delete m_file; m_file = 0;
qDebug( "ODebug: can't write to file '%s' (%s)", (const char*)OGlobalSettings::debugOutput(),
strerror(errno) );
return;
}
}
/* go to end of file */
m_file->at( m_file->size() );
QCString li = line( area, data );
m_file->writeBlock(li.data(), li.length() );
}
void DebugBackend::debugMsgB( const QString& area, const QString& data ) {
QMessageBox::warning( 0l, "("+area+")", data, ("Ok") );
}
void DebugBackend::debugShel( const QString& are, const QString& data ) {
FILE *output = stderr;
fprintf( output, "%s: %s", are.local8Bit().data(),
data.local8Bit().data() );
}
void DebugBackend::debugSysl( int prio, const QString& data ) {
::syslog( prio, "%s", data.local8Bit().data() );
}
void DebugBackend::debugSock( const QString& are, const QString& data ) {
if ( m_opened && !m_sock )
return;
else if ( !m_opened ){
m_opened = true;
QString destination = OGlobalSettings::debugOutput();
if ( destination && destination.find(":") != -1 ) {
QString host = destination.left( destination.find(":") );
m_port = destination.right( destination.length()-host.length()-1 ).toInt();
diff --git a/libopie2/opiecore/odebug.h b/libopie2/opiecore/odebug.h
index 3851a41..21a6c26 100644
--- a/libopie2/opiecore/odebug.h
+++ b/libopie2/opiecore/odebug.h
@@ -22,96 +22,103 @@
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ODEBUG_H
#define ODEBUG_H
#include <qstring.h>
class QWidget;
class QDateTime;
class QDate;
class QTime;
class QPoint;
class QSize;
class QRect;
class QRegion;
class QStringList;
class QColor;
class QBrush;
namespace Opie {
namespace Core {
class odbgstream;
class ondbgstream;
#ifdef __GNUC__
#define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
#else
#define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
#endif
#define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
#define owarn Opie::Core::odWarning()
#define oerr Opie::Core::odError()
#define odebug Opie::Core::odDebug()
#define ofatal Opie::Core::odFatal()
#define oendl "\n"
+const int ODEBUG_IGNORE = -1;
+const int ODEBUG_FILE = 0;
+const int ODEBUG_MSGBOX = 1;
+const int ODEBUG_STDERR = 2;
+const int ODEBUG_SYSLOG = 3;
+const int ODEBUG_SOCKET = 4;
+
class odbgstreamprivate;
/**
* odbgstream is a text stream that allows you to print debug messages.
* Using the overloaded "<<" operator you can send messages. Usually
* you do not create the odbgstream yourself, but use @ref odDebug() (odebug)
* @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one.
*
* Example:
* <pre>
* int i = 5;
* odebug << "The value of i is " << i << oendl;
* </pre>
* @see odbgstream
*/
/*======================================================================================
* odbgstream
*======================================================================================*/
class odbgstream
{
public:
/**
* @internal
*/
odbgstream(unsigned int _area, unsigned int _level, bool _print = true);
odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true);
odbgstream(odbgstream &str);
odbgstream(const odbgstream &str);
virtual ~odbgstream();
/**
* Prints the given value.
* @param i the boolean to print (as "true" or "false")
* @return this stream
*/
odbgstream &operator<<(bool i);
/**
* Prints the given value.
* @param i the short to print
* @return this stream
*/
odbgstream &operator<<(short i);
/**
* Prints the given value.
* @param i the unsigned short to print
* @return this stream
*/