Use HTTPD ap_log_error instead of stderr to log when running inside HTTPD, to get log piping and rotation to work.

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1222604 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jsdelfino 2011-12-23 08:18:38 +00:00
commit 681567b281
37 changed files with 172 additions and 41 deletions

View file

@ -31,6 +31,7 @@
* meantime the updates will be retrieved from the level1 cache).
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* Memcached-based cache component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -29,6 +29,7 @@
* cache without actually applying the function.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* XMPP chat sender component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -25,6 +25,7 @@
* input data from component references instead of function parameters.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* XMPP chat sender/receiver component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* TinyCDB-based database component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* File based database component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTP client component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTP client component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTP client component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTP client component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTP client component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* LevelDB-based database component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* Scribe-based log component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -24,6 +24,7 @@
* and log service invocations.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -34,6 +34,7 @@
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#undef VERSION
#undef OK
// Ignore integer conversion issues in Thrift and Scribe headers
#ifdef WANT_MAINTAINER_MODE

View file

@ -23,6 +23,7 @@
* AMQP queue listener component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* AMQP queue sender component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* PostgreSQL-based database component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* Axis2/C module that dispatches all server requests to the Tuscany Axis/2C service.
*/
#define WANT_HTTPD_LOG 1
#include "axis2.hpp"
namespace tuscany {

View file

@ -23,6 +23,7 @@
* Axis2/C service implementation that dispatches requests to SCA Web service components.
*/
#define WANT_HTTPD_LOG 1
#include "value.hpp"
#include "string.hpp"
#include "../../modules/http/httpd.hpp"

View file

@ -23,6 +23,7 @@
* Web service client component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* Web service listener component implementation.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -28,12 +28,37 @@
#include <stdio.h>
#include <stdarg.h>
#ifdef WANT_HTTPD_LOG
#include <apr_strings.h>
#include <apr_fnmatch.h>
#include <apr_lib.h>
#define APR_WANT_STRFUNC
#include <apr_want.h>
#include <apr_base64.h>
#include <httpd.h>
// Hack to workaround compile error with CLang/LLVM
#undef strtoul
// Hack to workaround compile error with HTTPD 2.3.8
#define new new_
#include <http_config.h>
#undef new
#include <http_main.h>
#include <http_log.h>
#else
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef WANT_THREADS
#include <pthread.h>
#endif
#endif
#include "string.hpp"
#include "stream.hpp"
@ -150,6 +175,73 @@ ifstream cin(stdin);
* Streams used for logging.
*/
#ifdef WANT_HTTPD_LOG
/*
* HTTPD-based log stream.
*/
class loghstream : public ostream {
public:
loghstream(const int level) : level(level), len(0) {
}
~loghstream() {
}
ostream& vprintf(const char* fmt, ...) {
va_list args;
va_start (args, fmt);
const int l = vsnprintf(buf + len, (sizeof(buf) - 1) - len, fmt, args);
va_end (args);
len += l;
if (len > (int)(sizeof(buf) - 1))
len = sizeof(buf) - 1;
return *this;
}
ostream& write(const string& s) {
if (s != "\n")
return this->vprintf("%s", c_str(s));
buf[len] = '\0';
ap_log_error(NULL, 0, -1, level, 0, ap_server_conf, "%s", buf);
len = 0;
return *this;
}
ostream& flush() {
return *this;
}
private:
const int level;
int len;
char buf[2049];
};
/**
* Info and failure log streams.
*/
loghstream cinfo(APLOG_INFO);
loghstream cfailure(APLOG_ERR);
#ifdef WANT_MAINTAINER_MODE
/**
* Debug log stream.
*/
loghstream cdebug(APLOG_DEBUG);
/**
* Return true if debug log is enabled.
*/
const bool isDebugLog() {
return APLOG_MODULE_IS_LEVEL(ap_server_conf, APLOG_NO_MODULE, APLOG_DEBUG);
}
#endif
#else
/**
* Format the current time.
*/
@ -166,25 +258,20 @@ const string logTime() {
}
/*
* Log stream.
* File-based log stream.
*/
class logfstream : public ostream {
public:
logfstream(FILE* file, const string& type) : file(file), type(type), owner(false), head(false) {
logfstream(FILE* file, const string& type) : file(file), type(type), head(false) {
}
logfstream(const logfstream& os) : file(os.file), type(os.type), owner(false), head(os.head) {
logfstream(const logfstream& os) : file(os.file), type(os.type), head(os.head) {
}
~logfstream() {
if (!owner)
return;
if (file == NULL)
return;
fclose(file);
}
logfstream& vprintf(const char* fmt, ...) {
ostream& vprintf(const char* fmt, ...) {
whead();
va_list args;
va_start (args, fmt);
@ -193,7 +280,7 @@ public:
return *this;
}
logfstream& write(const string& s) {
ostream& write(const string& s) {
whead();
fwrite(c_str(s), 1, length(s), file);
if (s == "\n")
@ -201,7 +288,7 @@ public:
return *this;
}
logfstream& flush() {
ostream& flush() {
fflush(file);
return *this;
}
@ -209,7 +296,6 @@ public:
private:
FILE* file;
const string type;
bool owner;
bool head;
const unsigned long tid() const {
@ -220,7 +306,7 @@ private:
#endif
}
logfstream& whead() {
ostream& whead() {
if (head)
return *this;
head = true;
@ -238,14 +324,29 @@ logfstream cfailure(stderr, "error");
#ifdef WANT_MAINTAINER_MODE
/**
* Debug log stream and debug functions.
* Debug log stream.
*/
logfstream cdebug(stderr, "debug");
/**
* Return true if debug log is enabled.
*/
const bool isDebugLog() {
return true;
}
#endif
#endif
#ifdef WANT_MAINTAINER_MODE
/**
* Log a debug message.
*/
const bool debugLog(const string& msg) {
if (!isDebugLog())
return true;
gc_scoped_pool();
cdebug << msg << endl;
return true;
@ -255,6 +356,8 @@ const bool debugLog(const string& msg) {
* Log a debug message and a value.
*/
template<typename V> const bool debugLog(const V& v, const string& msg) {
if (!isDebugLog())
return true;
gc_scoped_pool();
cdebug << msg << ": " << v << endl;
return true;

View file

@ -278,20 +278,15 @@ template<typename V, typename F> const lambda<failable<V, F>(const V)> success()
*/
template<typename V, typename F> const failable<V, F> mkfailure(const F& f, const bool log = true) {
#ifdef WANT_MAINTAINER_MODE
if (log) {
ostringstream os;
os << f;
if (length(str(os)) != 0)
debug(f, "failable::mkfailure");
}
#else
if (!log)
debug(f, "failable::mkfailure");
#endif
if (log) {
ostringstream os;
os << f;
if (length(str(os)) != 0)
cfailure << "failable::mkfailure" << ": " << f << endl;
}
#endif
return failable<V, F>(false, f);
}

View file

@ -81,7 +81,6 @@ 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 notice
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
Include conf/log.conf
@ -152,6 +151,7 @@ EOF
# Configure logging
cat >$root/conf/log.conf <<EOF
# Generated by: httpd-conf $*
LogLevel notice
ErrorLog $root/logs/error_log
CustomLog $root/logs/access_log combined

View file

@ -672,7 +672,6 @@ const char* debugOptional(const char* s) {
* Log a header
*/
int debugHeader(unused void* r, const char* key, const char* value) {
gc_scoped_pool();
cdebug << " header key: " << key << ", value: " << value << endl;
return 1;
}
@ -681,7 +680,6 @@ int debugHeader(unused void* r, const char* key, const char* value) {
* Log an environment variable
*/
int debugEnv(unused void* r, const char* key, const char* value) {
gc_scoped_pool();
cdebug << " var key: " << key << ", value: " << value << endl;
return 1;
}
@ -690,7 +688,6 @@ int debugEnv(unused void* r, const char* key, const char* value) {
* Log a note.
*/
int debugNote(unused void* r, const char* key, const char* value) {
gc_scoped_pool();
cdebug << " note key: " << key << ", value: " << value << endl;
return 1;
}
@ -699,6 +696,8 @@ int debugNote(unused void* r, const char* key, const char* value) {
* Log a request.
*/
const bool debugRequest(request_rec* r, const string& msg) {
if (!isDebugLog())
return true;
gc_scoped_pool();
cdebug << msg << ":" << endl;
cdebug << " unparsed uri: " << debugOptional(r->unparsed_uri) << endl;

View file

@ -33,6 +33,7 @@
#include <sys/stat.h>
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "stream.hpp"
#include "list.hpp"
@ -79,13 +80,20 @@ public:
#ifdef WANT_MAINTAINER_MODE
/**
* Log a session entry.
* Log session entries.
*/
int debugSession(unused void* r, const char* key, const char* value) {
int debugSessionEntry(unused void* r, const char* key, const char* value) {
cdebug << " session key: " << key << ", value: " << value << endl;
return 1;
}
const bool debugSession(request_rec* r, session_rec* z) {
if (!isDebugLog())
return true;
apr_table_do(debugSessionEntry, r, z->entries, NULL);
return true;
}
#endif
/**
@ -103,7 +111,7 @@ const failable<value> userInfoFromSession(const string& realm, request_rec* r) {
if (z == NULL)
return mkfailure<value>("Couldn't retrieve user session");
#ifdef WANT_MAINTAINER_MODE
apr_table_do(debugSession, r, z->entries, NULL);
debugSession(r, z);
#endif
if (ap_session_get_fn == NULL)
@ -225,8 +233,8 @@ static int checkAuthn(request_rec *r) {
if (hasContent(info)) {
// Try to authenticate the request
const value cinfo = content(info);
const failable<int> authz = checkAuthnz(cadr(assoc<value>("id", cinfo)), cadr(assoc<value>("password", cinfo)), r);
const value uinfo = content(info);
const failable<int> authz = checkAuthnz(cadr(assoc<value>("id", uinfo)), cadr(assoc<value>("password", uinfo)), r);
if (!hasContent(authz)) {
// Authentication failed, redirect to login page
@ -236,7 +244,7 @@ static int checkAuthn(request_rec *r) {
// Successfully authenticated, store the user info in the request
r->ap_auth_type = const_cast<char*>(atype);
return httpd::reportStatus(authenticated(cinfo, r));
return httpd::reportStatus(authenticated(uinfo, r));
}
}
@ -254,8 +262,8 @@ static int checkAuthn(request_rec *r) {
if (hasContent(info)) {
// Try to authenticate the request
const value cinfo = content(info);
const failable<int> authz = checkAuthnz(cadr(assoc<value>("id", cinfo)), cadr(assoc<value>("password", cinfo)), r);
const value uinfo = content(info);
const failable<int> authz = checkAuthnz(cadr(assoc<value>("id", uinfo)), cadr(assoc<value>("password", uinfo)), r);
if (!hasContent(authz)) {
// Authentication failed, redirect to login page
@ -265,7 +273,7 @@ static int checkAuthn(request_rec *r) {
// Successfully authenticated, store the user info in the request
r->ap_auth_type = const_cast<char*>(atype);
return httpd::reportStatus(authenticated(cinfo, r));
return httpd::reportStatus(authenticated(uinfo, r));
}
}

View file

@ -25,6 +25,7 @@
#include <sys/stat.h>
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "stream.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTPD module used to eval Java component implementations.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -52,13 +52,8 @@ namespace js {
* Report Javascript errors.
*/
void reportError(unused ::JSContext *cx, const char *message, JSErrorReport *report) {
#ifdef WANT_MAINTAINER_MODE
cdebug << (const char*)(report->filename? report->filename : "<no filename>") << ":"
cfailure << (const char*)(report->filename? report->filename : "<no filename>") << ":"
<< (int)report->lineno << ":" << message << endl;
#else
cerr << (const char*)(report->filename? report->filename : "<no filename>") << ":"
<< (int)report->lineno << ":" << message << endl;
#endif
}
/**

View file

@ -30,6 +30,7 @@ extern "C" {
#include <oauth.h>
}
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "stream.hpp"
#include "list.hpp"

View file

@ -25,6 +25,7 @@
#include <sys/stat.h>
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "stream.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTPD module used to eval Python component implementations.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -23,6 +23,7 @@
* HTTPD module used to eval C++ and Scheme component implementations.
*/
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"

View file

@ -26,6 +26,7 @@
#include <sys/stat.h>
#define WANT_HTTPD_LOG 1
#include "string.hpp"
#include "stream.hpp"
#include "list.hpp"