Skip to content

Commit

Permalink
Merge pull request #92 from donglei/fixed-gc
Browse files Browse the repository at this point in the history
Logger improved for GC using
  • Loading branch information
Heromyth authored Oct 21, 2021
2 parents 6e830ec + 2aadd1f commit 7dae022
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
26 changes: 15 additions & 11 deletions source/hunt/logging/ConsoleLogger.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import std.typecons;
import std.traits;

alias LogLayoutHandler = string delegate(string time_prior, string tid, string level, string myFunc,
string msg, string file, size_t line);
string msg, string file, size_t line);

private {
__gshared LogLayoutHandler _layoutHandler;
Expand All @@ -40,8 +40,10 @@ private {
_layoutHandler = (string time_prior, string tid, string level, string fun,
string msg, string file, size_t line) {

return time_prior ~ " | " ~ tid ~ " | " ~ level ~ " | " ~ fun ~ " | " ~ msg
~ " | " ~ file ~ ":" ~ to!string(line);
import std.format;
return format("%s | %s | %s | %s | %s | %s:%d", time_prior, tid, level, fun, msg, file, line);
/* return time_prior ~ " | " ~ tid ~ " | " ~ level ~ " | " ~ fun ~ " | " ~ msg
~ " | " ~ file ~ ":" ~ to!string(line);*/
};
}

Expand Down Expand Up @@ -234,7 +236,7 @@ class ConsoleLogger {

private static string layout(string file = __FILE__, size_t line = __LINE__,
string func = __FUNCTION__)(string msg, string level) {
enum lineNum = std.conv.to!string(line);
//enum lineNum = std.conv.to!string(line);
string time_prior = Clock.currTime.toString();
string tid = std.conv.to!string(cast(size_t)getTid());

Expand All @@ -250,12 +252,14 @@ class ConsoleLogger {
fun = func[index + 1 .. $];
}

LogLayoutHandler handler = layoutHandler();
if(handler !is null) {
return handler(time_prior, tid, level, fun, msg, file, line);
} else {
return time_prior ~ " | " ~ tid ~ " | " ~ level ~ " | " ~ fun ~ " | " ~ msg
~ " | " ~ file ~ ":" ~ lineNum;
LogLayoutHandler handler = layoutHandler();
if(handler !is null) {
return handler(time_prior, tid, level, fun, msg, file, line);
} else {
import std.format;
return format("%s | %s | %s | %s | %s | %s:%d", time_prior, tid, level, fun, msg, file, line);
/* return time_prior ~ " | " ~ tid ~ " | " ~ level ~ " | " ~ fun ~ " | " ~ msg
~ " | " ~ file ~ ":" ~ lineNum;*/
}
}

Expand Down Expand Up @@ -383,7 +387,7 @@ class ConsoleLogger {


void setLogLayout(LogLayoutHandler handler) {
_layoutHandler = handler;
_layoutHandler = handler;
}


Expand Down
13 changes: 8 additions & 5 deletions source/hunt/logging/Logger.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ LogLayoutHandler layoutHandler() {
if(_layoutHandler is null) {
_layoutHandler = (string time_prior, string tid, string level, string myFunc,
string msg, string file, size_t line) {

return time_prior ~ " (" ~ tid ~ ") [" ~ level ~ "] " ~ myFunc ~
" - " ~ msg ~ " - " ~ file ~ ":" ~ to!string(line);
import std.format;
return format("%s (%s) [%s] %s - %s - %s:%d", time_prior, tid, level, myFunc, msg, file, line);
//return time_prior ~ " (" ~ tid ~ ") [" ~ level ~ "] " ~ myFunc ~
// " - " ~ msg ~ " - " ~ file ~ ":" ~ to!string(line);
};
}

Expand Down Expand Up @@ -591,8 +592,10 @@ protected:
if(handler !is null) {
return handler(time_prior, tid, toString(level), myFunc, msg, file, line);
} else {
return time_prior ~ " (" ~ tid ~ ") [" ~ toString(
level) ~ "] " ~ myFunc ~ " - " ~ msg ~ " - " ~ file ~ ":" ~ to!string(line);
/*return time_prior ~ " (" ~ tid ~ ") [" ~ toString(
level) ~ "] " ~ myFunc ~ " - " ~ msg ~ " - " ~ file ~ ":" ~ to!string(line);*/
import std.format;
return format("%s | %s | %s | %s | %s | %s:%d", time_prior, tid, level, myFunc, msg, file, line);
}
}

Expand Down

0 comments on commit 7dae022

Please sign in to comment.