xref: /aoo42x/main/sal/inc/rtl/logfile.h (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _RTL_LOGFILE_H_
28 #define _RTL_LOGFILE_H_
29 
30 #include <sal/types.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 
37 /**	This function allows to log arbitrary messages even in a product-environment.
38 
39 	The logfile is created on first access and closed, when the sal-library gets unloaded.
40 	The file is line buffered. A log file is not created if no log messages are
41 	written.
42 
43 	The first time, rtl_logfile_trace is called, it checks for the bootstrap variable
44 	RTL_LOGFILE. If the variable is not empty, it creates a file with the name
45 	$(RTL_LOGFILE)_$(PID).log, where $(PID) is the process id of the running process.
46 
47 	@param pszformat A format string with fprintf-syntax
48 	@param ...       An arbitrary number of arguments for fprintf, matching the
49 	                 format string.
50 */
51 void SAL_CALL rtl_logfile_trace( const sal_Char* pszFormat, ... );
52 
53 /** Like rtl_logfile_trace, but prefixing every log entry with the current time
54     and thread ID.
55 
56 	@param format
57     a format string with fprintf-like syntax
58 
59 	@param ...
60     an arbitrary number of arguments for fprintf, matching the given format
61     string
62 
63     @since UDK 3.2.0
64 */
65 void SAL_CALL rtl_logfile_longTrace(char const * format, ...);
66 
67 /** Return if a log file is written.
68 
69 	@return true if a log file is written
70 
71     @since UDK 3.2.11
72 */
73 sal_Bool SAL_CALL rtl_logfile_hasLogFile( void );
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #ifdef TIMELOG
80 #define RTL_LOGFILE_TRACE( string )  \
81              rtl_logfile_longTrace( "| : %s\n", string )
82 #define RTL_LOGFILE_TRACE1( frmt, arg1 ) \
83              rtl_logfile_longTrace( "| : " ); \
84              rtl_logfile_trace( frmt, arg1 ); \
85              rtl_logfile_trace( "\n" )
86 
87 #define RTL_LOGFILE_TRACE2( frmt, arg1 , arg2 ) \
88              rtl_logfile_longTrace( "| : " ); \
89              rtl_logfile_trace( frmt, arg1 , arg2 ); \
90              rtl_logfile_trace( "\n" )
91 #define RTL_LOGFILE_TRACE3( frmt, arg1 , arg2 , arg3 ) \
92              rtl_logfile_longTrace( "| : " ); \
93              rtl_logfile_trace( frmt, arg1 , arg2 , arg3 ); \
94              rtl_logfile_trace( "\n" )
95 
96 //	Now the macros with project and author arguments.  The strings
97 //	are formatted in a way, so that the log file can be parsed by
98 //	post processing scripts.
99 #define RTL_LOGFILE_TRACE_AUTHOR( project, author, string )  \
100              rtl_logfile_longTrace( "| %s (%s) : %s\n", \
101 								project,\
102 								author,\
103                                 string )
104 #define RTL_LOGFILE_TRACE_AUTHOR1( project, author, frmt, arg1 ) \
105              rtl_logfile_longTrace( "| %s (%s) : ", \
106 								project,\
107 								author );\
108              rtl_logfile_trace( frmt, arg1 ); \
109              rtl_logfile_trace( "\n" )
110 
111 #define RTL_LOGFILE_TRACE_AUTHOR2( project, author, frmt, arg1 , arg2 ) \
112              rtl_logfile_longTrace( "| %s (%s) : ", \
113 								project,\
114 								author ); \
115              rtl_logfile_trace( frmt, arg1 , arg2 ); \
116              rtl_logfile_trace( "\n" )
117 #define RTL_LOGFILE_TRACE_AUTHOR3( project, author, frmt, arg1 , arg2 , arg3 ) \
118              rtl_logfile_longTrace( "| %s (%s) : ", \
119 								project,\
120 								author ); \
121              rtl_logfile_trace( frmt, arg1 , arg2 , arg3 ); \
122              rtl_logfile_trace( "\n" )
123 #else
124 #define RTL_LOGFILE_TRACE( string )  ((void)0)
125 #define RTL_LOGFILE_TRACE1( frmt, arg1 ) ((void)0)
126 #define RTL_LOGFILE_TRACE2( frmt, arg1 , arg2 ) ((void)0)
127 #define RTL_LOGFILE_TRACE3( frmt, arg1 , arg2 , arg3 ) ((void)0)
128 
129 #define RTL_LOGFILE_TRACE_AUTHOR( project, author, string )  ((void)0)
130 #define RTL_LOGFILE_TRACE_AUTHOR1( project, author, frmt, arg1 ) ((void)0)
131 #define RTL_LOGFILE_TRACE_AUTHOR2( project, author, frmt, arg1 , arg2 ) ((void)0)
132 #define RTL_LOGFILE_TRACE_AUTHOR3( project, author, frmt, arg1 , arg2 , arg3 ) ((void)0)
133 #endif // TIMELOG
134 #endif
135