aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2017-09-18 02:58:53 +0900
committeripknHama <ipknhama@gmail.com>2017-09-18 02:58:53 +0900
commit2c26b6c1def35f7b509f699097fdfb9480e9461c (patch)
tree3c7097832e5380ed04e6dd5ae6f603059b62c1f9
parente93ba25f2cd156a6544a3c9894cd667906146874 (diff)
downloadcrow-2c26b6c1def35f7b509f699097fdfb9480e9461c.tar.gz
crow-2c26b6c1def35f7b509f699097fdfb9480e9461c.zip
Change default settings
- disable crow debug mode by default - expose `loglevel` method on `App` to change the logging level easily - add a startup message that guides how to change the logging level
-rw-r--r--examples/example.cpp4
-rw-r--r--include/crow/app.h6
-rw-r--r--include/crow/http_server.h1
-rw-r--r--include/crow/settings.h2
-rw-r--r--include/crow/websocket.h25
5 files changed, 31 insertions, 7 deletions
diff --git a/examples/example.cpp b/examples/example.cpp
index 87231a2..1355b03 100644
--- a/examples/example.cpp
+++ b/examples/example.cpp
@@ -163,8 +163,8 @@ int main()
return std::string(512*1024, ' ');
});
- // ignore all log
- crow::logger::setLogLevel(crow::LogLevel::DEBUG);
+ // enables all log
+ app.loglevel(crow::LogLevel::DEBUG);
//crow::logger::setHandler(std::make_shared<ExampleLogHandler>());
app.port(18080)
diff --git a/include/crow/app.h b/include/crow/app.h
index cb72d3a..b454bf0 100644
--- a/include/crow/app.h
+++ b/include/crow/app.h
@@ -134,6 +134,12 @@ namespace crow
router_.debug_print();
}
+ self_t& loglevel(crow::LogLevel level)
+ {
+ crow::logger::setLogLevel(level);
+ return *this;
+ }
+
#ifdef CROW_ENABLE_SSL
self_t& ssl_file(const std::string& crt_filename, const std::string& key_filename)
{
diff --git a/include/crow/http_server.h b/include/crow/http_server.h
index f190739..6aa070e 100644
--- a/include/crow/http_server.h
+++ b/include/crow/http_server.h
@@ -150,6 +150,7 @@ namespace crow
CROW_LOG_INFO << server_name_ << " server is running at " << bindaddr_ <<":" << port_
<< " using " << concurrency_ << " threads";
+ CROW_LOG_INFO << "Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs.";
signals_.async_wait(
[&](const boost::system::error_code& /*error*/, int /*signal_number*/){
diff --git a/include/crow/settings.h b/include/crow/settings.h
index 5c67f3b..bd6259c 100644
--- a/include/crow/settings.h
+++ b/include/crow/settings.h
@@ -3,7 +3,7 @@
// TODO - replace with runtime config. libucl?
/* #ifdef - enables debug mode */
-#define CROW_ENABLE_DEBUG
+//#define CROW_ENABLE_DEBUG
/* #ifdef - enables logging */
#define CROW_ENABLE_LOGGING
diff --git a/include/crow/websocket.h b/include/crow/websocket.h
index c0e8c3f..ee0885f 100644
--- a/include/crow/websocket.h
+++ b/include/crow/websocket.h
@@ -183,7 +183,12 @@ namespace crow
{
//boost::asio::async_read(adaptor_.socket(), boost::asio::buffer(&mini_header_, 1),
adaptor_.socket().async_read_some(boost::asio::buffer(&mini_header_, 2),
- [this](const boost::system::error_code& ec, std::size_t bytes_transferred)
+ [this](const boost::system::error_code& ec, std::size_t
+#ifdef CROW_ENABLE_DEBUG
+ bytes_transferred
+#endif
+ )
+
{
is_reading = false;
mini_header_ = htons(mini_header_);
@@ -228,7 +233,11 @@ namespace crow
remaining_length_ = 0;
uint16_t remaining_length16_ = 0;
boost::asio::async_read(adaptor_.socket(), boost::asio::buffer(&remaining_length16_, 2),
- [this,&remaining_length16_](const boost::system::error_code& ec, std::size_t bytes_transferred)
+ [this,&remaining_length16_](const boost::system::error_code& ec, std::size_t
+#ifdef CROW_ENABLE_DEBUG
+ bytes_transferred
+#endif
+ )
{
is_reading = false;
remaining_length16_ = ntohs(remaining_length16_);
@@ -259,7 +268,11 @@ namespace crow
case WebSocketReadState::Len64:
{
boost::asio::async_read(adaptor_.socket(), boost::asio::buffer(&remaining_length_, 8),
- [this](const boost::system::error_code& ec, std::size_t bytes_transferred)
+ [this](const boost::system::error_code& ec, std::size_t
+#ifdef CROW_ENABLE_DEBUG
+ bytes_transferred
+#endif
+ )
{
is_reading = false;
remaining_length_ = ((1==ntohl(1)) ? (remaining_length_) : ((uint64_t)ntohl((remaining_length_) & 0xFFFFFFFF) << 32) | ntohl((remaining_length_) >> 32));
@@ -288,7 +301,11 @@ namespace crow
break;
case WebSocketReadState::Mask:
boost::asio::async_read(adaptor_.socket(), boost::asio::buffer((char*)&mask_, 4),
- [this](const boost::system::error_code& ec, std::size_t bytes_transferred)
+ [this](const boost::system::error_code& ec, std::size_t
+#ifdef CROW_ENABLE_DEBUG
+ bytes_transferred
+#endif
+ )
{
is_reading = false;
#ifdef CROW_ENABLE_DEBUG