2023-04-17 00:26:46 +02:00
|
|
|
// apparmor.d - Full set of apparmor profiles
|
2024-02-07 00:16:21 +01:00
|
|
|
// Copyright (C) 2023-2024 Alexandre Pujol <alexandre@pujol.io>
|
2023-04-17 00:26:46 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
package logging
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Colors
|
|
|
|
const (
|
|
|
|
reset = "\033[0m"
|
|
|
|
bold = "\033[1m"
|
|
|
|
boldRed = "\033[1;31m"
|
|
|
|
boldGreen = "\033[1;32m"
|
|
|
|
boldYellow = "\033[1;33m"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Logging messages prefix
|
|
|
|
const (
|
|
|
|
bulletText = bold + " ⋅ " + reset
|
2023-05-06 14:23:16 +02:00
|
|
|
fatalText = boldRed + " ✗ Error: " + reset
|
|
|
|
errorText = boldRed + " ✗ " + reset
|
2023-04-17 00:26:46 +02:00
|
|
|
successText = boldGreen + " ✓ " + reset
|
|
|
|
warningText = boldYellow + " ‼ " + reset
|
|
|
|
)
|
|
|
|
|
2023-12-13 18:39:21 +01:00
|
|
|
var Indent = ""
|
|
|
|
|
2023-04-17 00:26:46 +02:00
|
|
|
// Print prints a formatted message. Arguments are handled in the manner of fmt.Print.
|
|
|
|
func Print(msg string, a ...interface{}) int {
|
|
|
|
n, _ := fmt.Fprintf(os.Stdout, msg, a...)
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
// Println prints a formatted message. Arguments are handled in the manner of fmt.Println.
|
|
|
|
func Println(msg string) int {
|
2024-08-20 20:07:56 +02:00
|
|
|
n, _ := fmt.Fprintf(os.Stdout, "%s\n", msg)
|
2023-04-17 00:26:46 +02:00
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bulletf returns a formatted bullet point string
|
|
|
|
func Bulletf(msg string, a ...interface{}) string {
|
2023-12-13 18:39:21 +01:00
|
|
|
return fmt.Sprintf("%s%s%s\n", Indent, bulletText, fmt.Sprintf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bullet prints a formatted bullet point string
|
|
|
|
func Bullet(msg string, a ...interface{}) int {
|
2024-08-20 20:07:56 +02:00
|
|
|
return Print("%s", Bulletf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stepf returns a formatted step string
|
|
|
|
func Stepf(msg string, a ...interface{}) string {
|
2023-12-13 18:39:21 +01:00
|
|
|
return fmt.Sprintf("%s%s%s\033[0m\n", Indent, boldGreen, fmt.Sprintf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Step prints a step title
|
|
|
|
func Step(msg string, a ...interface{}) int {
|
2024-08-20 20:07:56 +02:00
|
|
|
return Print("%s", Stepf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Successf returns a formatted success string
|
|
|
|
func Successf(msg string, a ...interface{}) string {
|
2023-12-13 18:39:21 +01:00
|
|
|
return fmt.Sprintf("%s%s%s\n", Indent, successText, fmt.Sprintf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Success prints a formatted success message to stdout
|
|
|
|
func Success(msg string, a ...interface{}) int {
|
2024-08-20 20:07:56 +02:00
|
|
|
return Print("%s", Successf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Warningf returns a formatted warning string
|
|
|
|
func Warningf(msg string, a ...interface{}) string {
|
2023-12-13 18:39:21 +01:00
|
|
|
return fmt.Sprintf("%s%s%s\n", Indent, warningText, fmt.Sprintf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Warning prints a formatted warning message to stdout
|
|
|
|
func Warning(msg string, a ...interface{}) int {
|
2024-08-20 20:07:56 +02:00
|
|
|
return Print("%s", Warningf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-06 14:23:16 +02:00
|
|
|
// Fatalf returns a formatted error message
|
|
|
|
func Error(msg string, a ...interface{}) int {
|
2024-08-20 20:07:56 +02:00
|
|
|
return Print("%s", fmt.Sprintf("%s%s%s\n", Indent, errorText, fmt.Sprintf(msg, a...)))
|
2023-05-06 14:23:16 +02:00
|
|
|
}
|
|
|
|
|
2023-04-17 00:26:46 +02:00
|
|
|
// Fatalf returns a formatted error message
|
|
|
|
func Fatalf(msg string, a ...interface{}) string {
|
2023-12-13 18:39:21 +01:00
|
|
|
return fmt.Sprintf("%s%s%s\n", Indent, fatalText, fmt.Sprintf(msg, a...))
|
2023-04-17 00:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fatal is equivalent to Print() followed by a call to os.Exit(1).
|
|
|
|
func Fatal(msg string, a ...interface{}) {
|
|
|
|
fmt.Fprint(os.Stderr, Fatalf(msg, a...))
|
|
|
|
os.Exit(1)
|
|
|
|
}
|