Commit 7df0371e authored by Julien Bonjean's avatar Julien Bonjean

[#1671] Created new logger

parent f3c80c4b
......@@ -16,6 +16,7 @@ sflphoned_SOURCES = \
accountcreator.cpp \
call.cpp \
account.cpp \
logger.cpp \
numbercleaner.cpp
# Redefine the USE_IAX variable here, so that it could be used in managerimpl
......@@ -63,6 +64,7 @@ noinst_HEADERS = \
account.h \
accountcreator.h \
call.h \
logger.h \
numbercleaner.h
libsflphone_la_LIBADD = \
......
......@@ -31,6 +31,7 @@
#include <sstream>
#include <map>
#include <vector>
#include "logger.h"
#define SFLPHONED_VERSION "0.9.6" /** Version number */
......@@ -72,18 +73,6 @@ static const SOUND_FORMAT INT32 = 0x8;
#define SFLDataAmplitude (32767 >> 4)
#endif
#ifdef SFLDEBUG
#define _debug(...) fprintf(stderr, "[sfl-debug] " __VA_ARGS__)
#define _debugException(...) fprintf(stderr, "[sfl-excep] " __VA_ARGS__ "\n")
#define _debugInit(...) fprintf(stderr, "[sfl-init] " __VA_ARGS__ "\n")
#define _debugAlsa(...) fprintf(stderr, "[alsa-debug] " __VA_ARGS__ )
#else
#define _debug(...)
#define _debugException(...)
#define _debugInit(...)
#define _debugAlsa(...)
#endif
#define PROGNAME "sflphoned" /** Binary name */
#define PROGDIR "sflphone" /** Program directory */
#define RINGDIR "ringtones" /** Ringtones directory */
......
#include "logger.h"
#include <syslog.h>
#include <stdarg.h>
void Logger::log(const int level, const char* format, ...)
{
va_list ap;
string prefix = "<> ";
char buffer[1024];
string message = "";
string color_prefix = "";
switch(level)
{
case LOG_ERR:
{
prefix = "<error> ";
color_prefix = RED;
break;
}
case LOG_WARNING:
{
prefix = "<warning> ";
color_prefix = LIGHT_RED;
break;
}
case LOG_INFO:
{
prefix = "<info> ";
color_prefix = "";
break;
}
case LOG_DEBUG:
{
prefix = "<debug> ";
color_prefix = GREEN;
break;
}
}
va_start(ap, format);
vsprintf(buffer, format, ap);
va_end(ap);
message = buffer;
message = prefix + message;
syslog(level, message.c_str());
message = color_prefix + message + END_COLOR + "\n";
fprintf(stderr, message.c_str());
}
#ifndef __LOGGER_H__
#define __LOGGER_H__
#include <string>
#include <syslog.h>
using namespace std;
namespace Logger
{
void log(const int, const char*, ...);
};
#define _error(...) Logger::log(LOG_ERROR, __VA_ARGS__)
#define _warn(...) Logger::log(LOG_WARNING, __VA_ARGS__)
#define _info(...) Logger::log(LOG_INFO, __VA_ARGS__)
#define _debug(...) Logger::log(LOG_DEBUG, __VA_ARGS__)
#define _debugException(...)
#define _debugInit(...)
#define _debugAlsa(...)
#define BLACK "\033[22;30m"
#define RED "\033[22;31m"
#define GREEN "\033[22;32m"
#define BROWN "\033[22;33m"
#define BLUE "\033[22;34m"
#define MAGENTA "\033[22;35m"
#define CYAN "\033[22;36m"
#define GREY "\033[22;37m"
#define DARK_GREY "\033[01;30m"
#define LIGHT_RED "\033[01;31m"
#define LIGHT_SCREEN "\033[01;32m"
#define YELLOW "\033[01;33m"
#define LIGHT_BLUE "\033[01;34m"
#define LIGHT_MAGENTA "\033[01;35m"
#define LIGHT_CYAN "\033[01;36m"
#define WHITE "\033[01;37m"
#define END_COLOR "\033[0m"
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment