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

SyslogHandler #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions source/dlog/syslog.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module dlog.syslog;

import core.sys.posix.syslog : openlog, syslog, closelog;

import dlog.core : Handler, Message;
import dlog.basic : BasicMessage;

/**
* A file-based handler which
* writes `BasicMessage`(s)
* to a provided file
*/
public class SyslogHandler : Handler
{
this(string name)
{
// TODO: what top set options and facility to?
openlog(name.ptr, 0, 0);
}

/**
* Handles the message, does a
* no-op if the message is
* not a kind-of `BasicMessage`
*
* Params:
* message = the message
*/
public void handle(Message message)
{
// Only handle BasicMessage(s)
BasicMessage bmesg = cast(BasicMessage)message;
if(bmesg)
{
// TODO: What to set priortiy to?
syslog(0, bmesg.getText().ptr);
}
}

~this()
{
closelog();
}
}

unittest
{
BasicLogger log = new BasicLogger();
log.addHandler(new SyslogHandler("Ting"));
log.log(new BasicMessage("Howdy"));

}

version(unittest)
{
import dlog.basic;
}
Loading