Skip to content

Commit

Permalink
Add enableLoggerOverride/disableLoggerOverride
Browse files Browse the repository at this point in the history
  • Loading branch information
trikko committed Dec 17, 2024
1 parent 7fe5a71 commit ceb0888
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 9 additions & 1 deletion source/serverino/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ struct ServerinoConfig

sc.disableRemoteIp();

sc.enableLoggerOverride();

return sc;
}

Expand Down Expand Up @@ -217,6 +219,12 @@ struct ServerinoConfig
/// How long the socket will wait for a request after the connection?
@safe ref ServerinoConfig setHttpTimeout(Duration dur = 10.seconds) return { daemonConfig.maxHttpWaiting = dur; workerConfig.maxHttpWaiting = dur; return this;}

/// Enable/Disable std.logger override
@safe ref ServerinoConfig enableLoggerOverride(bool enable = true) return { daemonConfig.overrideLogger = enable; return this; }

/// Ditto
@safe ref ServerinoConfig disableLoggerOverride() return { daemonConfig.overrideLogger = false; return this; }

/// Enable/Disable keep-alive for http/1.1
@safe ref ServerinoConfig enableKeepAlive(bool enable = true, Duration timeout = 3.seconds) return { workerConfig.keepAlive = enable; daemonConfig.keepAliveTimeout = timeout; return this; }

Expand Down Expand Up @@ -347,6 +355,6 @@ package struct DaemonConfig
size_t maxWorkers;
int listenerBacklog;
bool withRemoteIp;

bool overrideLogger;
Listener[] listeners;
}
13 changes: 7 additions & 6 deletions source/serverino/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class ServerinoLogger : Logger

private static immutable string[LogLevel] LLSTR;
private static immutable string logPrefix;
private File outputStream;
}

enum OnMainThread; /// Let serverino run in the main thread (default)
Expand Down Expand Up @@ -202,12 +201,14 @@ template ServerinoLoop(Modules...)

int wakeServerino(Modules...)(ref ServerinoConfig config)
{
import std.experimental.logger : sharedLog;

static if (version_minor > 100)
sharedLog = new shared ServerinoLogger(config.daemonConfig.logLevel);
else
sharedLog = new ServerinoLogger(config.daemonConfig.logLevel);
if (config.daemonConfig.overrideLogger)
{
import std.experimental.logger : sharedLog;

static if (version_minor > 100) sharedLog = new shared ServerinoLogger(config.daemonConfig.logLevel);
else sharedLog = new ServerinoLogger(config.daemonConfig.logLevel);
}

if (config.returnCode != 0)
return config.returnCode;
Expand Down

0 comments on commit ceb0888

Please sign in to comment.