Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tests
testRollingFileAppender.cpp
Go to the documentation of this file.
1
#include <
log4cpp/Category.hh
>
2
#include <
log4cpp/RollingFileAppender.hh
>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <errno.h>
6
#include <iostream>
7
8
using namespace
log4cpp
;
9
using namespace
std
;
10
static
const
char
*
const
test_message
=
"message"
;
11
12
bool
remove_impl
(
const
char
* filename)
13
{
14
int
res =
remove
(filename);
15
16
if
(res != 0 && errno != ENOENT)
17
cout <<
"Can't remove file '"
<< filename <<
"'.\n"
;
18
19
return
res == 0 || (res != 0 && errno == ENOENT);
20
}
21
22
bool
remove_files
()
23
{
24
if
(!
remove_impl
(
"rolling_file.log"
))
25
return
false
;
26
if
(!
remove_impl
(
"rolling_file.log.1"
))
27
return
false
;
28
if
(!
remove_impl
(
"rolling_file.log.2"
))
29
return
false
;
30
31
return
true
;
32
}
33
34
bool
setup
()
35
{
36
if
(!
remove_files
())
37
return
false
;
38
39
Category
& root =
Category::getRoot
();
40
root.
addAppender
(
new
RollingFileAppender
(
"rolling-appender"
,
"rolling_file.log"
, 40, 3));
41
root.
setPriority
(
Priority::DEBUG
);
42
43
return
true
;
44
}
45
46
void
make_log_files
()
47
{
48
Category::getRoot
().
debugStream
() <<
test_message
<< 1;
49
Category::getRoot
().
debugStream
() <<
test_message
<< 2;
50
Category::getRoot
().
debugStream
() <<
test_message
<< 3;
51
Category::getRoot
().
debugStream
() <<
test_message
<< 4;
52
Category::getRoot
().
debugStream
() <<
test_message
<< 5;
53
}
54
55
bool
exists
(
const
char
* filename)
56
{
57
FILE* f = fopen(filename,
"r"
);
58
if
(f == NULL)
59
{
60
cout <<
"File '"
<< filename <<
"' doesn't exists.\n"
;
61
return
false
;
62
}
63
64
fclose(f);
65
66
return
true
;
67
}
68
69
bool
check_log_files
()
70
{
71
bool
result =
exists
(
"rolling_file.log"
) &&
72
exists
(
"rolling_file.log.1"
) &&
73
exists
(
"rolling_file.log.2"
);
74
75
Category::shutdown
();
76
return
result &&
remove_files
();
77
}
78
79
int
main
()
80
{
81
if
(!
setup
())
82
{
83
cout <<
"Setup has failed. Check for permissions on files 'rolling_file.log*'.\n"
;
84
return
-1;
85
}
86
87
make_log_files
();
88
89
if
(
check_log_files
())
90
return
0;
91
else
92
return
-1;
93
}
remove_files
bool remove_files()
Definition:
testRollingFileAppender.cpp:22
log4cpp::Category::debugStream
CategoryStream debugStream()
Definition:
Category.hh:330
log4cpp::Category
Definition:
Category.hh:33
std
Definition:
Portability.hh:44
log4cpp::Category::shutdown
static void shutdown()
Definition:
Category.cpp:48
make_log_files
void make_log_files()
Definition:
testRollingFileAppender.cpp:46
main
int main()
Definition:
testRollingFileAppender.cpp:79
exists
bool exists(const char *filename)
Definition:
testRollingFileAppender.cpp:55
log4cpp::Category::getRoot
static Category & getRoot()
Definition:
Category.cpp:23
log4cpp
Definition:
AbortAppender.hh:16
test_message
static const char *const test_message
Definition:
testRollingFileAppender.cpp:10
log4cpp::Category::setPriority
virtual void setPriority(Priority::Value priority)
Definition:
Category.cpp:71
remove_impl
bool remove_impl(const char *filename)
Definition:
testRollingFileAppender.cpp:12
Category.hh
check_log_files
bool check_log_files()
Definition:
testRollingFileAppender.cpp:69
log4cpp::Category::addAppender
virtual void addAppender(Appender *appender)
Definition:
Category.cpp:94
RollingFileAppender.hh
log4cpp::Priority::DEBUG
Definition:
Priority.hh:78
setup
bool setup()
Definition:
testRollingFileAppender.cpp:34
log4cpp::RollingFileAppender
Definition:
RollingFileAppender.hh:22
log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:14:17