diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-11-21 08:47:18 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-11-21 08:47:18 +0000 |
commit | ce2b2a6f5ca8e2bbdcbe90661bb39bd7d2d16422 (patch) | |
tree | c688f9721443d62109de1d955e514dbe7f5a1d3a /sca-cpp | |
parent | 57ff384203570508e81cdf5dfaa0cb96478e7654 (diff) |
Change default log level from 'info' to 'notice' and improve some of the log messages.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1204402 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp')
-rw-r--r-- | sca-cpp/trunk/components/cache/datacache.cpp | 7 | ||||
-rw-r--r-- | sca-cpp/trunk/components/cache/memcache.hpp | 37 | ||||
-rw-r--r-- | sca-cpp/trunk/components/constdb/tinycdb.hpp | 31 | ||||
-rw-r--r-- | sca-cpp/trunk/components/filedb/filedb.hpp | 28 | ||||
-rw-r--r-- | sca-cpp/trunk/components/kvdb/leveldb.hpp | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/components/sqldb/pgsql.hpp | 28 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/monad.hpp | 5 | ||||
-rwxr-xr-x | sca-cpp/trunk/modules/http/httpd-conf | 2 |
8 files changed, 89 insertions, 51 deletions
diff --git a/sca-cpp/trunk/components/cache/datacache.cpp b/sca-cpp/trunk/components/cache/datacache.cpp index e1cfdbfa57..502a57671d 100644 --- a/sca-cpp/trunk/components/cache/datacache.cpp +++ b/sca-cpp/trunk/components/cache/datacache.cpp @@ -52,8 +52,11 @@ const failable<value> get(const value& key, const lambda<value(const list<value> // Lookup level2 cache const value val2 = rcache2(mklist<value>("get", key)); - if (isNil(val2)) - return mkfailure<value>("Couldn't get cache entry"); + if (isNil(val2)) { + ostringstream os; + os << "Couldn't get cache entry: " << key; + return mkfailure<value>(str(os)); + } // Update level1 cache wcache1(mklist<value>("put", key, val2)); diff --git a/sca-cpp/trunk/components/cache/memcache.hpp b/sca-cpp/trunk/components/cache/memcache.hpp index e4cdceb6fa..5d23ff7c42 100644 --- a/sca-cpp/trunk/components/cache/memcache.hpp +++ b/sca-cpp/trunk/components/cache/memcache.hpp @@ -94,11 +94,14 @@ private: const failable<bool> addServer(const string& host, const int port) { apr_memcache_server_t *server; const apr_status_t sc = apr_memcache_server_create(pool, c_str(host), (apr_port_t)port, 1, 1, 1, 600, &server); - if (sc != APR_SUCCESS) - return mkfailure<bool>("Could not create memcached server"); + if (sc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't connect to memcached server: " << host << ":" << port; + return mkfailure<bool>(str(os)); + } const apr_status_t as = apr_memcache_add_server(mc, server); if (as != APR_SUCCESS) - return mkfailure<bool>("Could not add memcached server"); + return mkfailure<bool>("Couldn't add memcached server"); return true; } @@ -134,8 +137,11 @@ const failable<bool> post(const value& key, const value& val, const MemCached& c const string ks(scheme::writeValue(key)); const string vs(scheme::writeValue(val)); const apr_status_t rc = apr_memcache_add(cache.mc, nospaces(c_str(ks)), const_cast<char*>(c_str(vs)), length(vs), 0, 27); - if (rc != APR_SUCCESS) - return mkfailure<bool>("Could not add memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't add memcached entry: " << key; + return mkfailure<bool>(str(os)); + } debug(true, "memcache::post::result"); return true; @@ -151,8 +157,11 @@ const failable<bool> put(const value& key, const value& val, const MemCached& ca const string ks(scheme::writeValue(key)); const string vs(scheme::writeValue(val)); const apr_status_t rc = apr_memcache_set(cache.mc, nospaces(c_str(ks)), const_cast<char*>(c_str(vs)), length(vs), 0, 27); - if (rc != APR_SUCCESS) - return mkfailure<bool>("Could not set memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't set memcached entry: " << key; + return mkfailure<bool>(str(os)); + } debug(true, "memcache::put::result"); return true; @@ -168,8 +177,11 @@ const failable<value> get(const value& key, const MemCached& cache) { char *data; apr_size_t size; const apr_status_t rc = apr_memcache_getp(cache.mc, cache.pool, nospaces(c_str(ks)), &data, &size, NULL); - if (rc != APR_SUCCESS) - return mkfailure<value>("Could not get memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't get memcached entry: " << key; + return mkfailure<value>(str(os)); + } const value val(scheme::readValue(string(data, size))); debug(val, "memcache::get::result"); @@ -184,8 +196,11 @@ const failable<bool> del(const value& key, const MemCached& cache) { const string ks(scheme::writeValue(key)); const apr_status_t rc = apr_memcache_delete(cache.mc, nospaces(c_str(ks)), 0); - if (rc != APR_SUCCESS) - return mkfailure<bool>("Could not delete memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't delete memcached entry: " << key; + return mkfailure<bool>(str(os)); + } debug(true, "memcache::delete::result"); return true; diff --git a/sca-cpp/trunk/components/constdb/tinycdb.hpp b/sca-cpp/trunk/components/constdb/tinycdb.hpp index 514133b0e1..02114cf1ae 100644 --- a/sca-cpp/trunk/components/constdb/tinycdb.hpp +++ b/sca-cpp/trunk/components/constdb/tinycdb.hpp @@ -157,13 +157,13 @@ const failable<int> cdbopen(TinyCDB& cdb) { struct stat st; const int s = stat(c_str(cdb.name), &st); if (s == -1) - return mkfailure<int>(string("Couldn't tinycdb read database stat ") + cdb.name); + return mkfailure<int>(string("Couldn't tinycdb read database stat: ") + cdb.name); // Open database for the first time if (cdb.fd == -1) { cdb.fd = open(c_str(cdb.name), O_RDONLY); if (cdb.fd == -1) - return mkfailure<int>(string("Couldn't open tinycdb database file ") + cdb.name); + return mkfailure<int>(string("Couldn't open tinycdb database file: ") + cdb.name); debug(cdb.fd, "tinycdb::open::fd"); cdb.st = st; return cdb.fd; @@ -178,7 +178,7 @@ const failable<int> cdbopen(TinyCDB& cdb) { // Reopen database const int newfd = open(c_str(cdb.name), O_RDONLY); if (newfd == -1) - return mkfailure<int>(string("Couldn't open tinycdb database file ") + cdb.name); + return mkfailure<int>(string("Couldn't open tinycdb database file: ") + cdb.name); if (newfd == cdb.fd) { debug(cdb.fd, "tinycdb::open::fd"); cdb.st = st; @@ -187,7 +187,7 @@ const failable<int> cdbopen(TinyCDB& cdb) { // We got a different fd, dup it to the current fd then close it if (fcntl(newfd, F_DUPFD, cdb.fd) == -1) - return mkfailure<int>(string("Couldn't dup tinycdb database file handle ") + cdb.name); + return mkfailure<int>(string("Couldn't dup tinycdb database file handle: ") + cdb.name); close(newfd); debug(cdb.fd, "tinycdb::open::fd"); @@ -228,9 +228,9 @@ const failable<bool> rewrite(const lambda<failable<bool>(buffer& buf, const unsi // Read the db header unsigned int pos = 0; if (lseek(fd, 0, SEEK_SET) != 0) - return mkfailure<bool>("Could not seek to tinycdb database start"); + return mkfailure<bool>("Couldn't seek to tinycdb database start"); if (::read(fd, buf, 2048) != 2048) - return mkfailure<bool>("Could not read tinycdb database header"); + return mkfailure<bool>("Couldn't read tinycdb database header"); pos += 2048; unsigned int eod = cdb_unpack(buf); debug(pos, "tinycdb::rewrite::eod"); @@ -267,7 +267,7 @@ const failable<bool> rewrite(const lambda<failable<bool>(buffer& buf, const unsi // Add the entry to the new db if (cdb_make_add(&cdbm, buf, klen, ((unsigned char*)buf)+klen, vlen) == -1) - return mkfailure<bool>("Could not add tinycdb entry"); + return mkfailure<bool>("Couldn'tt add tinycdb entry"); } if (pos != eod) return mkfailure<bool>("Invalid tinycdb database format"); @@ -279,7 +279,7 @@ const failable<bool> rewrite(const lambda<failable<bool>(buffer& buf, const unsi // Save the new db if (cdb_make_finish(&cdbm) == -1) - return mkfailure<bool>("Could not save tinycdb database"); + return mkfailure<bool>("Couldn't save tinycdb database"); return true; } @@ -290,7 +290,7 @@ const failable<bool> rewrite(const lambda<failable<bool>(buffer& buf, const unsi string tmpname = dbname(cdb) + ".XXXXXX"; int tmpfd = mkstemp(const_cast<char*>(c_str(tmpname))); if (tmpfd == -1) - return mkfailure<bool>("Could not create temporary tinycdb database"); + return mkfailure<bool>("Couldn't create temporary tinycdb database"); // Rewrite the db, apply the update function to each entry buffer buf = mkbuffer(2048); @@ -303,7 +303,7 @@ const failable<bool> rewrite(const lambda<failable<bool>(buffer& buf, const unsi // Atomically replace the db and reopen it in read mode if (rename(c_str(tmpname), c_str(dbname(cdb))) == -1) - return mkfailure<bool>("Could not rename temporary tinycdb database"); + return mkfailure<bool>("Couldn't rename temporary tinycdb database"); cdbclose(cdb); failable<int> ffd = cdbopen(cdb); if (!hasContent(ffd)) @@ -333,7 +333,7 @@ struct postFinish { } const failable<bool> operator()(struct cdb_make& cdbm) const { if (cdb_make_add(&cdbm, c_str(ks), (unsigned int)length(ks), c_str(vs), (unsigned int)length(vs)) == -1) - return mkfailure<bool>("Could not add tinycdb entry"); + return mkfailure<bool>(string("Couldn't add tinycdb entry: ") + ks); return true; } }; @@ -379,7 +379,7 @@ struct putFinish { } const failable<bool> operator()(struct cdb_make& cdbm) const { if (cdb_make_add(&cdbm, c_str(ks), (unsigned int)length(ks), c_str(vs), (unsigned int)length(vs)) == -1) - return mkfailure<bool>("Could not add tinycdb entry"); + return mkfailure<bool>(string("Couldn't add tinycdb entry: ") + ks); return true; } }; @@ -419,8 +419,11 @@ const failable<value> get(const value& key, TinyCDB& cdb) { const string ks(scheme::writeValue(key)); cdbi_t vlen; - if (cdb_seek(fd, c_str(ks), (unsigned int)length(ks), &vlen) <= 0) - return mkfailure<value>("Could not get tinycdb entry"); + if (cdb_seek(fd, c_str(ks), (unsigned int)length(ks), &vlen) <= 0) { + ostringstream os; + os << "Couldn't get tinycdb entry: " << key; + return mkfailure<value>(str(os)); + } char* data = gc_cnew(vlen + 1); cdb_bread(fd, data, vlen); data[vlen] = '\0'; diff --git a/sca-cpp/trunk/components/filedb/filedb.hpp b/sca-cpp/trunk/components/filedb/filedb.hpp index 993003ce8e..ea7638320f 100644 --- a/sca-cpp/trunk/components/filedb/filedb.hpp +++ b/sca-cpp/trunk/components/filedb/filedb.hpp @@ -175,8 +175,11 @@ const failable<bool> post(const value& key, const value& val, FileDB& db) { const string fn = filename(key, db.name); debug(fn, "filedb::post::filename"); ofstream os(fn); - if (os.fail()) - return mkfailure<bool>("Couldn't post file database entry."); + if (os.fail()) { + ostringstream os; + os << "Couldn't post file database entry: " << key; + return mkfailure<bool>(str(os)); + } const failable<bool> r = write(val, os, db.format); debug(r, "filedb::post::result"); @@ -196,8 +199,11 @@ const failable<bool> put(const value& key, const value& val, FileDB& db) { const string fn = filename(key, db.name); debug(fn, "filedb::put::filename"); ofstream os(fn); - if (os.fail()) - return mkfailure<bool>("Couldn't put file database entry."); + if (os.fail()) { + ostringstream os; + os << "Couldn't put file database entry: " << key; + return mkfailure<bool>(str(os)); + } const failable<bool> r = write(val, os, db.format); debug(r, "filedb::put::result"); @@ -214,8 +220,11 @@ const failable<value> get(const value& key, FileDB& db) { const string fn = filename(key, db.name); debug(fn, "filedb::get::filename"); ifstream is(fn); - if (is.fail()) - return mkfailure<value>("Couldn't get file database entry."); + if (is.fail()) { + ostringstream os; + os << "Couldn't get file database entry: " << key; + return mkfailure<value>(str(os)); + } const failable<value> val = read(is, db.format); debug(val, "filedb::get::result"); @@ -232,8 +241,11 @@ const failable<bool> del(const value& key, FileDB& db) { const string fn = filename(key, db.name); debug(fn, "filedb::del::filename"); const int rc = unlink(c_str(fn)); - if (rc == -1) - return mkfailure<bool>("Couldn't delete file database entry."); + if (rc == -1) { + ostringstream os; + os << "Couldn't delete file database entry: " << key; + return mkfailure<bool>(str(os)); + } debug(true, "filedb::delete::result"); return true; diff --git a/sca-cpp/trunk/components/kvdb/leveldb.hpp b/sca-cpp/trunk/components/kvdb/leveldb.hpp index 96e404a6e4..b26cde73fe 100644 --- a/sca-cpp/trunk/components/kvdb/leveldb.hpp +++ b/sca-cpp/trunk/components/kvdb/leveldb.hpp @@ -158,7 +158,7 @@ const failable<int> dbopen(LevelDB& db) { const int s = stat(c_str(db.name), &st); if (s == -1) return mkfailure<int>( - string("Couldn't leveldb read database stat ") + db.name); + string("Couldn't leveldb read database stat: ") + db.name); leveldb::DB* ldb; leveldb::Options options; diff --git a/sca-cpp/trunk/components/sqldb/pgsql.hpp b/sca-cpp/trunk/components/sqldb/pgsql.hpp index 7dca38b086..df9b2724ff 100644 --- a/sca-cpp/trunk/components/sqldb/pgsql.hpp +++ b/sca-cpp/trunk/components/sqldb/pgsql.hpp @@ -63,7 +63,7 @@ public: debug(table, "pgsql::pgsql::table"); conn = PQconnectdb(c_str(conninfo)); if (PQstatus(conn) != CONNECTION_OK) { - mkfailure<bool>(string("Could not connect to postgresql database: ") + PQerrorMessage(conn)); + mkfailure<bool>(string("Couldn't connect to postgresql database: ") + PQerrorMessage(conn)); return; } setup(true); @@ -106,7 +106,7 @@ private: debug("pgsql::setup::reset"); PQreset(conn); if (PQstatus(conn) != CONNECTION_OK) - return mkfailure<bool>(string("Could not reconnect to postgresql database: ") + PQerrorMessage(conn)); + return mkfailure<bool>(string("Couldn't reconnect to postgresql database: ") + PQerrorMessage(conn)); } debug("pgsql::setup::init"); @@ -115,10 +115,10 @@ private: string ks = string("select a.attname from pg_attribute a, pg_class c where a.attrelid = c.relfilenode and c.relname = '") + table + string("' and a.attnum in (1, 2) order by a.attnum;"); PGresult* kr = PQexec(conn, c_str(ks)); if (PQresultStatus(kr) != PGRES_TUPLES_OK) - return mkfailure<bool>(string("Could not execute postgresql column select statement: ") + pgfailure(kr, conn)); + return mkfailure<bool>(string("Couldn't execute postgresql column select statement: ") + pgfailure(kr, conn)); if (PQntuples(kr) != 2) { PQclear(kr); - return mkfailure<bool>(string("Could not find postgresql table key and value column names")); + return mkfailure<bool>(string("Couldn't find postgresql table key and value column names")); } const string kname = PQgetvalue(kr, 0, 0); const string vname = PQgetvalue(kr, 1, 0); @@ -128,25 +128,25 @@ private: { PGresult* r = PQprepare(conn, "post", c_str(string("insert into ") + table + string(" values($1, $2);")), 2, NULL); if (PQresultStatus(r) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not prepare post postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure<bool>(string("Couldn't prepare post postgresql SQL statement: ") + pgfailure(r, conn)); PQclear(r); } { PGresult* r = PQprepare(conn, "put", c_str(string("update ") + table + string(" set ") + vname + string(" = $2 where ") + kname + string(" = $1;")), 2, NULL); if (PQresultStatus(r) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not prepare put postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure<bool>(string("Couldn't prepare put postgresql SQL statement: ") + pgfailure(r, conn)); PQclear(r); } { PGresult* r = PQprepare(conn, "get", c_str(string("select * from ") + table + string(" where ") + kname + string(" = $1;")), 1, NULL); if (PQresultStatus(r) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not prepare get postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure<bool>(string("Couldn't prepare get postgresql SQL statement: ") + pgfailure(r, conn)); PQclear(r); } { PGresult* r = PQprepare(conn, "delete", c_str(string("delete from ") + table + string(" where ") + kname + string(" = $1;")), 1, NULL); if (PQresultStatus(r) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not prepare delete postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure<bool>(string("Couldn't prepare delete postgresql SQL statement: ") + pgfailure(r, conn)); PQclear(r); } return true; @@ -175,7 +175,7 @@ const failable<bool> post(const value& key, const value& val, const PGSql& pgsql const char* params[2] = { c_str(ks), c_str(vs) }; PGresult* r = PQexecPrepared(pgsql.conn, "post", 2, params, NULL, NULL, 0); if (PQresultStatus(r) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not execute insert postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure<bool>(string("Couldn't execute insert postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); PQclear(r); debug(true, "pgsql::post::result"); @@ -197,7 +197,7 @@ const failable<bool> put(const value& key, const value& val, const PGSql& pgsql) const char* params[2] = { c_str(ks), c_str(vs) }; PGresult* r = PQexecPrepared(pgsql.conn, "put", 2, params, NULL, NULL, 0); if (PQresultStatus(r) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not execute update postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure<bool>(string("Couldn't execute update postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); const string t = PQcmdTuples(r); if (t != "0") { PQclear(r); @@ -208,7 +208,7 @@ const failable<bool> put(const value& key, const value& val, const PGSql& pgsql) PGresult* pr = PQexecPrepared(pgsql.conn, "post", 2, params, NULL, NULL, 0); if (PQresultStatus(pr) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not execute insert postgresql SQL statement: ") + pgfailure(pr, pgsql.conn)); + return mkfailure<bool>(string("Couldn't execute insert postgresql SQL statement: ") + pgfailure(pr, pgsql.conn)); PQclear(pr); debug(true, "pgsql::put::result"); @@ -228,10 +228,10 @@ const failable<value> get(const value& key, const PGSql& pgsql) { const char* params[1] = { c_str(ks) }; PGresult* r = PQexecPrepared(pgsql.conn, "get", 1, params, NULL, NULL, 0); if (PQresultStatus(r) != PGRES_TUPLES_OK) - return mkfailure<value>(string("Could not execute select postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure<value>(string("Couldn't execute select postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); if (PQntuples(r) < 1) { PQclear(r); - return mkfailure<value>(string("Could not get postgresql entry: ") + PQerrorMessage(pgsql.conn)); + return mkfailure<value>(string("Couldn't get postgresql entry: ") + PQerrorMessage(pgsql.conn)); } const char* data = PQgetvalue(r, 0, 1); const value val(scheme::readValue(string(data))); @@ -254,7 +254,7 @@ const failable<bool> del(const value& key, const PGSql& pgsql) { const char* params[1] = { c_str(ks) }; PGresult* r = PQexecPrepared(pgsql.conn, "delete", 1, params, NULL, NULL, 0); if (PQresultStatus(r) != PGRES_COMMAND_OK) - return mkfailure<bool>(string("Could not execute delete postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure<bool>(string("Couldn't execute delete postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); PQclear(r); debug(true, "pgsql::delete::result"); diff --git a/sca-cpp/trunk/kernel/monad.hpp b/sca-cpp/trunk/kernel/monad.hpp index d87a382ee1..34e39c72d9 100644 --- a/sca-cpp/trunk/kernel/monad.hpp +++ b/sca-cpp/trunk/kernel/monad.hpp @@ -282,6 +282,11 @@ template<typename V, typename F> const failable<V, F> mkfailure(const F& f) { os << f; if (length(str(os)) != 0) debug(f, "failable::mkfailure"); +#else + ostringstream os; + os << f; + if (length(str(os)) != 0) + cfailure << "failable::mkfailure" << ": " << f << endl; #endif return failable<V, F>(false, f); } diff --git a/sca-cpp/trunk/modules/http/httpd-conf b/sca-cpp/trunk/modules/http/httpd-conf index 67de40e5a6..9b55270bea 100755 --- a/sca-cpp/trunk/modules/http/httpd-conf +++ b/sca-cpp/trunk/modules/http/httpd-conf @@ -81,7 +81,7 @@ HostNameLookups Off # [timestamp] [access] remote-host remote-ident remote-user "request-line" # status response-size "referrer" "user-agent" "user-track" local-IP # virtual-host response-time bytes-received bytes-sent -LogLevel info +LogLevel notice ErrorLog $root/logs/error_log LogFormat "[%{%a %b %d %H:%M:%S %Y}t] [access] %h %l %u \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{cookie}n\" %A %V %D %I %O" combined CustomLog $root/logs/access_log combined |