diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-05-03 06:49:30 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-05-03 06:49:30 +0000 |
commit | 96b00553a0ffe6bb34af6ad15e1cfc2bed67bd75 (patch) | |
tree | a930fe51f01a7400fe97b46db2fcfcdc1f2712da /src/multilogtext.cpp | |
parent | 33fef4a17290e7872293d8cc173bec826f24001c (diff) | |
download | libbu++-96b00553a0ffe6bb34af6ad15e1cfc2bed67bd75.tar.gz libbu++-96b00553a0ffe6bb34af6ad15e1cfc2bed67bd75.tar.bz2 libbu++-96b00553a0ffe6bb34af6ad15e1cfc2bed67bd75.tar.xz libbu++-96b00553a0ffe6bb34af6ad15e1cfc2bed67bd75.zip |
Added a simple test for the log system, and switched the multilog to the new
singleton system, which unfortunately changed it's API slightly. Now it's not
a pointer from the singleton, but I did add a new macro to make most usage of it
even easier.
Diffstat (limited to '')
-rw-r--r-- | src/multilogtext.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/multilogtext.cpp b/src/multilogtext.cpp index be64595..daad4c0 100644 --- a/src/multilogtext.cpp +++ b/src/multilogtext.cpp | |||
@@ -1,4 +1,3 @@ | |||
1 | |||
2 | #include <stdio.h> | 1 | #include <stdio.h> |
3 | #include <stdlib.h> | 2 | #include <stdlib.h> |
4 | #include <fcntl.h> | 3 | #include <fcntl.h> |
@@ -7,9 +6,46 @@ | |||
7 | #include <string.h> | 6 | #include <string.h> |
8 | #include "multilogtext.h" | 7 | #include "multilogtext.h" |
9 | 8 | ||
10 | MultiLogText::MultiLogText( const char *sFileName, const char *lpFormat ) | 9 | bool fileexists( const char *sPath ) |
10 | { | ||
11 | int nFileDesc = open( sPath, O_RDONLY ); | ||
12 | if( nFileDesc < 0 ) | ||
13 | { | ||
14 | return false; | ||
15 | } | ||
16 | else | ||
17 | { | ||
18 | close( nFileDesc ); | ||
19 | return true; | ||
20 | } | ||
21 | } | ||
22 | |||
23 | MultiLogText::MultiLogText( const char *sFileName, const char *lpFormat, bool bRotateLog, int nMaxLogs ) | ||
11 | { | 24 | { |
12 | this->lpFormat = NULL; | 25 | this->lpFormat = NULL; |
26 | |||
27 | if( bRotateLog ) | ||
28 | { | ||
29 | if( fileexists( sFileName ) == false ) | ||
30 | { | ||
31 | return; | ||
32 | } | ||
33 | |||
34 | int nLen = strlen( sFileName ); | ||
35 | char *buf = new char[nLen+6]; | ||
36 | sprintf( buf, "%s.", sFileName ); | ||
37 | |||
38 | for( int j = 1; j < nMaxLogs; j++ ) | ||
39 | { | ||
40 | sprintf( &buf[nLen+1], "%d", j ); | ||
41 | if( !fileexists( buf ) ) | ||
42 | { | ||
43 | rename( sFileName, buf ); | ||
44 | break; | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | |||
13 | nFD = open( sFileName, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH ); | 49 | nFD = open( sFileName, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH ); |
14 | setLogFormat( lpFormat ); | 50 | setLogFormat( lpFormat ); |
15 | } | 51 | } |