]> 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 // SPDX-License-Identifier: GPL-3.0-or-later
4 // Copyright (C) 2021-2024  Simon Ruderich
5
6 package safcm
7
8 import (
9         "fmt"
10 )
11
12 // LogLevel controls the number of displayed log messages. Higher levels
13 // include all messages from lower levels (e.g. LogVerbose includes all
14 // messages from LogInfo).
15 type LogLevel int
16
17 const (
18         _ LogLevel = iota
19         // Log only errors
20         LogError
21         // Log changes
22         LogInfo
23         // Log host information and changes on remote host
24         LogVerbose
25         // Log additional information and commands leading up to the changes
26         LogDebug
27         // Log output of all commands
28         LogDebug2
29         // Log all RPC messages
30         LogDebug3
31 )
32
33 func ParseLogLevel(s string) (LogLevel, error) {
34         var x LogLevel
35         switch s {
36         case "error":
37                 x = LogError
38         case "info":
39                 x = LogInfo
40         case "verbose":
41                 x = LogVerbose
42         case "debug":
43                 x = LogDebug
44         case "debug2":
45                 x = LogDebug2
46         case "debug3":
47                 x = LogDebug3
48         default:
49                 return 0, fmt.Errorf("invalid LogLevel %q", s)
50         }
51         return x, nil
52 }