mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
sd-boot: allow setting the maximum log level
This commit is contained in:
@@ -361,6 +361,8 @@ static void print_status(Config *config, char16_t *loaded_image_path) {
|
||||
if (config->console_mode_efivar != CONSOLE_MODE_KEEP)
|
||||
printf(" console-mode (EFI var): %" PRIi64 "\n", config->console_mode_efivar);
|
||||
|
||||
printf(" log-level: %s\n", log_level_to_string(log_get_max_level()));
|
||||
|
||||
if (!ps_continue())
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "efi-log.h"
|
||||
#include "efi-string-table.h"
|
||||
#include "proto/rng.h"
|
||||
#include "util.h"
|
||||
|
||||
static unsigned log_count = 0;
|
||||
static LogLevel log_max_level = LOG_INFO;
|
||||
|
||||
static const uint8_t log_level_color[_LOG_MAX] = {
|
||||
[LOG_EMERG] = EFI_LIGHTRED,
|
||||
@@ -17,6 +19,44 @@ static const uint8_t log_level_color[_LOG_MAX] = {
|
||||
[LOG_DEBUG] = EFI_LIGHTGRAY,
|
||||
};
|
||||
|
||||
static const char *const log_level_table[_LOG_MAX] = {
|
||||
[LOG_EMERG] = "emerg",
|
||||
[LOG_ALERT] = "alert",
|
||||
[LOG_CRIT] = "crit",
|
||||
[LOG_ERR] = "err",
|
||||
[LOG_WARNING] = "warning",
|
||||
[LOG_NOTICE] = "notice",
|
||||
[LOG_INFO] = "info",
|
||||
[LOG_DEBUG] = "debug",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(log_level, LogLevel);
|
||||
|
||||
LogLevel log_get_max_level(void) {
|
||||
return log_max_level;
|
||||
}
|
||||
|
||||
int log_set_max_level(LogLevel level) {
|
||||
assert(level >= 0 && level < _LOG_MAX);
|
||||
|
||||
int old = log_max_level;
|
||||
log_max_level = level;
|
||||
return old;
|
||||
}
|
||||
|
||||
int log_set_max_level_from_string(const char *e) {
|
||||
int r;
|
||||
|
||||
assert(e);
|
||||
|
||||
r = log_level_from_string(e);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
log_set_max_level(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void freeze(void) {
|
||||
for (;;)
|
||||
BS->Stall(60 * 1000 * 1000);
|
||||
@@ -46,6 +86,9 @@ EFI_STATUS log_internal(EFI_STATUS status, LogLevel log_level, const char *forma
|
||||
assert(format);
|
||||
assert(log_level >= 0 && log_level < _LOG_MAX);
|
||||
|
||||
if (log_level > log_max_level)
|
||||
return status;
|
||||
|
||||
int32_t attr = ST->ConOut->Mode->Attribute;
|
||||
|
||||
if (ST->ConOut->Mode->CursorColumn > 0)
|
||||
|
||||
@@ -34,6 +34,13 @@ typedef enum LogLevel {
|
||||
_LOG_INVALID = -1,
|
||||
} LogLevel;
|
||||
|
||||
LogLevel log_level_from_string(const char *s) _pure_;
|
||||
const char* log_level_to_string(LogLevel l) _const_;
|
||||
|
||||
LogLevel log_get_max_level(void) _pure_;
|
||||
int log_set_max_level(LogLevel level);
|
||||
int log_set_max_level_from_string(const char *e);
|
||||
|
||||
_noreturn_ void freeze(void);
|
||||
void log_wait(void);
|
||||
_gnu_printf_(3, 4) EFI_STATUS log_internal(EFI_STATUS status, LogLevel log_level, const char *format, ...);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "efi-string.h"
|
||||
#include "macro-fundamental.h"
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
|
||||
@@ -9,5 +10,23 @@
|
||||
return name##_table[i]; \
|
||||
}
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope) \
|
||||
scope type name##_from_string(const char *s) { \
|
||||
if (!s) \
|
||||
return (type) -1; \
|
||||
for (size_t i = 0; i < ELEMENTSOF(name##_table); ++i) \
|
||||
if (streq8(name##_table[i], s)) \
|
||||
return (type) i; \
|
||||
return (type) -1; \
|
||||
}
|
||||
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP(name, type, scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \
|
||||
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope)
|
||||
|
||||
#define DEFINE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,)
|
||||
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type,)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type, static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static)
|
||||
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, static)
|
||||
|
||||
Reference in New Issue
Block a user