LibreOffice
LibreOffice 4.3 SDK C/C++ API Reference
logfile.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_RTL_LOGFILE_HXX
20 #define INCLUDED_RTL_LOGFILE_HXX
21 
22 #include <rtl/logfile.h>
23 #include <rtl/string.hxx>
24 #include <sal/detail/log.h>
25 
26 namespace rtl
27 {
93  class Logfile
94  {
95  public:
96  inline Logfile( const sal_Char *name );
107  inline Logfile( const sal_Char *project, const sal_Char *author, const sal_Char *name );
108  inline ~Logfile();
109  inline const sal_Char *getName();
110  private:
111  ::rtl::OString m_sName;
112  };
113 
114  inline Logfile::Logfile( const sal_Char *name )
115  : m_sName( name )
116  {
117  rtl_logfile_longTrace( "{ %s\n", name );
118  }
119 
120  inline Logfile::Logfile( const sal_Char *project, const sal_Char *author, const sal_Char *name )
121  : m_sName( project)
122  {
123  m_sName += " (";
124  m_sName += author;
125  m_sName += ") ";
126  m_sName += name;
127  rtl_logfile_longTrace( "{ %s\n", m_sName.pData->buffer );
128  }
129 
131  {
132  rtl_logfile_longTrace( "} %s\n", m_sName.pData->buffer );
133  }
134 
135  inline const sal_Char * Logfile::getName()
136  {
137  return m_sName.getStr();
138  }
139 }
140 
141 #ifdef TIMELOG
142 #define RTL_LOGFILE_CONTEXT( instance, name ) ::rtl::Logfile instance( name )
143 #define RTL_LOGFILE_CONTEXT_AUTHOR( instance, project, author, name ) ::rtl::Logfile instance(project, author, name )
144 #define RTL_LOGFILE_CONTEXT_TRACE( instance, message ) \
145  rtl_logfile_longTrace( "| %s : %s\n", \
146  instance.getName(), \
147  message )
148 #define RTL_LOGFILE_CONTEXT_TRACE1( instance , frmt, arg1 ) \
149  rtl_logfile_longTrace( "| %s : ", \
150  instance.getName() ); \
151  rtl_logfile_trace( frmt , arg1 ); \
152  rtl_logfile_trace( "\n" )
153 #define RTL_LOGFILE_CONTEXT_TRACE2( instance , frmt, arg1 , arg2 ) \
154  rtl_logfile_longTrace( "| %s : ", \
155  instance.getName() ); \
156  rtl_logfile_trace( frmt , arg1 , arg2 ); \
157  rtl_logfile_trace( "\n" )
158 #define RTL_LOGFILE_CONTEXT_TRACE3( instance , frmt, arg1 , arg2 , arg3 ) \
159  rtl_logfile_longTrace( "| %s : ", \
160  instance.getName() ); \
161  rtl_logfile_trace( frmt , arg1 , arg2 , arg3 ); \
162  rtl_logfile_trace( "\n" )
163 
164 #else
165 
166 #define RTL_LOGFILE_FORWARD_VIA_SAL_LOG(area, message) \
167  SAL_DETAIL_INFO_IF_FORMAT(SAL_DETAIL_ENABLE_LOG_INFO, area, "%s", message)
168 
169 #define RTL_LOGFILE_CONTEXT( instance, name ) RTL_LOGFILE_FORWARD_VIA_SAL_LOG("logfile", name)
170 #define RTL_LOGFILE_CONTEXT_AUTHOR( instance, project, author, name ) RTL_LOGFILE_FORWARD_VIA_SAL_LOG(project ".logfile", name)
171 #define RTL_LOGFILE_CONTEXT_TRACE( instance, message ) RTL_LOGFILE_FORWARD_VIA_SAL_LOG("logfile", message)
172 #define RTL_LOGFILE_CONTEXT_TRACE1( instance, frmt, arg1 ) ((void)arg1,(void)0)
173 #define RTL_LOGFILE_CONTEXT_TRACE2( instance, frmt, arg1, arg2 ) ((void)arg1,(void)arg2,(void)0)
174 #define RTL_LOGFILE_CONTEXT_TRACE3( instance, frmt, arg1, arg2 , arg3 ) ((void)arg1,(void)arg2,(void)arg3,(void)0)
175 #endif
176 
177 // Normal RTL_LOGFILE_* entries will not make it into release versions,
178 // TIMELOG is disabled a few versions prior relase build.
179 
180 // We need some logs also in these builds, eg. for making performance regression tests.
181 
182 // POLICY: Don't use RTL_LOGFILE_PRODUCT_* for your personal logging information.
183 // Be aware that these logs make it into the product shipped to customers.
184 // If you have good reasons for doing this, please contact product management.
185 
186 #define RTL_LOGFILE_PRODUCT_TRACE( string ) \
187  rtl_logfile_longTrace( "| : %s\n", string )
188 #define RTL_LOGFILE_PRODUCT_TRACE1( frmt, arg1 ) \
189  rtl_logfile_longTrace( "| : " ); \
190  rtl_logfile_trace( frmt, arg1 ); \
191  rtl_logfile_trace( "\n" )
192 #define RTL_LOGFILE_PRODUCT_CONTEXT( instance, name ) \
193  ::rtl::Logfile instance( name )
194 #define RTL_LOGFILE_PRODUCT_CONTEXT_TRACE1( instance, frmt, arg1 ) \
195  rtl_logfile_longTrace( "| %s : ", \
196  instance.getName() ); \
197  rtl_logfile_trace( frmt, arg1 ); \
198  rtl_logfile_trace( "\n" )
199 #define RTL_LOGFILE_HASLOGFILE() \
200  rtl_logfile_hasLogFile()
201 
202 
203 #endif
204 
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC void rtl_logfile_longTrace(char const *format,...)
Like rtl_logfile_trace, but prefixing every log entry with the current time and thread ID...
The intended use for class Logfile is to write time stamp information for profiling purposes...
Definition: logfile.hxx:93
const sal_Char * getStr() const SAL_THROW(())
Returns a pointer to the characters of this string.
Definition: string.hxx:353
Definition: bootstrap.hxx:24
char sal_Char
A legacy synonym for char.
Definition: types.h:128
~Logfile()
Definition: logfile.hxx:130
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:89
Logfile(const sal_Char *name)
Definition: logfile.hxx:114
const sal_Char * getName()
Definition: logfile.hxx:135