From ce2b2a6f5ca8e2bbdcbe90661bb39bd7d2d16422 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 21 Nov 2011 08:47:18 +0000 Subject: 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 --- sca-cpp/trunk/components/cache/datacache.cpp | 7 ++++-- sca-cpp/trunk/components/cache/memcache.hpp | 37 +++++++++++++++++++--------- sca-cpp/trunk/components/constdb/tinycdb.hpp | 31 ++++++++++++----------- sca-cpp/trunk/components/filedb/filedb.hpp | 28 +++++++++++++++------ sca-cpp/trunk/components/kvdb/leveldb.hpp | 2 +- sca-cpp/trunk/components/sqldb/pgsql.hpp | 28 ++++++++++----------- sca-cpp/trunk/kernel/monad.hpp | 5 ++++ sca-cpp/trunk/modules/http/httpd-conf | 2 +- 8 files changed, 89 insertions(+), 51 deletions(-) (limited to 'sca-cpp') 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 get(const value& key, const lambda // Lookup level2 cache const value val2 = rcache2(mklist("get", key)); - if (isNil(val2)) - return mkfailure("Couldn't get cache entry"); + if (isNil(val2)) { + ostringstream os; + os << "Couldn't get cache entry: " << key; + return mkfailure(str(os)); + } // Update level1 cache wcache1(mklist("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 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("Could not create memcached server"); + if (sc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't connect to memcached server: " << host << ":" << port; + return mkfailure(str(os)); + } const apr_status_t as = apr_memcache_add_server(mc, server); if (as != APR_SUCCESS) - return mkfailure("Could not add memcached server"); + return mkfailure("Couldn't add memcached server"); return true; } @@ -134,8 +137,11 @@ const failable 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(c_str(vs)), length(vs), 0, 27); - if (rc != APR_SUCCESS) - return mkfailure("Could not add memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't add memcached entry: " << key; + return mkfailure(str(os)); + } debug(true, "memcache::post::result"); return true; @@ -151,8 +157,11 @@ const failable 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(c_str(vs)), length(vs), 0, 27); - if (rc != APR_SUCCESS) - return mkfailure("Could not set memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't set memcached entry: " << key; + return mkfailure(str(os)); + } debug(true, "memcache::put::result"); return true; @@ -168,8 +177,11 @@ const failable 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("Could not get memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't get memcached entry: " << key; + return mkfailure(str(os)); + } const value val(scheme::readValue(string(data, size))); debug(val, "memcache::get::result"); @@ -184,8 +196,11 @@ const failable 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("Could not delete memcached entry"); + if (rc != APR_SUCCESS) { + ostringstream os; + os << "Couldn't delete memcached entry: " << key; + return mkfailure(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 cdbopen(TinyCDB& cdb) { struct stat st; const int s = stat(c_str(cdb.name), &st); if (s == -1) - return mkfailure(string("Couldn't tinycdb read database stat ") + cdb.name); + return mkfailure(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(string("Couldn't open tinycdb database file ") + cdb.name); + return mkfailure(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 cdbopen(TinyCDB& cdb) { // Reopen database const int newfd = open(c_str(cdb.name), O_RDONLY); if (newfd == -1) - return mkfailure(string("Couldn't open tinycdb database file ") + cdb.name); + return mkfailure(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 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(string("Couldn't dup tinycdb database file handle ") + cdb.name); + return mkfailure(string("Couldn't dup tinycdb database file handle: ") + cdb.name); close(newfd); debug(cdb.fd, "tinycdb::open::fd"); @@ -228,9 +228,9 @@ const failable rewrite(const lambda(buffer& buf, const unsi // Read the db header unsigned int pos = 0; if (lseek(fd, 0, SEEK_SET) != 0) - return mkfailure("Could not seek to tinycdb database start"); + return mkfailure("Couldn't seek to tinycdb database start"); if (::read(fd, buf, 2048) != 2048) - return mkfailure("Could not read tinycdb database header"); + return mkfailure("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 rewrite(const lambda(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("Could not add tinycdb entry"); + return mkfailure("Couldn'tt add tinycdb entry"); } if (pos != eod) return mkfailure("Invalid tinycdb database format"); @@ -279,7 +279,7 @@ const failable rewrite(const lambda(buffer& buf, const unsi // Save the new db if (cdb_make_finish(&cdbm) == -1) - return mkfailure("Could not save tinycdb database"); + return mkfailure("Couldn't save tinycdb database"); return true; } @@ -290,7 +290,7 @@ const failable rewrite(const lambda(buffer& buf, const unsi string tmpname = dbname(cdb) + ".XXXXXX"; int tmpfd = mkstemp(const_cast(c_str(tmpname))); if (tmpfd == -1) - return mkfailure("Could not create temporary tinycdb database"); + return mkfailure("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 rewrite(const lambda(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("Could not rename temporary tinycdb database"); + return mkfailure("Couldn't rename temporary tinycdb database"); cdbclose(cdb); failable ffd = cdbopen(cdb); if (!hasContent(ffd)) @@ -333,7 +333,7 @@ struct postFinish { } const failable 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("Could not add tinycdb entry"); + return mkfailure(string("Couldn't add tinycdb entry: ") + ks); return true; } }; @@ -379,7 +379,7 @@ struct putFinish { } const failable 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("Could not add tinycdb entry"); + return mkfailure(string("Couldn't add tinycdb entry: ") + ks); return true; } }; @@ -419,8 +419,11 @@ const failable 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("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(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 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("Couldn't post file database entry."); + if (os.fail()) { + ostringstream os; + os << "Couldn't post file database entry: " << key; + return mkfailure(str(os)); + } const failable r = write(val, os, db.format); debug(r, "filedb::post::result"); @@ -196,8 +199,11 @@ const failable 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("Couldn't put file database entry."); + if (os.fail()) { + ostringstream os; + os << "Couldn't put file database entry: " << key; + return mkfailure(str(os)); + } const failable r = write(val, os, db.format); debug(r, "filedb::put::result"); @@ -214,8 +220,11 @@ const failable 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("Couldn't get file database entry."); + if (is.fail()) { + ostringstream os; + os << "Couldn't get file database entry: " << key; + return mkfailure(str(os)); + } const failable val = read(is, db.format); debug(val, "filedb::get::result"); @@ -232,8 +241,11 @@ const failable 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("Couldn't delete file database entry."); + if (rc == -1) { + ostringstream os; + os << "Couldn't delete file database entry: " << key; + return mkfailure(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 dbopen(LevelDB& db) { const int s = stat(c_str(db.name), &st); if (s == -1) return mkfailure( - 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(string("Could not connect to postgresql database: ") + PQerrorMessage(conn)); + mkfailure(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(string("Could not reconnect to postgresql database: ") + PQerrorMessage(conn)); + return mkfailure(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(string("Could not execute postgresql column select statement: ") + pgfailure(kr, conn)); + return mkfailure(string("Couldn't execute postgresql column select statement: ") + pgfailure(kr, conn)); if (PQntuples(kr) != 2) { PQclear(kr); - return mkfailure(string("Could not find postgresql table key and value column names")); + return mkfailure(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(string("Could not prepare post postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure(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(string("Could not prepare put postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure(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(string("Could not prepare get postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure(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(string("Could not prepare delete postgresql SQL statement: ") + pgfailure(r, conn)); + return mkfailure(string("Couldn't prepare delete postgresql SQL statement: ") + pgfailure(r, conn)); PQclear(r); } return true; @@ -175,7 +175,7 @@ const failable 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(string("Could not execute insert postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure(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 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(string("Could not execute update postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure(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 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(string("Could not execute insert postgresql SQL statement: ") + pgfailure(pr, pgsql.conn)); + return mkfailure(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 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(string("Could not execute select postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure(string("Couldn't execute select postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); if (PQntuples(r) < 1) { PQclear(r); - return mkfailure(string("Could not get postgresql entry: ") + PQerrorMessage(pgsql.conn)); + return mkfailure(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 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(string("Could not execute delete postgresql SQL statement: ") + pgfailure(r, pgsql.conn)); + return mkfailure(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 const failable 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(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 -- cgit v1.2.3