www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - vibe.d HTMLLogger

reply Chris <wendlec tcd.ie> writes:
Why does FileLogger work while HTMLLogger crashes on the same 
thing? I've had a look at the source code, but couldn't find 
anything. It happens with vibe.d `0.7.30-beta1` and `0.7.29` 
alike (haven't tested lower versions).

[Test code]
auto logLine = LogLine();
logLine.level = LogLevel.info;

// Fine
auto l = new FileLogger("log/logger_test.log");
l.minLevel = LogLevel.info;
l.beginLine(logLine);
l.put("Hello!");
l.endLine();

htmlLogger = new HTMLLogger("log/logger_test.html");
htmlLogger.minLevel = LogLevel.info;
// crashes here (at `beginLine`), if removed it works.
htmlLogger.beginLine(logLine);
htmlLogger.put("Hello!");
htmlLogger.endLine();
Oct 12 2016
parent reply Chris <wendlec tcd.ie> writes:
On Wednesday, 12 October 2016 at 11:54:14 UTC, Chris wrote:
 Why does FileLogger work while HTMLLogger crashes on the same 
 thing? I've had a look at the source code, but couldn't find 
 anything. It happens with vibe.d `0.7.30-beta1` and `0.7.29` 
 alike (haven't tested lower versions).

 [Test code]
 auto logLine = LogLine();
 logLine.level = LogLevel.info;

 // Fine
 auto l = new FileLogger("log/logger_test.log");
 l.minLevel = LogLevel.info;
 l.beginLine(logLine);
 l.put("Hello!");
 l.endLine();

 htmlLogger = new HTMLLogger("log/logger_test.html");
 htmlLogger.minLevel = LogLevel.info;
 // crashes here (at `beginLine`), if removed it works.
 htmlLogger.beginLine(logLine);
 htmlLogger.put("Hello!");
 htmlLogger.endLine();
The answer is that `HTMLLogger` needs to be given the time in the `LogLine` struct, else it fails. The time stamp is not auto generated. I completely overlooked that. Here's the culprit: cf. m_logFile.writef(`<div class="timeStamp">%s</div>`, msg.time.toISOExtString()); https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/log.d#L363
Oct 12 2016
parent Chris <wendlec tcd.ie> writes:
On Wednesday, 12 October 2016 at 14:19:36 UTC, Chris wrote:
 The answer is that `HTMLLogger` needs to be given the time in 
 the `LogLine` struct, else it fails. The time stamp is not auto 
 generated. I completely overlooked that.

 Here's the culprit:

 cf.

 m_logFile.writef(`<div class="timeStamp">%s</div>`, 
 msg.time.toISOExtString());

 https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/log.d#L363
I wonder, if the design of HTMLLogger couldn't be improved in this respect. It's not an obvious error.
Oct 12 2016