Skip to content

Commit b31ea1e

Browse files
committed
- Added basic logging to CppCMS
- Added std::cerr logger by-default
1 parent 8269b25 commit b31ea1e

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

booster/lib/log/src/log.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ namespace log {
9797

9898
namespace {
9999
// make sure it is created
100-
struct init { init() { logger::instance(); } } the_init;
100+
struct init {
101+
init()
102+
{
103+
logger::instance().add_sink(shared_ptr<sink>(new sinks::standard_error()));
104+
}
105+
} the_init;
101106
}
102107

103108
struct logger::data {

src/cgi_api.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
namespace boost = cppcms_boost;
3737
#endif
3838

39+
#include <booster/log.h>
40+
3941

4042
namespace cppcms { namespace impl { namespace cgi {
4143
/*
@@ -301,6 +303,8 @@ void connection::load_content(booster::system::error_code const &e,http::request
301303
long long allowed=service().settings().get("security.multipart_form_data_limit",64*1024)*1024;
302304
if(content_length > allowed) {
303305
set_error(h,"security violation: multipart/form-data content length too big");
306+
BOOSTER_NOTICE("cppcms") << "multipart/form-data size too big " << content_length <<
307+
" REMOTE_ADDR = `" << getenv("REMOTE_ADDR") << "' REMOTE_HOST=`" << getenv("REMOTE_HOST") << "'";
304308
return;
305309
}
306310
// FIXME
@@ -310,7 +314,8 @@ void connection::load_content(booster::system::error_code const &e,http::request
310314
long long allowed=service().settings().get("security.content_length_limit",1024)*1024;
311315
if(content_length > allowed) {
312316
set_error(h,"security violation POST content length too big");
313-
// TODO log
317+
BOOSTER_NOTICE("cppcms") << "POST data size too big " << content_length <<
318+
" REMOTE_ADDR = `" << getenv("REMOTE_ADDR") << "' REMOTE_HOST=`" << getenv("REMOTE_HOST") << "'";
314319
return;
315320
}
316321

src/fastcgi_api.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ namespace cgi {
554554
{
555555
if(e) { h(e); return; }
556556
if(header_.type!=fcgi_stdin || header_.content_length!=0) {
557-
std::cerr<<int(header_.type) <<" "<<header_.content_length<<std::endl;
558557
h(booster::system::error_code(errc::protocol_violation,cppcms_category));
559558
return;
560559
}

src/http_context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <cppcms/cache_interface.h>
3030
#include <cppcms/session_interface.h>
3131
#include <cppcms/cppcms_error.h>
32+
#include <booster/log.h>
3233

3334
#include <cppcms/config.h>
3435
#ifdef CPPCMS_USE_EXTERNAL_BOOST
@@ -127,8 +128,7 @@ void context::dispatch(booster::intrusive_ptr<application> app,std::string url,b
127128
app->response().make_error_response(http::response::internal_server_error,e.what());
128129
}
129130
else {
130-
// TODO log it
131-
std::cerr<<"Catched excepion ["<<e.what()<<"]"<<std::endl;
131+
BOOSTER_ERROR("cppcms") << "Catched excepion ["<<e.what()<<"]";
132132
}
133133
}
134134
}

src/service.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <cppcms/views_pool.h>
5757
#include <cppcms/session_pool.h>
5858

59+
#include <booster/log.h>
5960

6061
#ifdef CPPCMS_POSIX
6162
#include <sys/wait.h>
@@ -422,20 +423,20 @@ bool service::prefork()
422423
// TODO: Make better error handling
423424
if(!WIFEXITED(status) || WEXITSTATUS(status)!=0){
424425
if(WIFEXITED(status)) {
425-
std::cerr<<"Chaild exited with "<<WEXITSTATUS(status)<<std::endl;
426+
BOOSTER_CRITICAL("cppcms") <<"Chaild exited with "<<WEXITSTATUS(status);
426427
}
427428
else if(WIFSIGNALED(status)) {
428-
std::cerr<<"Chaild killed by "<<WTERMSIG(status)<<std::endl;
429+
BOOSTER_CRITICAL("cppcms") <<"Chaild killed by "<<WTERMSIG(status);
429430
}
430431
else {
431-
std::cerr<<"Chaild exited for unknown reason"<<std::endl;
432+
BOOSTER_CRITICAL("cppcms") <<"Chaild exited for unknown reason";
432433
}
433434
impl_->id_ = p - pids.begin() + 1;
434435
*p=-1;
435436
pid = ::fork();
436437
if(pid < 0) {
437438
int err=errno;
438-
std::cerr<<"Failed to create process: " <<strerror(err)<<std::endl;
439+
BOOSTER_ALERT("cppcms") <<"Failed to create process: " <<strerror(err);
439440
}
440441
else if(pid == 0) {
441442
::sigaction(SIGCHLD,&sa_old,NULL);

src/tcp_cache_server.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <booster/aio/io_service.h>
4444
#include <booster/aio/endpoint.h>
4545
#include <booster/aio/buffer.h>
46+
#include <booster/log.h>
4647
#include <time.h>
4748
#include <stdlib.h>
4849

@@ -351,16 +352,16 @@ static void thread_function(io::io_service *io)
351352
// Not much to do...
352353
// Object will be destroyed automatically
353354
// Because it does not resubmit itself
354-
std::cerr <<"CppCMS Error "<<e.what()<<std::endl;
355+
BOOSTER_ERROR("cache_server") <<"CppCMS Error "<<e.what();
355356
}
356357
}
357358
}
358359
catch(std::exception const &e)
359360
{
360-
std::cerr << "Fatal" << e.what() << std::endl;
361+
BOOSTER_ERROR("cache_server") << "Fatal" << e.what();
361362
}
362363
catch(...){
363-
std::cerr << "Unknown exception" << std::endl;
364+
BOOSTER_ERROR("cache_server") << "Unknown exception" << std::endl;
364365
}
365366
io->stop();
366367
}

0 commit comments

Comments
 (0)