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
This commit is contained in:
Marijn Haverbeke
2011-04-19 12:21:57 +02:00
parent 6511d471ba
commit 880be6a940
24 changed files with 463 additions and 637 deletions

View File

@@ -14,16 +14,15 @@ circular_buffer::circular_buffer(rust_dom *dom, size_t unit_sz) :
A(dom, unit_sz, "Unit size must be larger than zero.");
DLOG(dom, rust_log::MEM | rust_log::COMM,
"new circular_buffer(buffer_sz=%d, unread=%d)"
"-> circular_buffer=0x%" PRIxPTR,
_buffer_sz, _unread, this);
DLOG(dom, mem, "new circular_buffer(buffer_sz=%d, unread=%d)"
"-> circular_buffer=0x%" PRIxPTR,
_buffer_sz, _unread, this);
A(dom, _buffer, "Failed to allocate buffer.");
}
circular_buffer::~circular_buffer() {
DLOG(dom, rust_log::MEM, "~circular_buffer 0x%" PRIxPTR, this);
DLOG(dom, mem, "~circular_buffer 0x%" PRIxPTR, this);
I(dom, _buffer);
W(dom, _unread == 0,
"freeing circular_buffer with %d unread bytes", _unread);
@@ -79,10 +78,9 @@ circular_buffer::enqueue(void *src) {
grow();
}
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer enqueue "
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
_unread, _next, _buffer_sz, unit_sz);
DLOG(dom, mem, "circular_buffer enqueue "
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
_unread, _next, _buffer_sz, unit_sz);
I(dom, _unread < _buffer_sz);
I(dom, _unread + unit_sz <= _buffer_sz);
@@ -101,8 +99,7 @@ circular_buffer::enqueue(void *src) {
memcpy(&_buffer[dst_idx], src, unit_sz);
_unread += unit_sz;
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer pushed data at index: %d", dst_idx);
DLOG(dom, mem, "circular_buffer pushed data at index: %d", dst_idx);
}
/**
@@ -117,7 +114,7 @@ circular_buffer::dequeue(void *dst) {
I(dom, _unread <= _buffer_sz);
I(dom, _buffer);
DLOG(dom, rust_log::MEM | rust_log::COMM,
DLOG(dom, mem,
"circular_buffer dequeue "
"unread: %d, next: %d, buffer_sz: %d, unit_sz: %d",
_unread, _next, _buffer_sz, unit_sz);
@@ -126,8 +123,7 @@ circular_buffer::dequeue(void *dst) {
if (dst != NULL) {
memcpy(dst, &_buffer[_next], unit_sz);
}
DLOG(dom, rust_log::MEM | rust_log::COMM,
"shifted data from index %d", _next);
DLOG(dom, mem, "shifted data from index %d", _next);
_unread -= unit_sz;
_next += unit_sz;
if (_next == _buffer_sz) {
@@ -144,8 +140,7 @@ void
circular_buffer::grow() {
size_t new_buffer_sz = _buffer_sz * 2;
I(dom, new_buffer_sz <= MAX_CIRCULAR_BUFFER_SIZE);
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer is growing to %d bytes", new_buffer_sz);
DLOG(dom, mem, "circular_buffer is growing to %d bytes", new_buffer_sz);
void *new_buffer = dom->malloc(new_buffer_sz);
transfer(new_buffer);
dom->free(_buffer);
@@ -158,8 +153,7 @@ void
circular_buffer::shrink() {
size_t new_buffer_sz = _buffer_sz / 2;
I(dom, initial_size() <= new_buffer_sz);
DLOG(dom, rust_log::MEM | rust_log::COMM,
"circular_buffer is shrinking to %d bytes", new_buffer_sz);
DLOG(dom, mem, "circular_buffer is shrinking to %d bytes", new_buffer_sz);
void *new_buffer = dom->malloc(new_buffer_sz);
transfer(new_buffer);
dom->free(_buffer);