Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access logging due to very nasty bug in Phobos' formatedWrite #808

Merged
merged 3 commits into from Sep 8, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions source/vibe/core/log.d
Expand Up @@ -38,10 +38,12 @@ nothrow @safe {

This level applies to the default stdout/stderr logger only.
*/
void setLogFormat(FileLogger.Format fmt)
void setLogFormat(FileLogger.Format fmt, FileLogger.Format infoFmt = FileLogger.Format.plain)
nothrow @safe {
assert(ss_stdoutLogger !is null, "Console logging disabled du to missing console.");
ss_stdoutLogger.lock().format = fmt;
auto l = ss_stdoutLogger.lock();
l.format = fmt;
l.infoFormat = infoFmt;
}


Expand Down Expand Up @@ -207,6 +209,7 @@ final class FileLogger : Logger {
}

Format format = Format.thread;
Format infoFormat = Format.plain;

this(File info_file, File diag_file)
{
Expand Down Expand Up @@ -238,9 +241,7 @@ final class FileLogger : Logger {
case LogLevel.none: assert(false);
}

auto fmt = this.format;
// force informational output to be in plain form
if (file !is m_diagFile) fmt = Format.plain;
auto fmt = (file is m_diagFile) ? this.format : this.infoFormat;

final switch (fmt) {
case Format.plain: file.writeln(msg.text); break;
Expand Down
14 changes: 8 additions & 6 deletions source/vibe/http/log.d
Expand Up @@ -173,7 +173,7 @@ void formatApacheLog(R)(ref R ln, string format, HTTPServerRequest req, HTTPServ
//case 'B': //Size of Response in bytes, excluding headers
case 'b': //same as 'B' but a '-' is written if no bytes where sent
if (!res.bytesWritten) ln.put('-');
else ln.formattedWrite("%s", res.bytesWritten);
else formattedWrite(&ln, "%s", res.bytesWritten);
break;
case 'C': //Cookie content {cookie}
enforce(key, "cookie name missing");
Expand All @@ -182,7 +182,7 @@ void formatApacheLog(R)(ref R ln, string format, HTTPServerRequest req, HTTPServ
break;
case 'D': //The time taken to serve the request
auto d = res.timeFinalized - req.timeCreated;
ln.formattedWrite("%s", d.total!"msecs"());
formattedWrite(&ln, "%s", d.total!"msecs"());
break;
//case 'e': //Environment variable {variable}
//case 'f': //Filename
Expand All @@ -206,25 +206,27 @@ void formatApacheLog(R)(ref R ln, string format, HTTPServerRequest req, HTTPServ
else ln.put("-");
break;
case 'p': //port
ln.formattedWrite("%s", settings.port);
formattedWrite(&ln, "%s", settings.port);
break;
//case 'P': //Process ID
case 'q': //query string (with prepending '?')
ln.put("?");
ln.put(req.queryString);
break;
case 'r': //First line of Request
ln.formattedWrite("%s %s %s", httpMethodString(req.method), req.requestURL, getHTTPVersionString(req.httpVersion));
ln.put(httpMethodString(req.method));
ln.put(req.requestURL);
ln.put(getHTTPVersionString(req.httpVersion));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the spaces between the individual values.

break;
case 's': //Status
ln.formattedWrite("%s", res.statusCode);
formattedWrite(&ln, "%s", res.statusCode);
break;
case 't': //Time the request was received {format}
ln.put(req.timeCreated.toSimpleString());
break;
case 'T': //Time taken to server the request in seconds
auto d = res.timeFinalized - req.timeCreated;
ln.formattedWrite("%s", d.total!"seconds");
formattedWrite(&ln, "%s", d.total!"seconds");
break;
case 'u': //Remote user
ln.put(req.username.length ? req.username : "-");
Expand Down