1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_MACROS_DEBUG_LOGMECHANISM_HXX_
25 #define __FRAMEWORK_MACROS_DEBUG_LOGMECHANISM_HXX_
26 
27 //*****************************************************************************************************************
28 //	generic macros for logging
29 //*****************************************************************************************************************
30 
31 #ifdef	ENABLE_LOGMECHANISM
32 
33 	//_____________________________________________________________________________________________________________
34 	//	includes
35 	//_____________________________________________________________________________________________________________
36 
37 	#ifndef _RTL_STRING_HXX_
38 	#include <rtl/string.hxx>
39 	#endif
40 
41 	#include <stdio.h>
42 
43 	/*_____________________________________________________________________________________________________________
44 		WRITE_LOGFILE( SFILENAME, STEXT )
45 
46 		Log any information in file. We append any information at file and don't clear it anymore.
47 		( Use new scope in macro to declare pFile more then on time in same "parentscope"!
48 	  	  Don't control pFile before access! What will you doing if its not valid? Log an error ...
49   	  	  An error and an error is an error ... )
50 
51         Attention:  You must use "%s" and STEXT as parameter ... because otherwise encoded strings (they include e.g. %...)
52                     are handled wrong.
53 	_____________________________________________________________________________________________________________*/
54 
writeToLogFile(const char * SFILENAME,const char * STEXT)55 	inline void writeToLogFile( const char* SFILENAME, const char* STEXT )
56 				{																								\
57 					::rtl::OString	_swriteLogfileFileName	( SFILENAME	);										\
58 					::rtl::OString	_swriteLogfileText		( STEXT		);										\
59 					FILE* pFile = fopen( _swriteLogfileFileName.getStr(), "a" );								\
60                     fprintf( pFile, "%s", _swriteLogfileText.getStr() );                                        \
61                     fclose ( pFile                                    );                                        \
62 				}
63 
writeToLogFile(const char * pFILENAME,const rtl::OString & rTEXT)64 	inline void writeToLogFile( const char* pFILENAME, const rtl::OString& rTEXT ) { writeToLogFile( pFILENAME, rTEXT.getStr()); }
65 
66 	#define WRITE_LOGFILE( SFILENAME, STEXT ) { writeToLogFile( (SFILENAME), (STEXT) ); }
67 
68 	/*_____________________________________________________________________________________________________________
69 		LOGTYPE
70 
71 		For other debug macros we need information about the output mode. If user forget to set this information we
72 		do it for him. Valid values are:	LOGTYPE_FILECONTINUE
73 											LOGTYPE_FILEEXIT
74 											LOGTYPE_MESSAGEBOX
75 		The normal case is LOGTYPE_MESSAGEBOX to show assertions in normal manner!
76 	_____________________________________________________________________________________________________________*/
77 
78 	#define	LOGTYPE_MESSAGEBOX		1
79 	#define	LOGTYPE_FILECONTINUE	2
80 	#define	LOGTYPE_FILEEXIT		3
81 
82 	#ifndef	LOGTYPE
83 		#define	LOGTYPE																							\
84 					LOGTYPE_MESSAGEBOX
85 	#endif
86 
87 #else	// #ifdef ENABLE_LOGMECHANISM
88 
89 	/*_____________________________________________________________________________________________________________
90 		If right testmode is'nt set - implements these macro empty!
91 	_____________________________________________________________________________________________________________*/
92 
93 	#define	WRITE_LOGFILE( SFILENAME, STEXT )
94 	#undef	LOGTYPE
95 
96 #endif	// #ifdef ENABLE_LOGMECHANISM
97 
98 //*****************************************************************************************************************
99 //	end of file
100 //*****************************************************************************************************************
101 
102 #endif	// #ifndef __FRAMEWORK_MACROS_DEBUG_LOGMECHANISM_HXX_
103