Permalink
Browse files

first stab at changing couts to log::info() etc.

  • Loading branch information...
1 parent 5b74f59 commit 44132c52a7f3cd3ee49459efa413b35a17f25a77 @RJ committed Sep 9, 2009
View
5 includes/playdar/pluginadaptor_impl.hpp
@@ -28,6 +28,7 @@
#include "json_spirit/json_spirit.h"
#include "playdar/config.hpp"
#include "playdar/resolver.h"
+#include "playdar/logger.h"
namespace playdar {
@@ -45,11 +46,11 @@ class PluginAdaptorImpl : public PluginAdaptor
if( boost::filesystem::exists( p ) )
{
m_config = new Config( p.string() );
- std::cout << "Using plugin config file: "<< p.string() << std::endl;
+ log::info() << "Using plugin config file: "<< p.string() << std::endl;
}
else
{
- std::cout << "Using default config for " << className << std::endl;
+ log::info() << "Using default config for " << className << std::endl;
m_config = new Config();
}
}
View
7 resolvers/api/api.cpp
@@ -20,6 +20,7 @@
#include <boost/algorithm/string.hpp>
#include "playdar/playdar_request.h"
#include "playdar/track_rq_builder.hpp"
+#include "playdar/logger.h"
namespace playdar {
namespace resolvers {
@@ -113,7 +114,7 @@ api::authed_http_handler(const playdar_request& req, playdar_response& resp, pla
}
else
{
- cout << "WARNING - resolve request provided a QID, but that QID already exists as a running query. Assigning a new QID." << endl;
+ log::info() << "WARNING - resolve request provided a QID, but that QID already exists as a running query. Assigning a new QID." << endl;
// new qid assigned automatically if we don't provide one.
}
}
@@ -123,7 +124,7 @@ api::authed_http_handler(const playdar_request& req, playdar_response& resp, pla
}
if( !rq->isValidTrack() ) // usually caused by empty track name or something.
{
- cout << "Tried to dispatch an invalid query, failing." << endl;
+ log::info() << "Tried to dispatch an invalid query, failing." << endl;
playdar_response r("");
r.set_response_code( 400 ); // bad_request
resp = r;
@@ -147,7 +148,7 @@ api::authed_http_handler(const playdar_request& req, playdar_response& resp, pla
{
if( !m_pap->query_exists( req.getvar("qid") ) )
{
- cerr << "Error get_results(" << req.getvar("qid") << ") - qid went away." << endl;
+ log::error() << "Error get_results(" << req.getvar("qid") << ") - qid went away." << endl;
playdar_response r("");
r.set_response_code( 404 ); // bad_request
resp = r;
View
6 resolvers/audioscrobbler/audioscrobbler_plugin.cpp
@@ -19,6 +19,8 @@
#include "scrobsub.h"
#include "playdar/playdar_request.h"
#include "playdar/playdar_response.h"
+#include "playdar/logger.h"
+
using std::cout;
using std::endl;
using std::string;
@@ -34,7 +36,7 @@ audioscrobbler::scrobsub_callback(int e, const char*s)
if (e == SCROBSUB_AUTH_REQUIRED && !instance->auth_required)
{
instance->auth_required = true;
- cout << "You need to authenticate scrobbling, visit http://localhost:8888/audioscrobbler/config/" << endl; //FIXME hardcoded url
+ log::info() << "You need to authenticate scrobbling, visit http://localhost:60210/audioscrobbler/config/" << endl; //FIXME hardcoded url
}
}
@@ -102,7 +104,7 @@ audioscrobbler::anon_http_handler(const playdar_request& rq, playdar_response& r
bool
audioscrobbler::authed_http_handler(const playdar_request& rq, playdar_response& resp, playdar::auth& pauth)
{
- cout << "audioscrobbler: Authed HTTP" << endl;
+ log::info() << "audioscrobbler: Authed HTTP" << endl;
if(rq.parts().size()<2) return false;
View
67 resolvers/lan/lan.cpp
@@ -21,11 +21,12 @@
#include "playdar/resolver_query.hpp"
#include "playdar/playdar_request.h"
#include "playdar/utils/htmlentities.hpp"
+#include "playdar/logger.h"
#include <ctime>
/// port used for binding the udp endpoints only (nothing to do with tcp/http):
-#define DEFAULT_LAN_PORT 8888
+#define DEFAULT_LAN_PORT 60210
#define DEFAULT_LAN_ENDPOINT "239.255.0.1"
using namespace std;
@@ -47,7 +48,7 @@ lan::init(pa_ptr pap)
setup_endpoints();
if( m_endpoints.size() == 0 )
{
- cerr << "LAN: Error, no valid endpoints configured" << endl;
+ log::error() << "LAN Error, no valid endpoints configured" << endl;
return false;
}
@@ -57,7 +58,7 @@ lan::init(pa_ptr pap)
lan::~lan() throw()
{
- cout << "DTOR LAN " << endl;
+ //cout << "DTOR LAN " << endl;
//send_pang(); // can't send when shutting down - crashes atm.
if( m_io_service )
m_io_service->stop();
@@ -87,7 +88,7 @@ lan::setup_endpoints()
( boost::asio::ip::address::from_string
(DEFAULT_LAN_ENDPOINT), DEFAULT_LAN_PORT )
);
- cout << "LAN plugin using default multicast address of " << DEFAULT_LAN_ENDPOINT << endl;
+ log::info() << "LAN plugin using default multicast address of " << DEFAULT_LAN_ENDPOINT << endl;
}
else // manual config of endpoints:
{
@@ -122,7 +123,7 @@ lan::setup_endpoints()
boost::asio::ip::address::from_string( ip ), port ) );
}catch(...){}
}
- cout << "LAN plugin has " << m_endpoints.size() << " endpoints configured." << endl;
+ log::info() << "LAN plugin has " << m_endpoints.size() << " endpoints configured." << endl;
}
}
@@ -132,7 +133,7 @@ lan::start_resolving(boost::shared_ptr<ResolverQuery> rq)
using namespace json_spirit;
ostringstream querystr;
write_formatted( rq->get_json(), querystr );
- //cout << "Resolving: " << querystr.str() << " through the LAN plugin" << endl;
+ //log::info() << "Resolving: " << querystr.str() << " through the LAN plugin" << endl;
async_send(querystr.str());
}
@@ -162,7 +163,7 @@ lan::run()
( m_pap->get<string>("listenip", DEFAULT_LAN_ENDPOINT) ),
m_pap->get<int>("listenport", DEFAULT_LAN_PORT) );
- cout << "LAN Resolver is online udp://"
+ log::info() << "LAN Resolver is online udp://"
<< socket_->local_endpoint().address() << ":"
<< socket_->local_endpoint().port()
<< endl;
@@ -211,15 +212,12 @@ void
lan::async_send(boost::asio::ip::udp::endpoint * remote_endpoint,
const string& message)
{
- if(message.length()>max_length)
+ if( message.length() > max_length )
{
- cerr << "WARNING outgoing UDP message is rather large, haven't tested this, discarding." << endl;
+ log::error() << "WARNING outgoing UDP message is rather large, haven't tested this, discarding." << endl;
return;
}
- //cout << "UDPsend[" << remote_endpoint.address()
- // << ":" << remote_endpoint.port() << "]"
- // << "(" << message << ")" << endl;
-
+
// you can set numcopies to 2 or 3 for lossy networks:
int copies = m_pap->get<int>("numcopies", 1);
if(copies<1) copies=1;
@@ -283,7 +281,7 @@ lan::handle_receive_from(const boost::system::error_code& error,
Value mv;
if(!read(msg, mv))
{
- cout << "lan: invalid JSON in this message, discarding." << endl;
+ log::warning() << "lan: invalid JSON in this message, discarding." << endl;
break; // Invalid JSON, ignore it.
}
Object qo = mv.get_obj();
@@ -299,7 +297,7 @@ lan::handle_receive_from(const boost::system::error_code& error,
}
else
{
- cerr << "UDP msg rcvd without _msgtype - discarding"
+ log::warning() << "UDP msg rcvd without _msgtype - discarding"
<< endl;
break;
}
@@ -313,7 +311,7 @@ lan::handle_receive_from(const boost::system::error_code& error,
}
catch (...)
{
- cout << "lan: missing fields in JSON query object, discarding" << endl;
+ log::warning() << "lan: missing fields in JSON query object, discarding" << endl;
break;
}
@@ -338,7 +336,7 @@ lan::handle_receive_from(const boost::system::error_code& error,
query_uid qid = r["qid"].get_str();
if(!m_pap->query_exists(qid))
{
- cout << "lan: Ignoring response - QID invalid or expired" << endl;
+ log::warning() << "lan: Ignoring response - QID invalid or expired" << endl;
break;
}
//cout << "lan: Got udp response." <<endl;
@@ -367,7 +365,7 @@ lan::handle_receive_from(const boost::system::error_code& error,
}
catch (...)
{
- cout << "lan: Missing fields in response json, discarding" << endl;
+ log::warning() << "lan: Missing fields in response json, discarding" << endl;
break;
}
}
@@ -394,7 +392,7 @@ lan::handle_receive_from(const boost::system::error_code& error,
}
else
{
- cerr << "Some error for udp" << endl;
+ log::warning() << "Some error for udp" << endl;
}
}
@@ -428,7 +426,7 @@ lan::send_response( query_uid qid,
void
lan::send_ping()
{
- cout << "LAN sending ping.." << endl;
+ log::info() << "LAN sending ping.." << endl;
using namespace json_spirit;
Object jq;
jq.push_back( Pair("_msgtype", "ping") );
@@ -443,7 +441,7 @@ lan::send_ping()
void
lan::send_pong(boost::asio::ip::udp::endpoint sender_endpoint)
{
- cout << "LAN sending pong back to "
+ log::info() << "LAN sending pong back to "
<< sender_endpoint.address().to_string() <<".." << endl;
Object o;
o.push_back( Pair("_msgtype", "pong") );
@@ -458,7 +456,7 @@ lan::send_pong(boost::asio::ip::udp::endpoint sender_endpoint)
void
lan::send_pang()
{
- cout << "LAN sending pang.." << endl;
+ log::info() << "LAN sending pang.." << endl;
using namespace json_spirit;
Object o;
o.push_back( Pair("_msgtype", "pang") );
@@ -474,18 +472,18 @@ lan::receive_ping(map<string,Value> & om,
{
if(om.find("from_name")==om.end() || om["from_name"].type()!=str_type)
{
- cout << "Malformed UDP PING dropped." << endl;
+ log::warning() << "Malformed UDP PING dropped." << endl;
return;
}
// ignore pings sent from ourselves:
if(om["from_name"]==m_pap->hostname()) return;
if(om.find("http_port")==om.end() || om["http_port"].type()!=int_type)
{
- cout << "Malformed UDP PING dropped." << endl;
+ log::warning() << "Malformed UDP PING dropped." << endl;
return;
}
string from_name = om["from_name"].get_str();
- cout << "Received UDP PING from '" << from_name
+ log::info() << "Received UDP PING from '" << from_name
<< "' @ " << sender_endpoint.address().to_string()
<< endl;
ostringstream hbase;
@@ -506,16 +504,16 @@ lan::receive_pong(map<string,Value> & om,
{
if(om.find("from_name")==om.end() || om["from_name"].type()!=str_type)
{
- cout << "Malformed UDP PONG dropped." << endl;
+ log::warning() << "Malformed UDP PONG dropped." << endl;
return;
}
if(om.find("http_port")==om.end() || om["http_port"].type()!=int_type)
{
- cout << "Malformed UDP PONG dropped." << endl;
+ log::warning() << "Malformed UDP PONG dropped." << endl;
return;
}
string from_name = om["from_name"].get_str();
- cout << "Received UDP PONG from '" << from_name
+ log::info() << "Received UDP PONG from '" << from_name
<< "' @ " << sender_endpoint.address().to_string()
<< endl;
ostringstream hbase;
@@ -528,13 +526,6 @@ lan::receive_pong(map<string,Value> & om,
node.http_base = hbase.str();
node.udp_ep = sender_endpoint;
m_lannodes[from_name] = node;
- cout << "Current LAN roster: ";
- typedef std::pair<string,lannode> pair_t;
- BOOST_FOREACH( pair_t p, m_lannodes )
- {
- cout << p.first << ": " << p.second.lastdate << ", ";
- }
- cout << endl;
}
void
@@ -543,11 +534,11 @@ lan::receive_pang(map<string,Value> & om,
{
if(om.find("from_name")==om.end() || om["from_name"].type()!=str_type)
{
- cout << "Malformed UDP PANG dropped." << endl;
+ log::warning() << "Malformed UDP PANG dropped." << endl;
return;
}
string from_name = om["from_name"].get_str();
- cout << "Received UDP PANG from '" << from_name
+ log::info() << "Received UDP PANG from '" << from_name
<< "' @ " << sender_endpoint.address().to_string()
<< endl;
m_lannodes.erase(from_name);
@@ -562,7 +553,7 @@ bool endsWith(const std::string& s, const std::string& tail)
bool
lan::anon_http_handler(const playdar_request& req, playdar_response& resp, playdar::auth& /*pauth*/)
{
- cout << "request handler on lan for url: " << req.url() << endl;
+ log::info() << "request handler on lan for url: " << req.url() << endl;
time_t now;
time(&now);
View
31 resolvers/local/library.cpp
@@ -26,6 +26,7 @@
#include <boost/algorithm/string.hpp>
#include "library_sql.h"
+#include "playdar/logger.h"
using namespace std;
@@ -38,12 +39,12 @@ Library::Library(const string& dbfilepath)
m_dbfilepath = dbfilepath;
// confirm DB is correct version, or create schema if first run
check_db();
- cout << "library DB opened ok" << endl;
+ log::info() << "library DB opened ok" << endl;
}
Library::~Library()
{
- cout << "DTOR library" << endl;
+ log::info() << "DTOR library" << endl;
}
void
@@ -57,19 +58,19 @@ Library::check_db()
{
// unusual - table exists but doesn't contain this row.
// could have been created wrongly
- cerr << "Errror, playdar_system table missing schema_version key!" << endl
+ log::error() << "Errror, playdar_system table missing schema_version key!" << endl
<< "Maybe you created the database wrong, or it's corrupt." << endl
<< "Try deleting it and re-scanning?" << endl;
throw; // not caught here.
}
string val = (*i).get<string>(0);
- cout << "Database schema detected as version " << val << endl;
+ log::info() << "Database schema detected as version " << val << endl;
// check the schema version is what we expect
// TODO auto-upgrade to newest schema version as needed.
if( val != "2" )
{
- cerr << "Schema version too old. TODO handle auto-upgrades" << endl;
- cerr << "To upgrade from 1->2, run this: alter table playdar_auth add column ua text not null default \"\"; update playdar_system set value=\"2\" where key=\"schema_version\";"
+ log::error() << "Schema version too old. TODO handle auto-upgrades" << endl;
+ log::error() << "To upgrade from 1->2, run this: alter table playdar_auth add column ua text not null default \"\"; update playdar_system set value=\"2\" where key=\"schema_version\";"
<< endl;
throw; // not caught here
@@ -80,7 +81,7 @@ Library::check_db()
{
// probably doesn't exist yet, try and create it
//
- cout << "database_error: " << err.what() << endl;
+ log::warning() << "database_error: " << err.what() << endl;
create_db_schema();
}
@@ -89,19 +90,19 @@ Library::check_db()
void
Library::create_db_schema()
{
- cout << "Attempting to create DB schema..." << endl;
+ log::info() << "Attempting to create DB schema..." << endl;
string sql( playdar::get_playdar_sql() );
vector<string> statements;
boost::split( statements, sql, boost::is_any_of(";") );
BOOST_FOREACH( string s, statements )
{
boost::trim( s );
if(s.empty()) continue;
- cout << "Executing: " << s << endl;
+ log::info() << "Executing: " << s << endl;
sqlite3pp::command cmd(m_db, s.c_str());
cmd.execute();
}
- cout << "Schema created, reopening." << endl;
+ log::info() << "Schema created, reopening." << endl;
m_db.connect( m_dbfilepath.c_str() ); // this will close/flush and reopen
}
@@ -154,7 +155,7 @@ Library::add_file( const string& url, int mtime, int size, const string& md5, c
cmd.bind(6, duration);
cmd.bind(7, bitrate);
if(cmd.execute() != SQLITE_OK){
- cerr<<"Error inserting into file table"<<endl;
+ log::warning() << "Error inserting into file table"<<endl;
return 0;
}
fileid = static_cast<int>( m_db.last_insert_rowid() );
@@ -175,7 +176,7 @@ Library::add_file( const string& url, int mtime, int size, const string& md5, c
cmd2.bind(4, trkid);
boost::mutex::scoped_lock lock(m_mut);
if(cmd2.execute() != SQLITE_OK){
- cerr<<"Error inserting into file_join table"<<endl;
+ log::warning() << "Error inserting into file_join table"<<endl;
return 0;
}
return fileid;
@@ -204,7 +205,7 @@ Library::get_artist_id(const string& name_orig)
cmd.bind(1,name_orig.c_str(),true);
cmd.bind(2,sortname.c_str(),true);
if(SQLITE_OK != cmd.execute()){
- cerr << "Failed to insert artist: " << name_orig << endl;
+ log::warning() << "Failed to insert artist: " << name_orig << endl;
return 0;
}
id = static_cast<int>( m_db.last_insert_rowid() );
@@ -238,7 +239,7 @@ Library::get_track_id(int artistid, const string& name_orig)
cmd.bind(2, name_orig.c_str(), true);
cmd.bind(3, sortname.c_str(), true);
if(SQLITE_OK != cmd.execute()){
- cerr << "Failed to insert track: " << name_orig << endl;
+ log::warning() << "Failed to insert track: " << name_orig << endl;
return 0;
}
id = static_cast<int>( m_db.last_insert_rowid() );
@@ -272,7 +273,7 @@ Library::get_album_id(int artistid, const string& name_orig)
cmd.bind(2, name_orig.c_str(), true);
cmd.bind(3, sortname.c_str(), true);
if(SQLITE_OK != cmd.execute()){
- cerr << "Failed to insert album: " << name_orig << endl;
+ log::warning() << "Failed to insert album: " << name_orig << endl;
return 0;
}
id = static_cast<int>( m_db.last_insert_rowid() );
View
11 resolvers/local/rs_local_library.cpp
@@ -25,6 +25,7 @@
#include "playdar/resolver_query.hpp"
#include "playdar/playdar_request.h"
#include "playdar/playdar_response.h"
+#include "playdar/logger.h"
using namespace std;
@@ -45,12 +46,12 @@ local::init(pa_ptr pap)
m_library = new Library( m_pap->getstring( "database", default_db_path ).get_str());
m_exiting = false;
- cout << "Local library resolver: " << m_library->num_files()
- << " files indexed." << endl;
+ log::info() << "Local library resolver: " << m_library->num_files()
+ << " files indexed." << endl;
if(m_library->num_files() == 0)
{
- cout << endl << "WARNING! You don't have any files in your database!"
- << "Run the scanner, then restart Playdar." << endl << endl;
+ log::info() << "WARNING! You don't have any files in your database!"
+ << "Run the scanner, then restart Playdar." << endl;
}
// worker thread for doing actual resolving:
m_t = new boost::thread(boost::bind(&local::run, this));
@@ -90,7 +91,7 @@ local::run()
}
catch(...)
{
- cout << "local runner exiting." << endl;
+ //cout << "local runner exiting." << endl;
}
}
View
18 src/auth.cpp
@@ -22,6 +22,7 @@
#include <boost/foreach.hpp>
#include "playdar/auth.h"
#include "auth_sql.h"
+#include "playdar/logger.h"
namespace playdar {
@@ -121,13 +122,14 @@ auth::check_db()
{
// unusual - table exists but doesn't contain this row.
// could have been created wrongly
- cerr << "Error, settings table missing schema_version key!" << endl
- << "Maybe you created the database wrong, or it's corrupt." << endl
- << "Try deleting the auth database" << endl;
+ log::error() <<
+ "Error, settings table missing schema_version key! "
+ "Maybe you created the database wrong, or it's corrupt. "
+ "Try deleting the auth database" << endl;
throw; // not caught here.
}
string val = (*i).get<string>(0);
- cout << "Auth database schema detected as version " << val << endl;
+ log::info() << "Auth database schema detected as version " << val << endl;
// check the schema version is what we expect
// TODO auto-upgrade to newest schema version as needed.
if( val != "2" )
@@ -140,28 +142,28 @@ auth::check_db()
{
// probably doesn't exist yet, try and create it
//
- cout << "database_error: " << err.what() << endl;
+ log::error() << "database_error: " << err.what() << endl;
create_db_schema();
}
}
void
auth::create_db_schema()
{
- cout << "Attempting to create DB schema..." << endl;
+ log::info() << "Attempting to create DB schema..." << endl;
string sql( playdar::get_auth_sql() );
vector<string> statements;
boost::split( statements, sql, boost::is_any_of(";") );
BOOST_FOREACH( string s, statements )
{
boost::trim( s );
if (!s.empty()) {
- cout << "Executing: " << s << endl;
+ log::info() << "Executing: " << s << endl;
sqlite3pp::command cmd(m_db, s.c_str());
cmd.execute();
}
}
- cout << "Schema created, reopening." << endl;
+ log::info() << "Schema created, reopening." << endl;
m_db.connect( m_dbfilepath.c_str() ); // this will close/flush and reopen the file
}
View
42 src/main.cpp
@@ -31,6 +31,7 @@
#include <curl/curl.h>
#include "playdar/playdar_request_handler.h"
+#include "playdar/logger.h"
using namespace std;
using namespace playdar;
@@ -41,7 +42,7 @@ MyApplication * app = 0;
static void sigfunc(int sig)
{
- cout << "Signal handler." << endl;
+ log::info() << "Signal handler triggered" << endl;
if ( app )
app->shutdown(sig);
}
@@ -67,7 +68,7 @@ string find_config_dir()
}
else
{
- cerr << "Error, $HOME not set." << endl;
+ log::error() << "Error, $HOME not set." << endl;
throw;
}
#elif _WIN32
@@ -84,7 +85,7 @@ string find_config_dir()
}
else
{
- cerr << "Error, $HOME or $XDG_CONFIG_HOME not set." << endl;
+ log::error() << "Error, $HOME or $XDG_CONFIG_HOME not set." << endl;
throw;
}
path config_base = p;
@@ -101,7 +102,7 @@ string find_config_dir()
void start_http_server(string ip, int port, int conc, MyApplication* app)
{
if(conc<1) conc=1;
- cout << "HTTP server starting on: http://" << ip << ":" << port << "/" << " with " << conc << " threads" << endl;
+ log::info() << "HTTP server starting on: http://" << ip << ":" << port << "/" << " with " << conc << " threads" << endl;
moost::http::server<playdar_request_handler> s(ip, port, conc);
s.request_handler().init(app);
// tell app how to stop the http server:
@@ -113,9 +114,9 @@ void start_http_server(string ip, int port, int conc, MyApplication* app)
}
catch( const boost::system::system_error& e )
{
- cerr << "HTTP server error: " << e.what() << endl;
+ log::error() << "HTTP server error: " << e.what() << endl;
}
- cout << "http_server thread exiting." << endl;
+ log::info() << "http_server thread exiting." << endl;
}
static void print_curl_info()
@@ -124,20 +125,21 @@ static void print_curl_info()
curl_version_info_data * cv = curl_version_info(CURLVERSION_NOW);
if(cv->age >= 0)
{
- cout << "Curl version:\t" << cv->version << endl;
+ log::info() << "Curl version:\t" << cv->version << endl;
const char * proto;
int i = 0;
- cout << "* Protocols:\t";
+ log::info() << "* Protocols:\t";
for(; (proto = cv->protocols[i]) ; i++ )
{
- cout << proto << ", " ;
+ log::info() << proto << ", " ;
}
- cout << endl;
- cout << "* SSL:\t" << (cv->features&CURL_VERSION_SSL ? "YES" : "NO") << endl;
- cout << "* IPv6:\t" << (cv->features&CURL_VERSION_IPV6 ? "YES" : "NO") << endl;
- cout << "* LIBZ:\t" << (cv->features&CURL_VERSION_LIBZ ? "YES" : "NO") << endl;
+ log::info()
+ << endl
+ << "* SSL:\t" << (cv->features&CURL_VERSION_SSL ? "YES" : "NO") << endl
+ << "* IPv6:\t" << (cv->features&CURL_VERSION_IPV6 ? "YES" : "NO") << endl
+ << "* LIBZ:\t" << (cv->features&CURL_VERSION_LIBZ ? "YES" : "NO") << endl;
}else{
- cerr << "Curl detection failed." << endl;
+ log::error() << "Curl detection failed." << endl;
throw;
}
cout << endl;
@@ -204,11 +206,11 @@ int main(int ac, char *av[])
try
{
- cout << "Using config file: " << configfile << endl;
+ log::info() << "Using config file: " << configfile << endl;
Config conf(configfile);
if(conf.get<string>("name", "YOURNAMEHERE")=="YOURNAMEHERE")
{
- cout << "Autodetecting name: " << conf.name() << endl;
+ log::info() << "Autodetecting name: " << conf.name() << endl;
}
#ifndef WIN32
@@ -228,7 +230,7 @@ int main(int ac, char *av[])
}
catch(...)
{
- cerr << "Curl FAIL." << endl;
+ log::error() << "Curl FAIL." << endl;
return 9;
}
@@ -243,14 +245,14 @@ int main(int ac, char *av[])
);
http_thread.join();
- cout << "HTTP server finished, destructing app..." << endl;
+ log::info() << "HTTP server finished, destructing app..." << endl;
delete app;
- cout << "App deleted." << endl;
+ log::info() << "App deleted." << endl;
return 0;
}
catch(exception& e)
{
- cout << "Playdar main exception: " << e.what() << "\n";
+ log::error() << "Playdar main exception: " << e.what() << "\n";
return 1;
}
View
1 src/playdar_request.cpp
@@ -22,6 +22,7 @@
#include <boost/foreach.hpp>
#include <moost/http.hpp>
+
using namespace std;
namespace playdar {
View
31 src/playdar_request_handler.cpp
@@ -41,6 +41,7 @@
#include "playdar/utils/htmlentities.hpp"
#include "playdar/CometSession.hpp"
#include "playdar/HttpAsyncAdaptor.hpp"
+#include "playdar/logger.h"
using namespace std;
@@ -52,7 +53,7 @@ void
playdar_request_handler::init(MyApplication * app)
{
m_disableAuth = app->conf()->get<bool>( "disableauth", false );
- cout << "HTTP handler online." << endl;
+ log::info() << "HTTP handler online." << endl;
m_pauth = new playdar::auth(app->conf()->get<string>( "authdb", "auth.db" ));
m_app = app;
// built-in handlers:
@@ -84,13 +85,13 @@ playdar_request_handler::handle_request(const moost::http::request& req, moost::
{
//TODO: Handle % encodings
- cout << "HTTP " << req.method << " " << req.uri << " " << req.origin << endl;
+ log::info() << "HTTP " << req.method << " " << req.uri << " " << req.origin << endl;
if( req.origin != "127.0.0.1" &&
req.origin != "::1" && // not tested the ipv6 check
req.origin != "0:0:0:0:0:0:0:1" &&
req.uri.substr(0,5) != "/sid/" )
{
- cout << "BLOCKED. Only localhost may access non /sid/ urls." << endl;
+ log::info() << "BLOCKED. Only localhost may access non /sid/ urls." << endl;
rep.stock_reply(moost::http::reply::unauthorized);
return;
}
@@ -321,7 +322,7 @@ playdar_request_handler::handle_pluginurl( const playdar_request& req,
if( rs == 0 )
{
- cout << "No plugin of that name found." << endl;
+ log::info() << "No plugin of that name found." << endl;
rep.stock_reply(moost::http::reply::not_found);
return;
}
@@ -333,17 +334,17 @@ playdar_request_handler::handle_pluginurl( const playdar_request& req,
string whom;
if(m_disableAuth || m_pauth->is_valid(req.getvar("auth"), whom) )
{
- //cout << "AUTH: validated " << whom << endl;
+ //log::info() << "AUTH: validated " << whom << endl;
permissions = "*"; // allow all.
}
else
{
- //cout << "AUTH: Invalid authtoken." << endl;
+ //log::info() << "AUTH: Invalid authtoken." << endl;
}
}
else
{
- //cout << "AUTH: no auth value provided." << endl;
+ //log::info() << "AUTH: no auth value provided." << endl;
}
playdar_response resp;
@@ -526,15 +527,15 @@ playdar_request_handler::handle_queries( const playdar_request& req,
{
if( req.parts().size() == 1 )
{
- cout << "Query handler, parts: " << req.parts()[0] << endl;
+ //log::info() << "Query handler, parts: " << req.parts()[0] << endl;
const string& s = handle_queries_root(req);
serve_body( s, rep );
break;
}
else if( req.parts().size() == 2 )
{
- cout << "Query handler, parts: " << req.parts()[0] << ", " << req.parts()[1] << endl;
+ //log::info() << "Query handler, parts: " << req.parts()[0] << ", " << req.parts()[1] << endl;
query_uid qid = req.parts()[1];
rq_ptr rq = app()->resolver()->rq(qid);
@@ -648,9 +649,9 @@ playdar_request_handler::handle_quickplay( const playdar_request& req,
if (results.size() && !results[0]->json_value( "url", "" ).empty()) {
json_spirit::Object ro = results[0]->get_json();
- cout << "Top result:" <<endl;
- json_spirit::write_formatted( ro, cout );
- cout << endl;
+ //log::info() << "Top result:" <<endl;
+ //json_spirit::write_formatted( ro, cout );
+ //log::info() << endl;
string url = "/sid/";
url += results[0]->id();
rep.set_status( moost::http::reply::moved_temporarily );
@@ -695,15 +696,15 @@ playdar_request_handler::serve_static_file(const moost::http::request& req, moos
void
playdar_request_handler::serve_sid( moost::http::reply& rep, source_uid sid)
{
- cout << "Serving SID " << sid << endl;
+ log::info() << "Serving SID " << sid << endl;
ss_ptr ss = app()->resolver()->get_ss(sid);
if(!ss)
{
cerr << "This SID does not exist or does not resolve to a playable item." << endl;
rep.stock_reply(moost::http::reply::not_found);
return;
}
- cout << "-> " << ss->debug() << endl;
+ log::info() << "-> " << ss->debug() << endl;
boost::shared_ptr<HttpAsyncAdaptor> hp(new HttpAsyncAdaptor(rep.shared_from_this()));
ss->start_reply(hp);
@@ -754,7 +755,7 @@ playdar_request_handler::handle_comet(const playdar_request& req, moost::http::r
static std::string startArray("[");
rep.write_content( startArray );
} else {
- cout << "couldn't create comet session" << endl;
+ log::error() << "couldn't create comet session" << endl;
rep.stock_reply( moost::http::reply::internal_server_error );
}
} else {
View
62 src/resolver.cpp
@@ -32,6 +32,7 @@
#include "playdar/resolver.h"
#include "playdar/ss_curl.hpp"
#include "playdar/rs_script.h"
+#include "playdar/logger.h"
// Generic track calculation stuff:
#include "playdar/track_rq_builder.hpp"
@@ -56,7 +57,7 @@ Resolver::Resolver(MyApplication * app)
:m_app(app), m_exiting(false)
{
m_id_counter = 0;
- cout << "Resolver starting..." << endl;
+ log::info() << "Resolver starting..." << endl;
m_t = new boost::thread(boost::bind(&Resolver::dispatch_runner, this));
@@ -87,29 +88,28 @@ Resolver::Resolver(MyApplication * app)
}
catch(...)
{
- cout << "Error loading resolver plugins." << endl;
+ log::error() << "Error loading resolver plugins." << endl;
}
- typedef std::pair<string,ResolverService*> pairx;
- BOOST_FOREACH( pairx px, m_pluginNameMap )
- {
- cout << px.first << ", " ;
- }
- cout << endl;
+ //typedef std::pair<string,ResolverService*> pairx;
+ //BOOST_FOREACH( pairx px, m_pluginNameMap )
+ //{
+ // log::info() << px.first << ", " ;
+ //}
+ //log::info() << endl;
// sort the list of resolvers by weight, descending:
boost::function<bool (const pa_ptr &, const pa_ptr&)> sortfun =
boost::bind(&Resolver::pluginadaptor_sorter, this, _1, _2);
sort(m_resolvers.begin(), m_resolvers.end(), sortfun);
- cout << endl;
- cout << "Loaded resolvers (" << m_resolvers.size() << ")" << endl;
+ //cout << endl;
+ log::info() << "Loaded resolvers (" << m_resolvers.size() << ")" << endl;
BOOST_FOREACH( pa_ptr & pa, m_resolvers )
{
- cout << "RESOLVER w:" << pa->weight() << "\tp:" << pa->preference()
+ log::info() << "RESOLVER w:" << pa->weight() << "\tp:" << pa->preference()
<< "\tt:" << pa->targettime()
<< "\t[" << (pa->script()?"script":"plugin") << "] "
<< pa->rs()->name() << endl;
}
- cout << endl;
}
/// set up SS factories for every protocol curl can handle
@@ -124,7 +124,7 @@ Resolver::detect_curl_capabilities()
for(int i = 0; (proto = cv->protocols[i]) ; i++ )
{
string p(proto);
- cout << "SS factory registered for: " << p << endl ;
+ log::info() << "SS factory registered for: " << p << endl ;
m_ss_factories[ p ] = ssf; // add an SS factory for this protocol
}
}
@@ -158,7 +158,7 @@ Resolver::load_resolver_scripts()
using namespace boost::filesystem;
path const etc = "scripts"; //FIXME don't depend on working directory
- cout << "Loading resolver scripts from: " << etc << endl;
+ log::info() << "Loading resolver scripts from: " << etc << endl;
if (!exists(etc) || !is_directory(etc)) return; // avoid the throw
@@ -179,11 +179,11 @@ Resolver::load_resolver_scripts()
if (name=="README.txt")
continue;
if (app()->conf()->get<bool>(conf+".enabled", true) == false){
- cout << "-> Skipping '"+name+"' - disabled in config file";
+ log::info() << "-> Skipping '"+name+"' - disabled in config file";
continue;
}
- cout << "-> Loading: " << name << endl;
+ log::info() << "-> Loading: " << name << endl;
pa_ptr pap( new PluginAdaptorImpl( app()->conf(), this, name ) );
pap->set_script( true );
@@ -204,7 +204,7 @@ Resolver::load_resolver_scripts()
if(pap->weight() > 0)
{
m_resolvers.push_back( pap );
- cout << "-> OK [w:" << pap->weight()
+ log::info() << "-> OK [w:" << pap->weight()
<< " p:" << pap->preference()
<< " t:" << pap->targettime()
<< "] "
@@ -225,7 +225,7 @@ Resolver::load_resolver_plugins()
namespace bfs = boost::filesystem;
bfs::directory_iterator end_itr;
bfs::path p( m_app->conf()->get(string("plugin_path"), string("plugins")) );
- cout << "Loading resolver plugins from: "
+ log::info() << "Loading resolver plugins from: "
<< p.string() << endl;
for(bfs::directory_iterator itr( p ); itr != end_itr; ++itr)
@@ -250,15 +250,15 @@ Resolver::load_resolver_plugins()
confopt += ".enabled";
if(app()->conf()->get<bool>(confopt, true) == false)
{
- cout << "Skipping '" << classname
+ log::info() << "Skipping '" << classname
<<"' - disabled in config file" << endl;
continue;
}
try
{
PDL::DynamicLoader & dynamicLoader =
PDL::DynamicLoader::Instance();
- cout << "Loading resolver: " << pluginfile << endl;
+ log::info() << "Loading resolver: " << pluginfile << endl;
ResolverServicePlugin * instance =
dynamicLoader.GetClassInstance< ResolverServicePlugin >
( pluginfile.c_str(), classname.c_str() );
@@ -270,7 +270,7 @@ Resolver::load_resolver_plugins()
continue;
}
m_pluginNameMap[ boost::to_lower_copy(classname) ] = instance;
- cout << "Added pluginName " << boost::to_lower_copy(classname) << endl;
+ log::info() << "Added pluginName " << boost::to_lower_copy(classname) << endl;
pap->set_script( false );
pap->set_rs( instance );
string rsopt = "plugins."+classname;
@@ -285,7 +285,7 @@ Resolver::load_resolver_plugins()
(rsopt + ".localonly", instance->localonly()) );
m_resolvers.push_back( pap );
- cout << "-> OK [w:" << pap->weight()
+ log::info() << "-> OK [w:" << pap->weight()
<< " p:" << pap->preference()
<< " t:" << pap->targettime()
<< "] "
@@ -295,7 +295,7 @@ Resolver::load_resolver_plugins()
typedef std::pair< std::string, boost::function<ss_ptr(std::string)> > sspair_t;
BOOST_FOREACH( sspair_t sp, ssfacts )
{
- cout << "-> Added SS factory for protocol '"<<sp.first<<"'" << endl;
+ log::info() << "-> Added SS factory for protocol '"<<sp.first<<"'" << endl;
m_ss_factories[ sp.first ] = sp.second;
}
}
@@ -369,9 +369,9 @@ Resolver::dispatch_runner()
}
catch(...)
{
- cout << "Error exiting Resolver::dispatch_runner" << endl;
+ log::error() << "Error exiting Resolver::dispatch_runner" << endl;
}
- cout << "Resolver dispatch_runner terminating" << endl;
+ log::info() << "Resolver dispatch_runner terminating" << endl;
}
/// go thru list of resolversservices and dispatch in order
@@ -448,7 +448,7 @@ Resolver::run_pipeline_cont( rq_ptr rq,
bool
Resolver::add_results(query_uid qid, const vector< ri_ptr >& results, string via)
{
- cout << "add_results(" << results.size() << ", '"<< via << "')" << endl;
+ log::info() << "add_results(" << results.size() << ", '"<< via << "')" << endl;
if(results.size()==0)
{
return true;
@@ -588,7 +588,7 @@ Resolver::calculate_score( const rq_ptr & rq, // query
void
Resolver::cancel_query(const query_uid & qid)
{
- cout << "Cancelling query: " << qid << endl;
+ log::info() << "Cancelling query: " << qid << endl;
// send cancel to all resolvers, in case they have cleanup to do:
BOOST_FOREACH( pa_ptr pap, m_resolvers )
{
@@ -627,7 +627,7 @@ Resolver::cancel_query(const query_uid & qid)
void
Resolver::cancel_query_timeout(query_uid qid)
{
- cout << "Stale timeout reached for QID: " << qid << endl;
+ log::info() << "Stale timeout reached for QID: " << qid << endl;
rq_ptr rq;
{
boost::mutex::scoped_lock lock(m_mut_results);
@@ -645,7 +645,7 @@ Resolver::cancel_query_timeout(query_uid qid)
}
else if( m_qidtimers.find(qid) != m_qidtimers.end() ) // not stale, reset timer
{
- cout << "Not stale, resetting timer." << endl;
+ log::info() << "Not stale, resetting timer." << endl;
m_qidtimers[qid]->expires_from_now(boost::posix_time::seconds(max_query_lifetime()-diff));
m_qidtimers[qid]->async_wait(boost::bind(&Resolver::cancel_query_timeout, this, qid));
}
@@ -730,7 +730,7 @@ Resolver::get_ss(const source_uid & sid)
if( offset == string::npos ) return ss_ptr();
string p = rip->url().substr(0, offset);
- cout << "get a SS("<<p<<") for url: " << rip->url() << endl;
+ log::info() << "get a SS("<<p<<") for url: " << rip->url() << endl;
map< std::string, boost::function<ss_ptr(std::string)> >::iterator itFac =
m_ss_factories.find(p);
@@ -743,7 +743,7 @@ Resolver::get_ss(const source_uid & sid)
vector<string> xh = rip->get_extra_headers();
BOOST_FOREACH( string h, xh )
{
- cout << "Extra header: " << h<< endl;
+ log::info() << "Extra header: " << h<< endl;
ss->set_extra_header( h );
}
return ss;
View
29 src/rs_script.cpp
@@ -23,6 +23,7 @@
#include <boost/algorithm/string.hpp>
#include "playdar/resolver.h"
+#include "playdar/logger.h"
/*
This resolver spawns an external process, typically a python/ruby script
@@ -56,7 +57,7 @@ rs_script::init(pa_ptr pap)
m_scriptpath = m_pap->scriptpath();
if(m_scriptpath=="")
{
- cout << "No script path specified. gateway plugin failed."
+ log::info() << "No script path specified. gateway plugin failed."
<< endl;
m_name = "MISSING SCRIPT PATH";
m_dead = true;
@@ -65,17 +66,17 @@ rs_script::init(pa_ptr pap)
}
else if(!boost::filesystem::exists(m_scriptpath))
{
- cout << "-> FAILED - script doesn't exist at: " << m_scriptpath << endl;
+ log::error() << "-> FAILED - script doesn't exist at: " << m_scriptpath << endl;
return false;
}
else
{
m_name = m_scriptpath; // should be overwritten by script settings
- cout << "Starting resolver process: "<<m_scriptpath << endl;
+ log::info() << "Starting resolver process: "<<m_scriptpath << endl;
// wait for script to send us a settings object:
boost::mutex::scoped_lock lk(m_mutex_settings);
init_worker(); // launch script
- cout << "-> Waiting for settings from script (5 secs)..." << endl;
+ log::info() << "-> Waiting for settings from script (5 secs)..." << endl;
if(!m_got_settings)
{
boost::xtime time;
@@ -86,13 +87,13 @@ rs_script::init(pa_ptr pap)
if(m_got_settings)
{
- cout << "-> OK, script reports name: " << m_name << endl;
+ log::info() << "-> OK, script reports name: " << m_name << endl;
// dispatcher thread:
m_dt = new boost::thread(boost::bind(&rs_script::run, this));
}
else
{
- cout << "-> FAILED - script didn't report any settings" << endl;
+ log::error() << "-> FAILED - script didn't report any settings" << endl;
m_dead = true;
m_weight = 0; // disable us.
return false;
@@ -103,7 +104,7 @@ rs_script::init(pa_ptr pap)
rs_script::~rs_script() throw()
{
- cout <<"DTOR Resolver script " << endl;
+ log::info() <<"DTOR Resolver script " << endl;
m_exiting = true;
m_cond.notify_all();
if(m_dt) m_dt->join();
@@ -119,7 +120,7 @@ rs_script::start_resolving(rq_ptr rq)
cerr << "Not dispatching to script: " << m_scriptpath << endl;
return;
}
- //cout << "gateway dispatch enqueue: " << rq->str() << endl;
+ //log::info() << "gateway dispatch enqueue: " << rq->str() << endl;
if(!rq->cancelled())
{
boost::mutex::scoped_lock lk(m_mutex);
@@ -138,7 +139,7 @@ rs_script::run()
{
rq_ptr rq;
{
- //cout << "Waiting on something" << endl;
+ //log::info() << "Waiting on something" << endl;
boost::mutex::scoped_lock lk(m_mutex);
if(m_pending.size() == 0) m_cond.wait(lk);
if(m_exiting || m_dead) break;
@@ -148,7 +149,7 @@ rs_script::run()
// dispatch query to script:
if(rq && !rq->cancelled())
{
- //cout << "Got " << rq->str() << endl;
+ //log::info() << "Got " << rq->str() << endl;
ostringstream os;
write_formatted( rq->get_json(), os );
string msg = os.str();
@@ -161,9 +162,9 @@ rs_script::run()
}
catch(...)
{
- cout << "exception in rs_script runner." << endl;
+ log::error() << "exception in rs_script runner." << endl;
}
- cout << "rs_script dispatch runner ending" << endl;
+ log::info() << "rs_script dispatch runner ending" << endl;
}
@@ -199,7 +200,7 @@ rs_script::process_stderr()
void
rs_script::process_output()
{
- cout << "Gateway process_output started.." <<endl;
+ log::info() << "Gateway process_output started.." <<endl;
using namespace json_spirit;
bp::pistream &is = m_c->get_stdout();
Value j;
@@ -305,7 +306,7 @@ rs_script::process_output()
m_pap->report_results( qid, v );
}
}
- cout << "Gateway plugin read loop exited" << endl;
+ log::info() << "Gateway plugin read loop exited" << endl;
m_dead = true;
}

0 comments on commit 44132c5

Please sign in to comment.