mirror of https://github.com/deavmi/dlog.git
SyslogHandler
- Added new handler SyslogHandler (unittests) - Added test case
This commit is contained in:
parent
852388df42
commit
ad089bc5d2
|
@ -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…
Reference in New Issue