1 /*
2  *
3  * appender_type_stream.h
4  *
5  * Copyright 2001-2003, Meiosys (www.meiosys.com). All rights reserved.
6  *
7  * See the COPYING file for the terms of usage and distribution.
8  */
9 
10 #ifndef log4c_appender_type_stream2_h
11 #define log4c_appender_type_stream2_h
12 
13 /**
14  * @file appender_type_stream2.h
15  *
16  * @brief Log4c stream2 appender interface.
17  *
18  * The stream2 appender uses a file handle @c FILE* for logging.
19  * It can be used with @c stdout, @c stderr or a normal file.
20  * It is pretty primitive as it does not do file rotation, or have a maximum
21  * configurable file size etc. It improves on the stream appender in a few
22  * ways that make it a better starting point for new stream based appenders.
23  *
24  * It enhances the stream appender by allowing
25  * the default file pointer to be used in buffered or unbuffered mode.
26  * Also when you set the file pointer stream2 will not attempt to close
27  * it on exit which avoids it fighting with the owner of the file pointer.
28  * stream2 is configured via setter functions--the udata is
29  * not exposed directly.  This means that new options (eg. configure the open
30  * mode ) could be added to stream2 while maintaining backward compatability.
31  *
32  * The appender can be used with default values, for example as follows:
33  *
34  * @code
35  * log4c_appender_t* myappender;
36  *
37  * myappender = log4c_appender_get("/var/logs/mylog.log");
38  * log4c_appender_set_type(myappender,log4c_appender_type_get("stream2"));
39  *
40  * @endcode
41  *
42  * In this case the appender will  be configured automatically with default
43  * values:
44  * @li the filename is the same as the name of the appender,
45  * @c "/var/logs/mymlog.log"
46  * @li the file is opened in "w+" mode
47  * @li the default system buffer is used (cf; @c setbuf() ) in buffered mode
48  *
49  * The stream2 appender can be configured by passing it a file pointer
50  * to use.  In this case you manage the file pointer yourself--open,
51  * option setting, closing.  If you set the file pointer log4c will
52  * not close the file on exiting--you must do this:
53  *
54  * @code
55  * log4c_appender_t* myappender;
56  * FILE * fp = fopen("myfile.log", "w");
57  *
58  * myappender = log4c_appender_get("myappender");
59  * log4c_appender_set_type(myappender, log4c_appender_type_get("stream2"));
60  * log4c_stream2_set_fp(stream2_appender,myfp);
61  *
62  * @endcode
63  *
64  * The default file pointer can be configured to use unbuffered mode.
65  * Buffered mode is typically 25%-50% faster than unbuffered mode but
66  * unbuffered mode is useful if your preference is for a more synchronized
67  * log file:
68  *
69  * @code log4c_appender_t* myappender;
70  *
71  * myappender = log4c_appender_get("/var/logs/mylog.log");
72  * log4c_appender_set_type(myappender,log4c_appender_type_get("stream2"));
73  * log4c_stream2_set_flags(myappender, LOG4C_STREAM2_UNBUFFERED);
74  *
75  * @endcode
76  *
77  **/
78 
79 #include <log4c/defs.h>
80 #include <log4c/appender.h>
81 
82 __LOG4C_BEGIN_DECLS
83 
84 /**
85  * Stream2 appender type definition.
86  *
87  * This should be used as a parameter to the log4c_appender_set_type()
88  * routine to set the type of the appender.
89  *
90  **/
91 LOG4C_API const log4c_appender_type_t log4c_appender_type_stream2;
92 
93 /**
94  * Set the file pointer for this appender.
95  * @param this a pointer to the appender
96  * @param fp the file pointer this appender will use.  The caller is
97  * responsible for managing the file pointer (open, option setting, closing).
98  */
99 LOG4C_API void log4c_stream2_set_fp(log4c_appender_t* a_this, FILE *fp);
100 
101 /**
102  * Get the file pointer for this appender.
103  * @param this a pointer to the appender
104  * @return the file pointer for this appender.  If there's a problem
105  * returns NULL.
106  *
107  */
108 LOG4C_API FILE * log4c_stream2_get_fp(log4c_appender_t* a_this);
109 
110 
111 /**
112  * Set the flags for this appender.
113  * @param this a pointer to the appender
114  * @param flags ar teh flags to set. These will overwrite the existing flags.
115  * Currently supported flags:  LOG4C_STREAM2_UNBUFFERED
116  *
117  */
118 LOG4C_API void log4c_stream2_set_flags(log4c_appender_t* a_this, int flags);
119 #define LOG4C_STREAM2_UNBUFFERED 0x01
120 
121 /**
122  * Get the flags for this appender.
123  * @param this a pointer to the appender
124  * @return the flags for this appender. returns -1 if there was a problem.
125  */
126 LOG4C_API int log4c_stream2_get_flags(log4c_appender_t* a_this);
127 
128 __LOG4C_END_DECLS
129 
130 #endif
131