1 module rfc5424; 2 3 public import vibe.core.log; 4 5 version (unittest) 6 { 7 void safelog(string msg) @trusted @nogc nothrow 8 { 9 import core.stdc.stdio : printf; 10 11 printf("%.*s\n", msg.length, &msg[0]); 12 } 13 14 void testFunctionality()() 15 { 16 import std.conv : hexString; 17 18 enum BOM = hexString!"EFBBBF"; 19 20 import vibe.core.file; 21 22 auto fstream = createTempFile(); 23 auto logger = new SyslogLogger!FileStream(fstream, 24 SyslogLogger!FileStream.Facility.local1, "appname", null); 25 LogLine msg; 26 import std.datetime; 27 import core.thread; 28 29 static if (is(typeof(SysTime.init.fracSecs))) 30 auto fs = 1.dur!"usecs"; 31 else 32 auto fs = FracSec.from!"usecs"(1); 33 msg.time = SysTime(DateTime(0, 1, 1, 0, 0, 0), fs); 34 35 foreach (lvl; [ 36 LogLevel.debug_, LogLevel.diagnostic, LogLevel.info, LogLevel.warn, 37 LogLevel.error, LogLevel.critical, LogLevel.fatal 38 ]) 39 { 40 msg.level = lvl; 41 logger.beginLine(msg); 42 logger.put("αβγ"); 43 logger.endLine(); 44 } 45 fstream.close(); 46 47 import std.file; 48 import std.string; 49 50 auto lines = splitLines(readFileUTF8(fstream.path()), KeepTerminator.yes); 51 assert(lines.length == 7); 52 assert( 53 lines[0] == "<143>1 0000-01-01T00:00:00.000001 - " ~ BOM 54 ~ "appname - - - " ~ BOM ~ "αβγ\n"); 55 assert( 56 lines[1] == "<142>1 0000-01-01T00:00:00.000001 - " ~ BOM 57 ~ "appname - - - " ~ BOM ~ "αβγ\n"); 58 assert( 59 lines[2] == "<141>1 0000-01-01T00:00:00.000001 - " ~ BOM 60 ~ "appname - - - " ~ BOM ~ "αβγ\n"); 61 assert( 62 lines[3] == "<140>1 0000-01-01T00:00:00.000001 - " ~ BOM 63 ~ "appname - - - " ~ BOM ~ "αβγ\n"); 64 assert( 65 lines[4] == "<139>1 0000-01-01T00:00:00.000001 - " ~ BOM 66 ~ "appname - - - " ~ BOM ~ "αβγ\n"); 67 assert( 68 lines[5] == "<138>1 0000-01-01T00:00:00.000001 - " ~ BOM 69 ~ "appname - - - " ~ BOM ~ "αβγ\n"); 70 assert( 71 lines[6] == "<137>1 0000-01-01T00:00:00.000001 - " ~ BOM 72 ~ "appname - - - " ~ BOM ~ "αβγ\n"); 73 removeFile(fstream.path()); 74 } 75 76 unittest 77 { 78 testFunctionality(); 79 safelog("package works"); 80 } 81 82 @safe unittest 83 { 84 static if (__traits(compiles, testFunctionality())) 85 { 86 pragma(msg, "package is @safe"); 87 } 88 else 89 { 90 pragma(msg, "package is not @safe"); 91 } 92 } 93 94 @nogc unittest 95 { 96 static if (__traits(compiles, testFunctionality())) 97 { 98 pragma(msg, "package is @nogc"); 99 } 100 else 101 { 102 pragma(msg, "package is not @nogc"); 103 } 104 } 105 106 nothrow unittest 107 { 108 static if (__traits(compiles, testFunctionality())) 109 { 110 pragma(msg, "package is nothrow"); 111 } 112 else 113 { 114 pragma(msg, "package is not nothrow"); 115 } 116 } 117 }