]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - log.go
Use SPDX license identifiers
[safcm/safcm.git] / log.go
1 // RPC primitives for safcm: logging constants
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 safcm
19
20 import (
21         "fmt"
22 )
23
24 // LogLevel controls the number of displayed log messages. Higher levels
25 // include all messages from lower levels (e.g. LogVerbose includes all
26 // messages from LogInfo).
27 type LogLevel int
28
29 const (
30         _ LogLevel = iota
31         // Log only errors
32         LogError
33         // Log changes
34         LogInfo
35         // Log host information and changes on remote host
36         LogVerbose
37         // Log additional information and commands leading up to the changes
38         LogDebug
39         // Log output of all commands
40         LogDebug2
41         // Log all RPC messages
42         LogDebug3
43 )
44
45 func ParseLogLevel(s string) (LogLevel, error) {
46         var x LogLevel
47         switch s {
48         case "error":
49                 x = LogError
50         case "info":
51                 x = LogInfo
52         case "verbose":
53                 x = LogVerbose
54         case "debug":
55                 x = LogDebug
56         case "debug2":
57                 x = LogDebug2
58         case "debug3":
59                 x = LogDebug3
60         default:
61                 return 0, fmt.Errorf("invalid LogLevel %q", s)
62         }
63         return x, nil
64 }