]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - EDK2/efiffs/org/src/logging.c
1. change some directory structure for the build script
[Ventoy.git] / EDK2 / efiffs / org / src / logging.c
1 /* logging.c - EFI logging */
2 /*
3 * Copyright © 2014-2017 Pete Batard <pete@akeo.ie>
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
19 #include "driver.h"
20
21 /* Not defined in gnu-efi yet */
22 #define SHELL_VARIABLE_GUID { \
23 0x158def5a, 0xf656, 0x419c, { 0xb0, 0x27, 0x7a, 0x31, 0x92, 0xc0, 0x79, 0xd2 } \
24 }
25 extern EFI_GUID gShellVariableGuid;
26 EFI_GUID ShellVariable = SHELL_VARIABLE_GUID;
27
28 static UINTN PrintNone(IN CONST CHAR16 *fmt, ... ) { return 0; }
29 Print_t PrintError = PrintNone;
30 Print_t PrintWarning = PrintNone;
31 Print_t PrintInfo = PrintNone;
32 Print_t PrintDebug = PrintNone;
33 Print_t PrintExtra = PrintNone;
34 Print_t* PrintTable[] = { &PrintError, &PrintWarning, &PrintInfo,
35 &PrintDebug, &PrintExtra };
36
37 /* Global driver verbosity level */
38 #if !defined(DEFAULT_LOGLEVEL)
39 #define DEFAULT_LOGLEVEL FS_LOGLEVEL_NONE
40 #endif
41 UINTN LogLevel = DEFAULT_LOGLEVEL;
42
43 /**
44 * Print status
45 *
46 * @v Status EFI status code
47 */
48 VOID
49 PrintStatus(EFI_STATUS Status)
50 {
51 #if defined(__MAKEWITH_GNUEFI)
52 CHAR16 StatusString[64];
53 StatusToString(StatusString, Status);
54 // Make sure the Status is unsigned 32 bits
55 Print(L": [%d] %s\n", (Status & 0x7FFFFFFF), StatusString);
56 #else
57 Print(L": [%d]\n", (Status & 0x7FFFFFFF));
58 #endif
59 }
60
61 /*
62 * You can control the verbosity of the driver output by setting the shell environment
63 * variable FS_LOGGING to one of the values defined in the FS_LOGLEVEL constants
64 */
65 VOID
66 SetLogging(VOID)
67 {
68 EFI_STATUS Status;
69 CHAR16 LogVar[4];
70 UINTN i, LogVarSize = sizeof(LogVar);
71
72 Status = RT->GetVariable(L"FS_LOGGING", &ShellVariable, NULL, &LogVarSize, LogVar);
73 if (Status == EFI_SUCCESS)
74 LogLevel = Atoi(LogVar);
75
76 for (i=0; i<ARRAYSIZE(PrintTable); i++)
77 *PrintTable[i] = (i < LogLevel)?(Print_t)Print:(Print_t)PrintNone;
78
79 PrintExtra(L"LogLevel = %d\n", LogLevel);
80 }