add log4cpp

pull/33/head
Michel Promonet 10 years ago
parent e87ae04630
commit a4c9d885ee

@ -13,6 +13,18 @@ include_directories("${PROJECT_BINARY_DIR}/inc")
aux_source_directory(src SRC_FILES)
add_executable(${PROJECT_NAME} ${SRC_FILES})
# LOG4CPP
find_path(LOG4CPP_INCLUDE_DIR log4cpp/Category.hh)
if (NOT LOG4CPP_INCLUDE_DIR)
message(STATUS "Could not find the liblog4cpp5-dev.")
EXEC_PROGRAM("sudo apt-get install liblog4cpp5-dev")
find_path(V4L2_INCLUDE_DIR log4cpp/Category.hh)
endif (NOT LOG4CPP_INCLUDE_DIR)
include_directories(${LOG4CPP_INCLUDE_DIR})
find_library(LOG4CPP_LIBRARY log4cpp)
target_link_libraries(${PROJECT_NAME} "${LOG4CPP_LIBRARY}")
# V4L2
find_path(V4L2_INCLUDE_DIR libv4l2.h)
if (NOT V4L2_INCLUDE_DIR)

@ -19,17 +19,18 @@ License
------------
Domain public
Requirements
Dependencies
------------
- liblivemedia-dev > live.2012.01.07 (need StreamReplicator)
- libv4l-dev
- liblog4cpp5-dev
Build
-------
cmake .
make
If it fails you will need to install libv4l-dev liblivemedia-dev.
If it fails you will need to install libv4l-dev liblivemedia-dev liblog4cpp5-dev.
If it still not work you will need to read Makefile.
Install

@ -0,0 +1,46 @@
/* ---------------------------------------------------------------------------
** This software is in the public domain, furnished "as is", without technical
** support, and with no warranty, express or implied, as to its usefulness for
** any purpose.
**
** logger.h
**
** -------------------------------------------------------------------------*/
#ifndef LOGGER_H
#define LOGGER_H
#include "log4cpp/Category.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/PatternLayout.hh"
#define LOG(__level) log4cpp::Category::getRoot() << log4cpp::Priority::__level << __FILE__ << ":" << __LINE__ << " "
inline void initLogger(int verbose)
{
// initialize log4cpp
log4cpp::Category &log = log4cpp::Category::getRoot();
log4cpp::Appender *app = new log4cpp::FileAppender("root", ::dup(fileno(stdout)));
if (app)
{
log4cpp::PatternLayout *plt = new log4cpp::PatternLayout();
if (plt)
{
plt->setConversionPattern("%d [%p] - %m%n");
app->setLayout(plt);
}
log.addAppender(app);
}
switch (verbose)
{
case 2: log.setPriority(log4cpp::Priority::DEBUG); break;
case 1: log.setPriority(log4cpp::Priority::INFO); break;
default: log.setPriority(log4cpp::Priority::NOTICE); break;
}
LOG(INFO) << "level:" << log4cpp::Priority::getPriorityName(log.getPriority());
}
#endif

@ -31,6 +31,8 @@
#include <Base64.hh>
// project
#include "logger.h"
#include "V4l2ReadCapture.h"
#include "V4l2MmapCapture.h"
@ -58,7 +60,7 @@ void addSession(RTSPServer* rtspServer, const char* sessionName, ServerMediaSubs
rtspServer->addServerMediaSession(sms);
char* url = rtspServer->rtspURL(sms);
env << "Play this stream using the URL \"" << url << "\"\n";
LOG(NOTICE) << "Play this stream using the URL \"" << url << "\"\n";
delete[] url;
}
@ -126,6 +128,8 @@ int main(int argc, char** argv)
{
dev_name = argv[optind];
}
// init logger
initLogger(verbose);
// create live555 environment
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
@ -135,7 +139,7 @@ int main(int argc, char** argv)
RTSPServer* rtspServer = RTSPServer::createNew(*env, rtspPort);
if (rtspServer == NULL)
{
*env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
LOG(ERROR) << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
}
else
{
@ -146,7 +150,7 @@ int main(int argc, char** argv)
}
// Init capture
*env << "Create V4L2 Source..." << dev_name << "\n";
LOG(NOTICE) << "Create V4L2 Source..." << dev_name << "\n";
V4L2DeviceParameters param(dev_name,format,width,height,fps,verbose);
V4l2Capture* videoCapture = NULL;
if (useMmap)
@ -159,12 +163,12 @@ int main(int argc, char** argv)
}
if (videoCapture)
{
*env << "Start V4L2 Capture..." << dev_name << "\n";
LOG(NOTICE) << "Start V4L2 Capture..." << dev_name << "\n";
videoCapture->captureStart();
V4L2DeviceSource* videoES = V4L2DeviceSource::createNew(*env, param, videoCapture, outputFile, queueSize, verbose);
if (videoES == NULL)
{
*env << "Unable to create source for device " << dev_name << "\n";
LOG(FATAL) << "Unable to create source for device " << dev_name << "\n";
}
else
{
@ -184,7 +188,7 @@ int main(int argc, char** argv)
// main loop
signal(SIGINT,sighandler);
env->taskScheduler().doEventLoop(&quit);
*env << "Exiting..\n";
LOG(NOTICE) << "Exiting..\n";
Medium::close(videoES);
}
videoCapture->captureStop();

Loading…
Cancel
Save