1 /* logging.c - EFI logging */
3 * Copyright © 2014-2017 Pete Batard <pete@akeo.ie>
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.
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.
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/>.
21 /* Not defined in gnu-efi yet */
22 #define SHELL_VARIABLE_GUID { \
23 0x158def5a, 0xf656, 0x419c, { 0xb0, 0x27, 0x7a, 0x31, 0x92, 0xc0, 0x79, 0xd2 } \
25 extern EFI_GUID gShellVariableGuid
;
26 EFI_GUID ShellVariable
= SHELL_VARIABLE_GUID
;
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
};
37 /* Global driver verbosity level */
38 #if !defined(DEFAULT_LOGLEVEL)
39 #define DEFAULT_LOGLEVEL FS_LOGLEVEL_NONE
41 UINTN LogLevel
= DEFAULT_LOGLEVEL
;
46 * @v Status EFI status code
49 PrintStatus(EFI_STATUS Status
)
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
);
57 Print(L
": [%d]\n", (Status
& 0x7FFFFFFF));
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
70 UINTN i
, LogVarSize
= sizeof(LogVar
);
72 Status
= RT
->GetVariable(L
"FS_LOGGING", &ShellVariable
, NULL
, &LogVarSize
, LogVar
);
73 if (Status
== EFI_SUCCESS
)
74 LogLevel
= Atoi(LogVar
);
76 for (i
=0; i
<ARRAYSIZE(PrintTable
); i
++)
77 *PrintTable
[i
] = (i
< LogLevel
)?(Print_t
)Print
:(Print_t
)PrintNone
;
79 PrintExtra(L
"LogLevel = %d\n", LogLevel
);