toaruos/kernel/misc/logging.c
Kevin Lange 7344a50fe0 Major changes to timing interfaces
- The kernel version has been bumped to 0.9.0
- The timer resolution in the kernel has been increased to millseconds.
- The preemptive scheduling interval has been descreased to one
  millisecond.
- Relative sleep continues to use 10 millsecond intervals for legacy
  reasons.
- `gettimeofday` now uses the internal tick counter to calculate the
  current time. Drift is calculated from the CMOS every 5 seconds and
  applies only to `gettimeofday` and other places that use it.
- The resolution of timing information provided by debug functions has
  been increased to three digits (milliseconds).
- The resolution of timing information provided by the procfs uptime
  virtual file has been increased to three digits (milliseconds).
- Functions have been added to the debug shell to read the TSC. The TSC
  is not used in timing functions at this time.
2015-04-14 23:05:07 -07:00

54 lines
1.2 KiB
C

/* vim: tabstop=4 shiftwidth=4 noexpandtab
* This file is part of ToaruOS and is released under the terms
* of the NCSA / University of Illinois License - see LICENSE.md
* Copyright (C) 2011-2014 Kevin Lange
*
* Kernel Logging Facility
*
* Maintains a log in-memory as well as to serial (unless
* told not to).
*/
#include <system.h>
#include <list.h>
#include <logging.h>
#include <va_list.h>
#include <printf.h>
log_type_t debug_level = NOTICE;
void * debug_file = NULL;
void (*debug_hook)(void *, char *) = NULL;
void (*debug_video_crash)(char **) = NULL;
static char * c_messages[] = {
" \033[1;34mINFO\033[0m:",
" \033[1;35mNOTICE\033[0m:",
" \033[1;33mWARNING\033[0m:",
" \033[1;31mERROR\033[0m:",
" \033[1;37;41mCRITICAL\033[0m:",
" \033[1;31;44mINSANE\033[0m:"
};
static char buffer[1024];
void _debug_print(char * title, int line_no, log_type_t level, char *fmt, ...) {
if (level >= debug_level && debug_file) {
va_list args;
va_start(args, fmt);
vasprintf(buffer, fmt, args);
va_end(args);
char * type;
if (level > INSANE) {
type = "";
} else {
type = c_messages[level];
}
fprintf(debug_file, "[%10d.%3d:%s:%d]%s %s\n", timer_ticks, timer_subticks, title, line_no, type, buffer);
}
/* else ignore */
}