aboutsummaryrefslogtreecommitdiff
path: root/src/old/multilog.cpp
blob: 143ee89f19bacca8cf38efb3e468c59514c033d9 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "multilog.h"
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>

#include "multilogchannel.h"

MultiLog::MultiLog()
{
	lChannel = new LinkedList();
	rEntry = new RingList( 150 );
	nEntriesLost = 0;
}

MultiLog::~MultiLog()
{
	int nMax = lChannel->getSize();
	for( int j = 0; j < nMax; j++ )
	{
		((MultiLogChannel *)lChannel->getAt(j))->closeLog();
		delete ((MultiLogChannel *)lChannel->getAt(j));
	}
	delete lChannel;
	
	for( int j = 0; j < rEntry->getSize(); j++ )
	{
		delete (LogEntry *)rEntry->getAt( j );
	}
	delete rEntry;
}
/*
void MultiLog::Log( int nLevel, const char *lpFormat, ...)
{
	switch( nLevel )
	{
		default:
			break;
	}
	va_list ap;
	va_start(ap, lpFormat);

	vprintf( lpFormat, ap );

	va_end(ap);
}*/

void MultiLog::DetailLog( int nLevel, const char *lpFile, int nLine, const char *lpFunction, const char *lpFormat, ...)
{
	LogEntry *e = new LogEntry();

	va_list ap;
	va_start(ap, lpFormat);
	char *text;
	vasprintf( &text, lpFormat, ap );
	va_end(ap);
	
	time( &e->xTime );
	e->nLevel = nLevel;
	e->nLine = nLine;
	e->lpFile = new char[strlen(lpFile)+1];
	strcpy( e->lpFile, lpFile );
	e->lpText = new char[strlen(text)+1];
	strcpy( e->lpText, text );
	free( text );
	
	append( e );
}

void MultiLog::append( LogEntry *pEntry )
{
	rEntry->append( pEntry );
	if( rEntry->getPushBuf() )
	{
		delete (LogEntry *)rEntry->getPushBuf();
		nEntriesLost++;
	}

	for( int j = 0; j < lChannel->getSize(); j++ )
	{
		((MultiLogChannel *)lChannel->getAt( j ))->append( pEntry );
	}
}

void MultiLog::addChannel( MultiLogChannel *pChannel )
{
	lChannel->append( pChannel );
	
	pChannel->openLog();
	
	for( int j = 0; j < rEntry->getSize(); j++ )
	{
		pChannel->append( (LogEntry *)rEntry->getAt( j ) );
	}
}

MultiLog::LogEntry::~LogEntry()
{
	delete[] lpFile;
	delete[] lpText;
}