Ejemplo n.º 1
0
	void PropertyConfigurator::configureFromFile(const QString &rConfigFileName,
                                                 LoggerRepository *pLoggerRepository)
	{
	    QFile file(rConfigFileName);
	    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	    {
	        LogError e = LOG4QT_ERROR(QT_TR_NOOP("Unable to open property file '%1'"),
                                      CONFIGURATOR_OPENING_FILE_ERROR,
                                      "Log4Qt::PropertyConfigurator");
	        e << rConfigFileName;
	        e.addCausingError(LogError(file.errorString(), file.error()));
	        logger()->error(e);
	        return;
	    }
		Properties properties;
		properties.load(&file);
        if (file.error())
        {
            LogError e = LOG4QT_ERROR(QT_TR_NOOP("Unable to read property file '%1'"),
                                      CONFIGURATOR_READING_FILE_ERROR,
                                      "Log4Qt::PropertyConfigurator");
            e << rConfigFileName;
            e.addCausingError(LogError(file.errorString(), file.error()));
            logger()->error(e);
            return;
        }
		configureFromProperties(properties, pLoggerRepository);
	}
Ejemplo n.º 2
0
    bool FileAppender::removeFile(QFile &rFile) const
	{
        if (rFile.remove())
        	return true;
        
    	LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to remove file '%1' for appender '%2'"),
                                         APPENDER_REMOVE_FILE_ERROR);
        e << rFile.fileName() << name();
        e.addCausingError(LogError(rFile.errorString(), rFile.error()));
        logger()->error(e);
        return false;
    }
Ejemplo n.º 3
0
    bool FileAppender::renameFile(QFile &rFile,
                                  const QString &rFileName) const
	{
        logger()->debug("Renaming file '%1' to '%2'", rFile.fileName(), rFileName);
        if (rFile.rename(rFileName))
        	return true;
        
        LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to rename file '%1' to '%2' for appender '%3'"),
                                         APPENDER_RENAMING_FILE_ERROR);
        e << rFile.fileName() << rFileName << name();
        e.addCausingError(LogError(rFile.errorString(), rFile.error()));
        logger()->error(e);
        return false;
    }
Ejemplo n.º 4
0
    bool FileAppender::handleIoErrors() const
	{
	    // Q_ASSERT_X(, "FileAppender::handleIoErrors()", "Lock must be held by caller")
	
	    if (mpFile->error() == QFile::NoError)
	        return false;
	    
	    LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to write to file '%1' for appender '%2'"),
                                         APPENDER_WRITING_FILE_ERROR);
	    e << mFileName << name();
	    e.addCausingError(LogError(mpFile->errorString(), mpFile->error()));
	    logger()->error(e);
	    return true;
	}
Ejemplo n.º 5
0
	void FileAppender::openFile()
	{
	    Q_ASSERT_X(mpFile == 0 && mpTextStream == 0, "FileAppender::openFile()", "Opening file without closing previous file");
	    
        QFileInfo file_info(QApplication::applicationDirPath() + "/" + mFileName);
	    QDir parent_dir = file_info.dir();
	    if (!parent_dir.exists())
	    {
	        logger()->trace("Creating missing parent directory for file %1", mFileName);
	        QString name = parent_dir.dirName();
	        parent_dir.cdUp();
	        parent_dir.mkdir(name);
	    }

	    
        mpFile = new QFile(QApplication::applicationDirPath() + "/" + mFileName);
	    QFile::OpenMode mode = QIODevice::WriteOnly | QIODevice::Text;
	    if (mAppendFile)
	        mode |= QIODevice::Append;
	    else
	        mode |= QIODevice::Truncate;
	    if (!mBufferedIo)
	        mode |= QIODevice::Unbuffered;
	    if (!mpFile->open(mode))
	    {
	        LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to open file '%1' for appender '%2'"),
                                             APPENDER_OPENING_FILE_ERROR);
	        e << mFileName << name();
	        e.addCausingError(LogError(mpFile->errorString(), mpFile->error()));
	        logger()->error(e);
	        return;
	    }
	    mpTextStream = new QTextStream(mpFile);
	    setWriter(mpTextStream);
	    logger()->debug("Opened file '%1' for appender '%2'", mpFile->fileName(), name());
	}
Ejemplo n.º 6
0
void Logger::warn(const LogError &rLogError) const
{
    if (isEnabledFor(Level::WARN_INT))
        forcedLog(Level::WARN_INT, rLogError.toString());
}
Ejemplo n.º 7
0
void Logger::trace(const LogError &rLogError) const
{
    if (isEnabledFor(Level::TRACE_INT))
        forcedLog(Level::TRACE_INT, rLogError.toString());
}
Ejemplo n.º 8
0
void Logger::log(Level level,
                 const LogError &rLogError) const
{
    if (isEnabledFor(level))
        forcedLog(level, rLogError.toString());
}
Ejemplo n.º 9
0
void Logger::info(const LogError &rLogError) const
{
    if (isEnabledFor(Level::INFO_INT))
        forcedLog(Level::INFO_INT, rLogError.toString());
}
Ejemplo n.º 10
0
void Logger::fatal(const LogError &rLogError) const
{
    if (isEnabledFor(Level::FATAL_INT))
        forcedLog(Level::FATAL_INT, rLogError.toString());
}
Ejemplo n.º 11
0
void Logger::error(const LogError &rLogError) const
{
    if (isEnabledFor(Level::ERROR_INT))
        forcedLog(Level::ERROR_INT, rLogError.toString());
}
Ejemplo n.º 12
0
void Logger::debug(const LogError &rLogError) const
{
    if (isEnabledFor(Level::DEBUG_INT))
        forcedLog(Level::DEBUG_INT, rLogError.toString());
}
Ejemplo n.º 13
0
		bool Factory::validateObjectProperty(QMetaProperty &rMetaProperty,
																				 const QString &rProperty,
																				 QObject *pObject)
		{
				// Validate:
				// - No null object pointer
				// - No empty property name
				// - Property exists on the object (QT or Java name)
				// - Property is readable
				// - Property is writable

				const char *p_context = "Log4Qt::Factory";
				LogError e = LOG4QT_ERROR(QT_TR_NOOP("Unable to set property value on object"),
																	CONFIGURATOR_PROPERTY_ERROR,
																	p_context);

				if (!pObject)
				{
						LogError ce = LOG4QT_ERROR(QT_TR_NOOP("Invalid null object pointer"),
																			 0,
																			 p_context);
						e.addCausingError(ce);
						logger()->error(e);
						return false;
				}
				if (rProperty.isEmpty())
				{
						LogError ce = LOG4QT_ERROR(QT_TR_NOOP("Invalid empty property name"),
																			 0,
																			 p_context);
						e.addCausingError(ce);
						logger()->error(e);
						return false;
				}
				const QMetaObject *p_meta_object = pObject->metaObject();
				QString property = rProperty;
				int i = p_meta_object->indexOfProperty(property.toLatin1());
				if (i < 0)
				{
						// Try name with lower case first character. Java properties names
						// start upper case
						property[0] = property[0].toLower();
						i = p_meta_object->indexOfProperty(property.toLatin1());
						if (i < 0)
						{
								LogError ce = LOG4QT_ERROR(QT_TR_NOOP("Property '%1' does not exist in class '%2'"),
																					 0,
																					 p_context);
								ce << property
									 << QString::fromLatin1(pObject->metaObject()->className());
								e.addCausingError(ce);
								logger()->error(e);
								return false;
						}
				}
				rMetaProperty = p_meta_object->property(i);
				if (!rMetaProperty.isWritable())
				{
						LogError ce = LOG4QT_ERROR(QT_TR_NOOP("Property '%1' is not writable in class '%2'"),
																			 0,
																			 p_context);
						ce << property
							 << QString::fromLatin1(pObject->metaObject()->className());
						e.addCausingError(ce);
						logger()->error(e);
						return false;
				}

				return true;
		}