mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
feat(core): provide a cpp logger
This commit is contained in:
parent
d150c2677a
commit
30cd765871
4 changed files with 144 additions and 10 deletions
|
|
@ -29,8 +29,9 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
cpim/message/cpim-message.h
|
||||
cpim/parser/cpim-grammar.h
|
||||
cpim/parser/cpim-parser.h
|
||||
object/object.h
|
||||
logger/logger.h
|
||||
object/object-p.h
|
||||
object/object.h
|
||||
object/singleton.h
|
||||
utils/general.h
|
||||
utils/utils.h
|
||||
|
|
@ -43,6 +44,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
|
|||
cpim/message/cpim-message.cpp
|
||||
cpim/parser/cpim-grammar.cpp
|
||||
cpim/parser/cpim-parser.cpp
|
||||
logger/logger.cpp
|
||||
object/object.cpp
|
||||
utils/utils.cpp
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@
|
|||
#include <belr/abnf.h>
|
||||
#include <belr/grammarbuilder.h>
|
||||
|
||||
#include "linphone/core.h"
|
||||
|
||||
#include "cpim-grammar.h"
|
||||
#include "logger/logger.h"
|
||||
#include "object/object-p.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
|
|
@ -100,7 +99,7 @@ namespace LinphonePrivate {
|
|||
if (force)
|
||||
header->force(mValue);
|
||||
else if (!header->setValue(mValue)) {
|
||||
ms_fatal("Unable to set value on core header: `%s` => `%s`.", mName.c_str(), mValue.c_str());
|
||||
lWarning() << "Unable to set value on core header: `" << mName << "` => `" << mValue << "`.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +119,8 @@ namespace LinphonePrivate {
|
|||
if (force)
|
||||
header->force(mValue, language);
|
||||
else if (!header->setValue(mValue) || (!language.empty() && !header->setLanguage(language))) {
|
||||
ms_fatal("Unable to set value on subject header: `%s` => `%s`, `%s`.", mName.c_str(), mValue.c_str(), language.c_str());
|
||||
lWarning() << "Unable to set value on subject header: `" <<
|
||||
mName << "` => `" << mValue << "`, `" << language << "`.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ namespace LinphonePrivate {
|
|||
shared_ptr<Message> createMessage () const {
|
||||
size_t size = mHeaders->size();
|
||||
if (size != 2) {
|
||||
ms_fatal("Bad headers lists size.");
|
||||
lWarning() << "Bad headers lists size.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ namespace LinphonePrivate {
|
|||
[](const shared_ptr<const HeaderNode> &headerNode) {
|
||||
return Utils::iequals(headerNode->getName(), "content-type") && headerNode->getValue() == "Message/CPIM";
|
||||
}) == cpimHeaders->cend()) {
|
||||
ms_fatal("No MIME `Content-Type` found!");
|
||||
lWarning() << "No MIME `Content-Type` found!";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ Cpim::Parser::Parser () : Singleton(*new ParserPrivate) {
|
|||
|
||||
d->grammar = builder.createFromAbnf(getGrammar(), make_shared<belr::CoreRules>());
|
||||
if (!d->grammar)
|
||||
ms_fatal("Unable to build CPIM grammar.");
|
||||
lFatal() << "Unable to build CPIM grammar.";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -255,13 +255,13 @@ shared_ptr<Cpim::Message> Cpim::Parser::parseMessage (const string &input) {
|
|||
size_t parsedSize;
|
||||
shared_ptr<Node> node = parser.parseInput("Message", input, &parsedSize);
|
||||
if (!node) {
|
||||
ms_fatal("Unable to parse message.");
|
||||
lWarning() << "Unable to parse message.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<MessageNode> messageNode = dynamic_pointer_cast<MessageNode>(node);
|
||||
if (!messageNode) {
|
||||
ms_fatal("Unable to cast belr result to message node.");
|
||||
lWarning() << "Unable to cast belr result to message node.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
74
src/logger/logger.cpp
Normal file
74
src/logger/logger.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* logger.cpp
|
||||
* Copyright (C) 2017 Belledonne Communications SARL
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "linphone/core.h"
|
||||
|
||||
#include "object/object-p.h"
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using namespace LinphonePrivate;
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace LinphonePrivate {
|
||||
class LoggerPrivate : public ObjectPrivate {
|
||||
public:
|
||||
Logger::Level level;
|
||||
ostringstream os;
|
||||
};
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Logger::Logger (Level level) : Object(*new LoggerPrivate) {
|
||||
L_D(Logger);
|
||||
d->level = level;
|
||||
}
|
||||
|
||||
Logger::~Logger () {
|
||||
L_D(Logger);
|
||||
|
||||
d->os << endl;
|
||||
const string str = d->os.str();
|
||||
|
||||
switch (d->level) {
|
||||
case Debug:
|
||||
ms_debug("%s", str.c_str());
|
||||
break;
|
||||
case Info:
|
||||
ms_message("%s", str.c_str());
|
||||
break;
|
||||
case Warning:
|
||||
ms_warning("%s", str.c_str());
|
||||
break;
|
||||
case Error:
|
||||
ms_error("%s", str.c_str());
|
||||
break;
|
||||
case Fatal:
|
||||
ms_fatal("%s", str.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ostringstream &Logger::getOutput () {
|
||||
L_D(Logger);
|
||||
return d->os;
|
||||
}
|
||||
58
src/logger/logger.h
Normal file
58
src/logger/logger.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* logger.h
|
||||
* Copyright (C) 2017 Belledonne Communications SARL
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LOGGER_H_
|
||||
#define _LOGGER_H_
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "object/object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace LinphonePrivate {
|
||||
class LoggerPrivate;
|
||||
|
||||
class LINPHONE_PUBLIC Logger : public Object {
|
||||
public:
|
||||
enum Level {
|
||||
Debug,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Fatal
|
||||
};
|
||||
|
||||
Logger (Level level);
|
||||
~Logger ();
|
||||
|
||||
std::ostringstream &getOutput ();
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(Logger);
|
||||
L_DISABLE_COPY(Logger);
|
||||
};
|
||||
}
|
||||
|
||||
#define lDebug() LinphonePrivate::Logger(Logger::Debug).getOutput()
|
||||
#define lInfo() LinphonePrivate::Logger(Logger::Info).getOutput()
|
||||
#define lWarning() LinphonePrivate::Logger(Logger::Warning).getOutput()
|
||||
#define lError() LinphonePrivate::Logger(Logger::Error).getOutput()
|
||||
#define lFatal() LinphonePrivate::Logger(Logger::Fatal).getOutput()
|
||||
|
||||
#endif // ifndef _LOGGER_H_
|
||||
Loading…
Add table
Reference in a new issue