File: debug.cc

package info (click to toggle)
sms-pl 1.8.9i-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 356 kB
  • ctags: 294
  • sloc: cpp: 1,837; ansic: 625; perl: 272; makefile: 101; sh: 29
file content (56 lines) | stat: -rw-r--r-- 848 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "debug.h"
#include "vsprintf.h"

Debug::Debug(const char *file)
{
     name = strdup(file);
     str = NULL;
}

Debug::~Debug()
{
     if (str) delete str;
     if (name) free(name);
}

void Debug::Open()
{
#ifdef DEBUG
     if (!str) str = new ofstream(name);
#endif
}

void Debug::Log(int level, const char *msg, ...)
{
    if (!str) Open();
    if (!str) return;
    
    char buf[MAX_LOG_LINE_LEN];
    va_list args;
    ofstream &stream = *str;

    va_start(args, msg);
    VSPRINTF(buf, sizeof(buf)-1, msg, args);
    va_end(args);

    stream << buf << std::endl;
}

Exception::Exception(const char *str)
{
        what = strdup(str);
}

Exception::~Exception()
{
        if (what) free(what);
}

const char *Exception::Info()
{
        return what;
}