LCOV - code coverage report
Current view: top level - extensions/source/logging - plaintextformatter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 65 24.6 %
Date: 2012-08-25 Functions: 7 13 53.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 90 11.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "log_module.hxx"
      31                 :            : 
      32                 :            : #include <stdio.h>
      33                 :            : 
      34                 :            : #include <com/sun/star/logging/XLogFormatter.hpp>
      35                 :            : #include <com/sun/star/uno/XComponentContext.hpp>
      36                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      37                 :            : 
      38                 :            : #include <comphelper/componentcontext.hxx>
      39                 :            : 
      40                 :            : #include <cppuhelper/implbase2.hxx>
      41                 :            : 
      42                 :            : #include <rtl/ustrbuf.hxx>
      43                 :            : 
      44                 :            : #include <osl/thread.h>
      45                 :            : 
      46                 :            : //........................................................................
      47                 :            : namespace logging
      48                 :            : {
      49                 :            : //........................................................................
      50                 :            : 
      51                 :            :     /** === begin UNO using === **/
      52                 :            :     using ::com::sun::star::logging::XLogFormatter;
      53                 :            :     using ::com::sun::star::uno::XComponentContext;
      54                 :            :     using ::com::sun::star::uno::Reference;
      55                 :            :     using ::com::sun::star::uno::Sequence;
      56                 :            :     using ::com::sun::star::lang::XServiceInfo;
      57                 :            :     using ::com::sun::star::uno::RuntimeException;
      58                 :            :     using ::com::sun::star::logging::LogRecord;
      59                 :            :     using ::com::sun::star::uno::XInterface;
      60                 :            :     /** === end UNO using === **/
      61                 :            : 
      62                 :            :     //====================================================================
      63                 :            :     //= PlainTextFormatter - declaration
      64                 :            :     //====================================================================
      65                 :            :     typedef ::cppu::WeakImplHelper2 <   XLogFormatter
      66                 :            :                                     ,   XServiceInfo
      67                 :            :                                     >   PlainTextFormatter_Base;
      68                 :            :     class PlainTextFormatter : public PlainTextFormatter_Base
      69                 :            :     {
      70                 :            :     private:
      71                 :            :         ::comphelper::ComponentContext  m_aContext;
      72                 :            : 
      73                 :            :     protected:
      74                 :            :         PlainTextFormatter( const Reference< XComponentContext >& _rxContext );
      75                 :            :         virtual ~PlainTextFormatter();
      76                 :            : 
      77                 :            :         // XLogFormatter
      78                 :            :         virtual ::rtl::OUString SAL_CALL getHead(  ) throw (RuntimeException);
      79                 :            :         virtual ::rtl::OUString SAL_CALL format( const LogRecord& Record ) throw (RuntimeException);
      80                 :            :         virtual ::rtl::OUString SAL_CALL getTail(  ) throw (RuntimeException);
      81                 :            : 
      82                 :            :         // XServiceInfo
      83                 :            :         virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
      84                 :            :         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException);
      85                 :            :         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
      86                 :            : 
      87                 :            :     public:
      88                 :            :         // XServiceInfo - static version
      89                 :            :         static ::rtl::OUString SAL_CALL getImplementationName_static();
      90                 :            :         static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
      91                 :            :         static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
      92                 :            :     };
      93                 :            : 
      94                 :            :     //====================================================================
      95                 :            :     //= PlainTextFormatter - implementation
      96                 :            :     //====================================================================
      97                 :            :     //--------------------------------------------------------------------
      98                 :         18 :     PlainTextFormatter::PlainTextFormatter( const Reference< XComponentContext >& _rxContext )
      99         [ +  - ]:         18 :         :m_aContext( _rxContext )
     100                 :            :     {
     101                 :         18 :     }
     102                 :            : 
     103                 :            :     //--------------------------------------------------------------------
     104         [ +  - ]:          9 :     PlainTextFormatter::~PlainTextFormatter()
     105                 :            :     {
     106         [ -  + ]:         18 :     }
     107                 :            : 
     108                 :            :     //--------------------------------------------------------------------
     109                 :          0 :     ::rtl::OUString SAL_CALL PlainTextFormatter::getHead(  ) throw (RuntimeException)
     110                 :            :     {
     111                 :          0 :         ::rtl::OUStringBuffer aHeader;
     112         [ #  # ]:          0 :         aHeader.appendAscii( "  event no" );                 // column 1: the event number
     113         [ #  # ]:          0 :         aHeader.appendAscii( " " );
     114         [ #  # ]:          0 :         aHeader.appendAscii( "thread  " );                   // column 2: the thread ID
     115         [ #  # ]:          0 :         aHeader.appendAscii( " " );
     116         [ #  # ]:          0 :         aHeader.appendAscii( "date      " );                 // column 3: date
     117         [ #  # ]:          0 :         aHeader.appendAscii( " " );
     118         [ #  # ]:          0 :         aHeader.appendAscii( "time       " );         // column 4: time
     119         [ #  # ]:          0 :         aHeader.appendAscii( " " );
     120         [ #  # ]:          0 :         aHeader.appendAscii( "(class/method:) message" );    // column 5: class/method/message
     121         [ #  # ]:          0 :         aHeader.appendAscii( "\n" );
     122         [ #  # ]:          0 :         return aHeader.makeStringAndClear();
     123                 :            :     }
     124                 :            : 
     125                 :            :     //--------------------------------------------------------------------
     126                 :          0 :     ::rtl::OUString SAL_CALL PlainTextFormatter::format( const LogRecord& _rRecord ) throw (RuntimeException)
     127                 :            :     {
     128                 :            :         char buffer[ 30 ];
     129                 :          0 :         const int buffer_size = sizeof( buffer );
     130                 :          0 :         int used = snprintf( buffer, buffer_size, "%10i", (int)_rRecord.SequenceNumber );
     131 [ #  # ][ #  # ]:          0 :         if ( used >= buffer_size || used < 0 )
     132                 :          0 :             buffer[ buffer_size - 1 ] = 0;
     133                 :            : 
     134                 :          0 :         ::rtl::OUStringBuffer aLogEntry;
     135         [ #  # ]:          0 :         aLogEntry.appendAscii( buffer );
     136         [ #  # ]:          0 :         aLogEntry.appendAscii( " " );
     137                 :            : 
     138 [ #  # ][ #  # ]:          0 :         ::rtl::OString sThreadID( ::rtl::OUStringToOString( _rRecord.ThreadID, osl_getThreadTextEncoding() ) );
     139                 :          0 :         snprintf( buffer, buffer_size, "%8s", sThreadID.getStr() );
     140         [ #  # ]:          0 :         aLogEntry.appendAscii( buffer );
     141         [ #  # ]:          0 :         aLogEntry.appendAscii( " " );
     142                 :            : 
     143                 :            :         snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%02i",
     144                 :            :             (int)_rRecord.LogTime.Year, (int)_rRecord.LogTime.Month, (int)_rRecord.LogTime.Day,
     145                 :          0 :             (int)_rRecord.LogTime.Hours, (int)_rRecord.LogTime.Minutes, (int)_rRecord.LogTime.Seconds, (int)_rRecord.LogTime.HundredthSeconds );
     146         [ #  # ]:          0 :         aLogEntry.appendAscii( buffer );
     147         [ #  # ]:          0 :         aLogEntry.appendAscii( " " );
     148                 :            : 
     149 [ #  # ][ #  # ]:          0 :         if ( !(_rRecord.SourceClassName.isEmpty() || _rRecord.SourceMethodName.isEmpty()) )
                 [ #  # ]
     150                 :            :         {
     151         [ #  # ]:          0 :             aLogEntry.append( _rRecord.SourceClassName );
     152         [ #  # ]:          0 :             aLogEntry.appendAscii( "::" );
     153         [ #  # ]:          0 :             aLogEntry.append( _rRecord.SourceMethodName );
     154         [ #  # ]:          0 :             aLogEntry.appendAscii( ": " );
     155                 :            :         }
     156                 :            : 
     157         [ #  # ]:          0 :         aLogEntry.append( _rRecord.Message );
     158         [ #  # ]:          0 :         aLogEntry.appendAscii( "\n" );
     159                 :            : 
     160         [ #  # ]:          0 :         return aLogEntry.makeStringAndClear();
     161                 :            :     }
     162                 :            : 
     163                 :            :     //--------------------------------------------------------------------
     164                 :          0 :     ::rtl::OUString SAL_CALL PlainTextFormatter::getTail(  ) throw (RuntimeException)
     165                 :            :     {
     166                 :            :         // no tail
     167                 :          0 :         return ::rtl::OUString();
     168                 :            :     }
     169                 :            : 
     170                 :            :     //--------------------------------------------------------------------
     171                 :          0 :     ::sal_Bool SAL_CALL PlainTextFormatter::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
     172                 :            :     {
     173         [ #  # ]:          0 :         const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() );
     174         [ #  # ]:          0 :         for (   const ::rtl::OUString* pServiceNames = aServiceNames.getConstArray();
     175                 :          0 :                 pServiceNames != aServiceNames.getConstArray() + aServiceNames.getLength();
     176                 :            :                 ++pServiceNames
     177                 :            :             )
     178         [ #  # ]:          0 :             if ( _rServiceName == *pServiceNames )
     179                 :          0 :                 return sal_True;
     180         [ #  # ]:          0 :         return sal_False;
     181                 :            :     }
     182                 :            : 
     183                 :            :     //--------------------------------------------------------------------
     184                 :          0 :     ::rtl::OUString SAL_CALL PlainTextFormatter::getImplementationName() throw(RuntimeException)
     185                 :            :     {
     186                 :          0 :         return getImplementationName_static();
     187                 :            :     }
     188                 :            : 
     189                 :            :     //--------------------------------------------------------------------
     190                 :          0 :     Sequence< ::rtl::OUString > SAL_CALL PlainTextFormatter::getSupportedServiceNames() throw(RuntimeException)
     191                 :            :     {
     192                 :          0 :         return getSupportedServiceNames_static();
     193                 :            :     }
     194                 :            : 
     195                 :            :     //--------------------------------------------------------------------
     196                 :          9 :     ::rtl::OUString SAL_CALL PlainTextFormatter::getImplementationName_static()
     197                 :            :     {
     198                 :          9 :         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.PlainTextFormatter" ) );
     199                 :            :     }
     200                 :            : 
     201                 :            :     //--------------------------------------------------------------------
     202                 :          9 :     Sequence< ::rtl::OUString > SAL_CALL PlainTextFormatter::getSupportedServiceNames_static()
     203                 :            :     {
     204                 :          9 :         Sequence< ::rtl::OUString > aServiceNames(1);
     205 [ +  - ][ +  - ]:          9 :         aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.PlainTextFormatter" ) );
     206                 :          9 :         return aServiceNames;
     207                 :            :     }
     208                 :            : 
     209                 :            :     //--------------------------------------------------------------------
     210                 :         18 :     Reference< XInterface > PlainTextFormatter::Create( const Reference< XComponentContext >& _rxContext )
     211                 :            :     {
     212         [ +  - ]:         18 :         return *( new PlainTextFormatter( _rxContext ) );
     213                 :            :     }
     214                 :            : 
     215                 :            :     //--------------------------------------------------------------------
     216                 :         27 :     void createRegistryInfo_PlainTextFormatter()
     217                 :            :     {
     218 [ +  + ][ +  - ]:         27 :         static OAutoRegistration< PlainTextFormatter > aAutoRegistration;
         [ +  - ][ #  # ]
     219                 :         27 :     }
     220                 :            : 
     221                 :            : //........................................................................
     222                 :            : } // namespace logging
     223                 :            : //........................................................................
     224                 :            : 
     225                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10