Skip to content

Commit

Permalink
Merge pull request #409 from vibe-d/shared_sysloglogger
Browse files Browse the repository at this point in the history
Let createSyslogLogger return a shared object
  • Loading branch information
l-kramer authored Aug 2, 2024
2 parents b31822c + fdcd843 commit 27a5a86
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions source/vibe/core/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,11 @@ final class HTMLLogger : Logger {
Logger uses the stream's write function when it logs and would hence
log forevermore.
*/
SyslogLogger!StreamCallback createSyslogLogger(StreamCallback)(StreamCallback stream_callback,
shared(SyslogLogger!StreamCallback) createSyslogLogger(StreamCallback)(StreamCallback stream_callback,
SyslogFacility facility, string app_name = null, string host_name = hostName())
if (isWeaklyIsolated!StreamCallback)
{
return new SyslogLogger!StreamCallback(stream_callback, facility, app_name, host_name);
return cast(shared)new SyslogLogger!StreamCallback(stream_callback, facility, app_name, host_name);
}

/**
Expand Down Expand Up @@ -743,14 +743,16 @@ final class SyslogLogger(StreamCallback) : Logger
}

void dispose()
{
shared {
auto thisus = cast()this;

{
auto l = scopedMutexLock(m_bufferMutex);
while (!m_buffer.empty) m_bufferCondition.wait();
m_buffer.capacity = 0;
while (!thisus.m_buffer.empty) thisus.m_bufferCondition.wait();
thisus.m_buffer.capacity = 0;
}
m_bufferCondition.notifyAll();
m_writeThread.join();
thisus.m_bufferCondition.notifyAll();
thisus.m_writeThread.join();
}

/**
Expand Down Expand Up @@ -938,9 +940,9 @@ unittest

foreach (lvl; [LogLevel.debug_, LogLevel.diagnostic, LogLevel.info, LogLevel.warn, LogLevel.error, LogLevel.critical, LogLevel.fatal]) {
msg.level = lvl;
logger.beginLine(msg);
logger.put("αβγ");
logger.endLine();
(cast()logger).beginLine(msg);
(cast()logger).put("αβγ");
(cast()logger).endLine();
}
logger.dispose();
auto path = atomicLoad(gpath);
Expand Down

0 comments on commit 27a5a86

Please sign in to comment.