-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathservaldswift.swift
54 lines (40 loc) · 1.73 KB
/
servaldswift.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Serval DNA daemon in Swift
Copyright 2017 Flinders University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import Foundation
import ServalDNA
import servald.log
// Logging
//
// A simplistic console log outputter that writes to standard error and is not
// configurable. Note that log_output_console.o is not linked into
// servaldswift, in order to avoid duplicate log outputs on standard error.
private func logPrint(_ level: CInt, _ message: UnsafePointer<CChar>?, _ overrun: Int8) {
let level_text = String(cString: serval_log_level_prefix_string(level)!)
let message_text = String(cString: message!)
FileHandle.standardError.write("\(level_text) \(message_text)\n".data(using:.utf8)!)
}
serval_log_delegate.print = logPrint
serval_log_delegate.minimum_level = LOG_LEVEL_WARN
serval_log_delegate.show_prolog = 1
serval_log_delegate.show_pid = 1
serval_log_delegate.show_time = 1
// Output
var contextFile = CliContextFile(FileHandle.standardOutput)
// Invocation
let status = serval_commandline_main(context: contextFile, args: CommandLine.arguments)
// Cleanup
contextFile.flush()
exit(status)