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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 
27 #ifdef HSQLDB_DBG
28 #include "accesslog.hxx"
29 #include "hsqldb/HStorageMap.hxx"
30 
31 #include <osl/thread.h>
32 
33 namespace connectivity { namespace hsqldb
34 {
35     DECLARE_STL_USTRINGACCESS_MAP(FILE *,TDebugStreamMap);
getStreams()36     TDebugStreamMap& getStreams()
37     {
38         static TDebugStreamMap streams;
39         return streams;
40     }
41 
42     //---------------------------------------------------------------------
LogFile(JNIEnv * env,jstring streamName,const sal_Char * _pAsciiSuffix)43     LogFile::LogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix )
44     {
45         m_sFileName = StorageContainer::jstring2ustring(env,streamName);
46         m_sFileName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("."));
47         m_sFileName += ::rtl::OUString::createFromAscii( _pAsciiSuffix );
48     }
49 
50     //---------------------------------------------------------------------
getLogFile()51     FILE*& LogFile::getLogFile()
52     {
53         FILE*& pLogFile = getStreams()[m_sFileName];
54         if ( !pLogFile )
55         {
56             ::rtl::OString sByteLogName = ::rtl::OUStringToOString(m_sFileName,osl_getThreadTextEncoding());
57             pLogFile = fopen( sByteLogName.getStr(), "a+" );
58         }
59         return pLogFile;
60     }
61 
62     //---------------------------------------------------------------------
writeString(const sal_Char * _pString,bool _bEndLine)63     void LogFile::writeString( const sal_Char* _pString, bool _bEndLine )
64     {
65         FILE* pLogFile = getLogFile();
66 		fwrite( _pString, sizeof( *_pString ), strlen( _pString ), pLogFile );
67         if ( _bEndLine )
68             fwrite( "\n", sizeof( *_pString ), strlen( "\n" ), pLogFile );
69         fflush( pLogFile );
70     }
71 
72     //---------------------------------------------------------------------
close()73     void LogFile::close()
74     {
75         fclose( getLogFile() );
76         getLogFile() = NULL;
77     }
78 } }
79 #endif
80