mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-07 21:58:50 +00:00
a79156c4d0
The daemon API is built as a Swift module called ServalDNA. The new CliContext class allows easy implementation of CLI output using Swift code. The new CliContextFile subclass is the obvious first implementation, equivalent to cli_stdio.c. The 'servaldswift' executable now uses CliContextFile to print its CLI output to standard output. The new delegated log output support constructs each log line in a buffer and prints it by calling the delegate's 'print' function at end-of-line. The 'servaldswift' executable now provides a log output delegate in Swift that simply prints to standard error, replacing log_output_console.o, which is omitted from its link.
40 lines
1020 B
Swift
40 lines
1020 B
Swift
import servald.log
|
|
|
|
private func serval_log(level: CInt, format: String, va_list: CVaListPointer) {
|
|
format.withCString { CString in
|
|
serval_vlogf(level, __whence, CString, va_list)
|
|
}
|
|
}
|
|
|
|
public func serval_log(level: CInt, text: String) {
|
|
text.withCString { CString in
|
|
withVaList([CString]) { va_list in
|
|
serval_log(level: level, format: "%s", va_list: va_list)
|
|
}
|
|
}
|
|
}
|
|
|
|
public func serval_log_fatal(_ text: String) {
|
|
serval_log(level: LOG_LEVEL_FATAL, text: text)
|
|
}
|
|
|
|
public func serval_log_error(_ text: String) {
|
|
serval_log(level: LOG_LEVEL_ERROR, text: text)
|
|
}
|
|
|
|
public func serval_log_warning(_ text: String) {
|
|
serval_log(level: LOG_LEVEL_WARN, text: text)
|
|
}
|
|
|
|
public func serval_log_hint(_ text: String) {
|
|
serval_log(level: LOG_LEVEL_HINT, text: text)
|
|
}
|
|
|
|
public func serval_log_info(_ text: String) {
|
|
serval_log(level: LOG_LEVEL_INFO, text: text)
|
|
}
|
|
|
|
public func serval_log_debug(_ text: String) {
|
|
serval_log(level: LOG_LEVEL_DEBUG, text: text)
|
|
}
|