mirror of https://github.com/sipwise/jitsi.git
messages for debug purpose.fix-message-formatting 5201
parent
9b03f3c841
commit
662c9352d3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
#include "Logger.h"
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LOGGER_DATE_STRING_LENGTH 25
|
||||
|
||||
/**
|
||||
* Constructs new Logger object.
|
||||
* @param pLogFile the filename of the log file.
|
||||
* @param pLogPath the path of the log file.
|
||||
*/
|
||||
Logger::Logger(const char* pLogFile, const char* pLogPath)
|
||||
{
|
||||
canWriteInFile = false;
|
||||
if(pLogPath != NULL && strlen(pLogPath) != 0)
|
||||
{
|
||||
logPath = (char*)malloc((strlen(pLogPath)+1)*sizeof(char));
|
||||
memcpy(logPath, pLogPath, strlen(pLogPath) + 1);
|
||||
if(pLogFile != NULL && strlen(pLogFile) != 0)
|
||||
{
|
||||
logFile = (char*)malloc((strlen(pLogPath) + strlen(pLogFile) + 1)*sizeof(char));
|
||||
sprintf(logFile, "%s%s", pLogPath, pLogFile);
|
||||
file = fopen(logFile, "w");
|
||||
if(file != NULL)
|
||||
{
|
||||
canWriteInFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!canWriteInFile)
|
||||
{
|
||||
logPath = NULL;
|
||||
logFile = NULL;
|
||||
file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
if(logPath != NULL)
|
||||
{
|
||||
free(logPath);
|
||||
}
|
||||
|
||||
if(logFile != NULL)
|
||||
{
|
||||
free(logFile);
|
||||
}
|
||||
|
||||
if(canWriteInFile)
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
const char* Logger::getCurrentFile()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current timestamp string.
|
||||
*/
|
||||
void Logger::getCurrentTimeString(char* dateString)
|
||||
{
|
||||
SYSTEMTIME systemTime;
|
||||
GetSystemTime(&systemTime);
|
||||
sprintf(dateString,"[%u-%02u-%02u %02u:%02u:%02u.%u]",
|
||||
systemTime.wYear,
|
||||
systemTime.wMonth,
|
||||
systemTime.wDay,
|
||||
systemTime.wHour,
|
||||
systemTime.wMinute,
|
||||
systemTime.wSecond,
|
||||
systemTime.wMilliseconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message
|
||||
* @param message the message.
|
||||
*/
|
||||
void Logger::log(const char* message)
|
||||
{
|
||||
if(canWriteInFile)
|
||||
{
|
||||
char *dateString = (char*)malloc(LOGGER_DATE_STRING_LENGTH*sizeof(char));
|
||||
getCurrentTimeString(dateString);
|
||||
fprintf(file, "%s %s: %s\n",dateString, getCurrentFile(), message);
|
||||
fflush(file);
|
||||
free(dateString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of the log file.
|
||||
*/
|
||||
char* Logger::getLogPath()
|
||||
{
|
||||
return logPath;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
#ifndef _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_LOGGER_H_
|
||||
#define _NET_JAVA_SIP_COMMUNICATOR_PLUGIN_ADDRBOOK_MSOUTLOOK_LOGGER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* Utility class for logging messages in file.
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* The full file name of the log file
|
||||
*/
|
||||
char* logFile;
|
||||
|
||||
/**
|
||||
* The path of the file.
|
||||
*/
|
||||
char* logPath;
|
||||
|
||||
/**
|
||||
* The file handle.
|
||||
*/
|
||||
FILE* file;
|
||||
|
||||
/**
|
||||
* Indicates whether the log file is successfully opened or not.
|
||||
*/
|
||||
bool canWriteInFile;
|
||||
|
||||
/**
|
||||
* Returns current timestamp string.
|
||||
*/
|
||||
void getCurrentTimeString(char*);
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
*/
|
||||
const char* getCurrentFile();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs new Logger object.
|
||||
* @param pLogFile the filename of the log file.
|
||||
* @param pLogPath the path of the log file.
|
||||
*/
|
||||
Logger(const char* pLogFile, const char* pLogPath);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~Logger();
|
||||
|
||||
/**
|
||||
* Logs a message
|
||||
* @param message the message.
|
||||
*/
|
||||
void log(const char* message);
|
||||
|
||||
/**
|
||||
* Returns the path of the log file.
|
||||
*/
|
||||
char* getLogPath();
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue