2021-09-14 15:51:43 +00:00
|
|
|
/*
|
|
|
|
* logger.c
|
|
|
|
*
|
|
|
|
* Created on: Sep 2, 2011
|
|
|
|
* Author: Tiberiu
|
|
|
|
*/
|
|
|
|
#include <debugio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
string LogAllowedDevices[] = {
|
|
|
|
"drivers",
|
|
|
|
//"floppy",
|
|
|
|
"hal",
|
|
|
|
"fat",
|
|
|
|
"initrd",
|
|
|
|
"system",
|
|
|
|
"vfs",
|
|
|
|
//"mem",
|
|
|
|
"console",
|
2021-09-14 16:02:20 +00:00
|
|
|
"tasking",
|
2021-09-14 15:51:43 +00:00
|
|
|
0x0,
|
|
|
|
0x0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern uint8 ConsoleDefaultColor;
|
|
|
|
extern void _write_char(char c);
|
|
|
|
extern void _write_string (string s);
|
|
|
|
|
|
|
|
int32 LogWrite (uint8 error, string device, string format, ...)
|
|
|
|
{
|
|
|
|
if (!format || !*format || !device || !*device) return 0;
|
|
|
|
|
|
|
|
// Print logged information
|
|
|
|
va_list args;
|
|
|
|
va_start (args, format);
|
|
|
|
uint32 i, len = strlen(format);
|
|
|
|
uint8 temp_color = ConsoleDefaultColor;
|
|
|
|
|
|
|
|
// Check if device is allowed. Errors are allowed
|
|
|
|
uint8 allowed = error;
|
|
|
|
for (i = 0; LogAllowedDevices[i] != 0 && !allowed; i++)
|
|
|
|
if (strcasecmp(device, LogAllowedDevices[i]) == 0) allowed = 1;
|
|
|
|
|
|
|
|
if (allowed)
|
|
|
|
{
|
|
|
|
ConsoleDefaultColor = (error) ? Color(ColorRed, ColorWhite) : (1 + (i % 15)) ;
|
|
|
|
_write_char('[');
|
|
|
|
_write_string(device);
|
|
|
|
_write_char(']');
|
|
|
|
|
|
|
|
ConsoleDefaultColor = temp_color;
|
|
|
|
_write_char(' ');
|
|
|
|
}
|
|
|
|
|
2021-09-14 15:53:27 +00:00
|
|
|
else return 0;
|
|
|
|
|
2021-09-14 15:51:43 +00:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
if (format[i] != '%' && allowed) _write_char(format[i]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
switch (format[i]) {
|
|
|
|
// Character
|
|
|
|
case 'c': {
|
|
|
|
char c = va_arg (args, char);
|
2021-09-14 15:53:27 +00:00
|
|
|
_write_char(c);
|
2021-09-14 15:51:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// String
|
|
|
|
case 's': {
|
|
|
|
int32* c = (int32*) va_arg (args, string);
|
2021-09-14 15:53:27 +00:00
|
|
|
_write_string((string)c);
|
2021-09-14 15:51:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Integers
|
|
|
|
case 'd':
|
|
|
|
case 'i': {
|
|
|
|
int32 c = va_arg(args, int32); char temp[32];
|
2021-09-14 15:53:27 +00:00
|
|
|
ConvertIntToString(temp, c, 10);
|
|
|
|
_write_string(temp);
|
2021-09-14 15:51:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Integers - hex
|
|
|
|
case 'X':
|
|
|
|
case 'x': {
|
|
|
|
int32 c = va_arg(args, int32); char temp[32];
|
2021-09-14 15:53:27 +00:00
|
|
|
ConvertUIntToString(temp, c, 16);
|
|
|
|
_write_string(temp);
|
|
|
|
|
2021-09-14 15:51:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Integers - unsigned
|
|
|
|
case 'u': {
|
|
|
|
int32 c = va_arg(args, uint32); char temp[32];
|
2021-09-14 15:53:27 +00:00
|
|
|
ConvertUIntToString (temp, c, 10);
|
|
|
|
_write_string(temp);
|
|
|
|
|
2021-09-14 15:51:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Colors
|
|
|
|
case '#': {
|
|
|
|
uint8 c = va_arg(args, uint8);
|
|
|
|
ConsoleDefaultColor = c;
|
|
|
|
break; }
|
|
|
|
|
2021-09-14 15:53:27 +00:00
|
|
|
case '%' : _write_char('%'); break;
|
2021-09-14 15:51:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
2021-09-14 15:53:27 +00:00
|
|
|
ConsoleDefaultColor = temp_color;
|
2021-09-14 15:51:43 +00:00
|
|
|
ConsoleCursorUpdateHardware();
|
|
|
|
return i;
|
|
|
|
}
|