rust/src/rt/rust_srv.cpp
Marijn Haverbeke 880be6a940 Overhaul logging system in runtime
See https://github.com/graydon/rust/wiki/Logging-vision

The runtime logging categories are now treated in the same way as
modules in compiled code. Each domain now has a log_lvl that can be
used to restrict the logging from that domain (will be used to allow
logging to be restricted to a single domain).

Features dropped (can be brought back to life if there is interest):
  - Logger indentation
  - Multiple categories per log statement
  - I possibly broke some of the color code -- it confuses me
2011-04-19 16:57:13 +02:00

78 lines
1.4 KiB
C++

/*
*
*/
#include "rust_internal.h"
#include "rust_srv.h"
rust_srv::rust_srv() :
local_region(this, false),
synchronized_region(this, true) {
// Nop.
}
rust_srv::~rust_srv() {}
void
rust_srv::free(void *p) {
::free(p);
}
void *
rust_srv::malloc(size_t bytes) {
return ::malloc(bytes);
}
void *
rust_srv::realloc(void *p, size_t bytes) {
return ::realloc(p, bytes);
}
void
rust_srv::log(char const *msg) {
printf("rt: %s\n", msg);
}
void
rust_srv::fatal(const char *expression,
const char *file,
size_t line,
const char *format,
...) {
char buf[BUF_BYTES];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
char msg[BUF_BYTES];
snprintf(msg, sizeof(msg),
"fatal, '%s' failed, %s:%d %s",
expression, file, (int)line, buf);
log(msg);
exit(1);
}
void
rust_srv::warning(char const *expression,
char const *file,
size_t line,
const char *format,
...) {
char buf[BUF_BYTES];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
char msg[BUF_BYTES];
snprintf(msg, sizeof(msg),
"warning: '%s', at: %s:%d %s",
expression, file, (int)line, buf);
log(msg);
}
rust_srv *
rust_srv::clone() {
return new rust_srv();
}