aboutsummaryrefslogtreecommitdiff
path: root/src/multilog.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
committerMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
commitf7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54 (patch)
tree53cec4864776e07950e3c72f2a990a1017d08045 /src/multilog.cpp
downloadlibbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.gz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.bz2
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.xz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.zip
libbu++ is finally laid out the way it should be, trunk, branches, and tags.
Diffstat (limited to '')
-rw-r--r--src/multilog.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/multilog.cpp b/src/multilog.cpp
new file mode 100644
index 0000000..64ff967
--- /dev/null
+++ b/src/multilog.cpp
@@ -0,0 +1,143 @@
1/***************************************************************************
2 multilog.cpp - description
3 -------------------
4 begin : Sat Sep 6 2003
5 copyright : (C) 2003 by Mike Buland
6 email : eichlan@yf-soft.com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "multilog.h"
19#include <stdio.h>
20#include <time.h>
21#include <string.h>
22#include <stdlib.h>
23
24#include "multilogchannel.h"
25
26// This section is what we need to make this a singleton
27// this makes this class easy to use from anywhere, without
28// worrying about re-creating every output form and all of that crazy jazz
29MultiLog *MultiLog::singleLog = NULL;
30
31MultiLog *MultiLog::getLog()
32{
33 if( singleLog == NULL )
34 {
35 singleLog = new MultiLog;
36 atexit( cleanup );
37 }
38 return singleLog;
39}
40
41void MultiLog::cleanup()
42{
43 if( singleLog != NULL )
44 {
45 delete singleLog;
46 singleLog = NULL;
47 }
48}
49
50MultiLog::MultiLog()
51{
52 lChannel = new LinkedList();
53 rEntry = new RingList( 150 );
54 nEntriesLost = 0;
55}
56
57MultiLog::~MultiLog()
58{
59 int nMax = lChannel->getSize();
60 for( int j = 0; j < nMax; j++ )
61 {
62 ((MultiLogChannel *)lChannel->getAt(j))->closeLog();
63 delete ((MultiLogChannel *)lChannel->getAt(j));
64 }
65 delete lChannel;
66
67 for( int j = 0; j < rEntry->getSize(); j++ )
68 {
69 delete (LogEntry *)rEntry->getAt( j );
70 }
71 delete rEntry;
72}
73/*
74void MultiLog::Log( int nLevel, const char *lpFormat, ...)
75{
76 switch( nLevel )
77 {
78 default:
79 break;
80 }
81 va_list ap;
82 va_start(ap, lpFormat);
83
84 vprintf( lpFormat, ap );
85
86 va_end(ap);
87}*/
88
89void MultiLog::DetailLog( int nLevel, const char *lpFile, int nLine, const char *lpFunction, const char *lpFormat, ...)
90{
91 LogEntry *e = new LogEntry();
92
93 va_list ap;
94 va_start(ap, lpFormat);
95 char *text;
96 vasprintf( &text, lpFormat, ap );
97 va_end(ap);
98
99 time( &e->xTime );
100 e->nLevel = nLevel;
101 e->nLine = nLine;
102 e->lpFile = new char[strlen(lpFile)+1];
103 strcpy( e->lpFile, lpFile );
104 e->lpText = new char[strlen(text)+1];
105 strcpy( e->lpText, text );
106 free( text );
107
108 append( e );
109}
110
111void MultiLog::append( LogEntry *pEntry )
112{
113 rEntry->append( pEntry );
114 if( rEntry->getPushBuf() )
115 {
116 delete (LogEntry *)rEntry->getPushBuf();
117 nEntriesLost++;
118 }
119
120 for( int j = 0; j < lChannel->getSize(); j++ )
121 {
122 ((MultiLogChannel *)lChannel->getAt( j ))->append( pEntry );
123 }
124}
125
126void MultiLog::addChannel( MultiLogChannel *pChannel )
127{
128 lChannel->append( pChannel );
129
130 pChannel->openLog();
131
132 for( int j = 0; j < rEntry->getSize(); j++ )
133 {
134 pChannel->append( (LogEntry *)rEntry->getAt( j ) );
135 }
136}
137
138MultiLog::LogEntry::~LogEntry()
139{
140 delete[] lpFile;
141 delete[] lpText;
142}
143