-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow a QString in a LOG4CXX_ macro when 'Qt support/integration' is …
…ON (#247) * Update Qt support documentation * Change configuration examples to links * Fix NDC example file name * Improve example code
- Loading branch information
Showing
27 changed files
with
362 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <QCoreApplication> | ||
#include "com/foo/config-qt.h" | ||
#include "com/foo/bar.h" | ||
|
||
int main(int argc, char **argv) { | ||
int result = EXIT_SUCCESS; | ||
QCoreApplication app(argc, argv); | ||
com::foo::ConfigureLogging(); | ||
try { | ||
auto logger = com::foo::getLogger("MyApp"); | ||
LOG4CXX_INFO(logger, QString("Message %1").arg(1)); | ||
com::foo::Bar bar; | ||
bar.doIt(); | ||
LOG4CXX_INFO(logger, QString("Message %1").arg(2)); | ||
} | ||
catch(std::exception&) { | ||
result = EXIT_FAILURE; | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "com/foo/bar.h" | ||
#include "com/foo/config-qt.h" | ||
|
||
using namespace com::foo; | ||
|
||
LoggerPtr Bar::m_logger(getLogger("com.foo.bar")); | ||
|
||
void Bar::doIt() { | ||
LOG4CXX_DEBUG(m_logger, QString("Did it again!") << QString(" - again!")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "config-qt.h" | ||
#include <log4cxx/logmanager.h> | ||
#include <log4cxx-qt/configuration.h> | ||
#include <log4cxx/helpers/loglog.h> | ||
#include <QCoreApplication> | ||
#include <QVector> | ||
#include <QFileInfo> | ||
#include <QDir> | ||
|
||
namespace com { namespace foo { | ||
|
||
// Provide the name of the configuration file to Log4cxx. | ||
// Reload the configuration on a QFileSystemWatcher::fileChanged event. | ||
void ConfigureLogging() { | ||
static struct log4cxx_finalizer { | ||
~log4cxx_finalizer() { | ||
log4cxx::LogManager::shutdown(); | ||
} | ||
} finaliser; | ||
QFileInfo app{QCoreApplication::applicationFilePath()}; | ||
QString basename{app.baseName()}; | ||
QVector<QString> paths = | ||
{ QString(".") | ||
, app.absoluteDir().absolutePath() | ||
}; | ||
QVector<QString> names = | ||
{ QString(basename + ".xml") | ||
, QString(basename + ".properties") | ||
, QString("MyApp.properties") | ||
, QString("log4cxx.xml") | ||
, QString("log4cxx.properties") | ||
, QString("log4j.xml") | ||
, QString("log4j.properties") | ||
}; | ||
#if defined(_DEBUG) | ||
log4cxx::helpers::LogLog::setInternalDebugging(true); | ||
#endif | ||
log4cxx::qt::Configuration::configureFromFileAndWatch(paths, names); | ||
} | ||
|
||
// Retrieve the \c name logger pointer. | ||
auto getLogger(const QString& name) -> LoggerPtr { | ||
return name.isEmpty() | ||
? log4cxx::LogManager::getRootLogger() | ||
: log4cxx::LogManager::getLogger(name.toStdString()); | ||
} | ||
|
||
// Retrieve the \c name logger pointer. | ||
auto getLogger(const char* name) -> LoggerPtr { | ||
return name | ||
? log4cxx::LogManager::getLogger(name) | ||
: log4cxx::LogManager::getRootLogger(); | ||
} | ||
|
||
} } // namespace com::foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef COM_FOO_CONFIG_QT_H_ | ||
#define COM_FOO_CONFIG_QT_H_ | ||
#include <log4cxx-qt/logger.h> | ||
|
||
/// Methods specific to foo.com | ||
namespace com { namespace foo { | ||
|
||
// Provide the name of the configuration file to Log4cxx. | ||
void ConfigureLogging(); | ||
|
||
/// The logger pointer we use | ||
using LoggerPtr = log4cxx::LoggerPtr; | ||
|
||
/// Retrieve the \c name logger pointer. | ||
extern auto getLogger(const QString& name) -> LoggerPtr; | ||
|
||
/// Retrieve the \c name logger pointer. | ||
extern auto getLogger(const char* name = NULL) -> LoggerPtr; | ||
|
||
} } // namespace com::foo | ||
#endif // COM_FOO_CONFIG_QT_H_ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef _LOG4CXX_QT_LOGGER_H | ||
#define _LOG4CXX_QT_LOGGER_H | ||
#include <log4cxx/logger.h> | ||
#include <log4cxx-qt/messagebuffer.h> | ||
#endif // _LOG4CXX_QT_LOGGER_H |
Oops, something went wrong.