]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - frontend/log.go
Move synchronization loop into new package frontend
[safcm/safcm.git] / frontend / log.go
1 // Frontend: Logging functions for programs using the safcm library
2
3 // Copyright (C) 2021  Simon Ruderich
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 package frontend
19
20 import (
21         "ruderich.org/simon/safcm"
22         "ruderich.org/simon/safcm/rpc"
23 )
24
25 type Event struct {
26         Host Host
27
28         // Only one of Error, Log and ConnEvent is set in a single event
29         Error     error
30         Log       Log
31         ConnEvent rpc.ConnEvent
32
33         Escaped bool // true if untrusted input is already escaped
34 }
35
36 type Log struct {
37         Level safcm.LogLevel
38         Text  string
39 }
40
41 func (l *Loop) Log(host Host, level safcm.LogLevel, escaped bool,
42         msg string) {
43
44         l.events <- Event{
45                 Host: host,
46                 Log: Log{
47                         Level: level,
48                         Text:  msg,
49                 },
50                 Escaped: escaped,
51         }
52 }