LCOV - code coverage report
Current view: top level - extensions/source/logging - plaintextformatter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 19 59 32.2 %
Date: 2015-06-13 12:38:46 Functions: 9 13 69.2 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : 
      21             : #include "log_module.hxx"
      22             : #include "log_services.hxx"
      23             : 
      24             : #include <stdio.h>
      25             : 
      26             : #include <com/sun/star/logging/XLogFormatter.hpp>
      27             : #include <com/sun/star/uno/XComponentContext.hpp>
      28             : #include <com/sun/star/lang/XServiceInfo.hpp>
      29             : 
      30             : #include <cppuhelper/implbase2.hxx>
      31             : #include <cppuhelper/supportsservice.hxx>
      32             : 
      33             : #include <rtl/ustrbuf.hxx>
      34             : 
      35             : #include <osl/thread.h>
      36             : 
      37             : 
      38             : namespace logging
      39             : {
      40             : 
      41             : 
      42             :     using ::com::sun::star::logging::XLogFormatter;
      43             :     using ::com::sun::star::uno::XComponentContext;
      44             :     using ::com::sun::star::uno::Reference;
      45             :     using ::com::sun::star::uno::Sequence;
      46             :     using ::com::sun::star::lang::XServiceInfo;
      47             :     using ::com::sun::star::uno::RuntimeException;
      48             :     using ::com::sun::star::logging::LogRecord;
      49             :     using ::com::sun::star::uno::XInterface;
      50             : 
      51             :     typedef ::cppu::WeakImplHelper2 <   XLogFormatter
      52             :                                     ,   XServiceInfo
      53             :                                     >   PlainTextFormatter_Base;
      54             :     class PlainTextFormatter : public PlainTextFormatter_Base
      55             :     {
      56             :     protected:
      57             :         PlainTextFormatter();
      58             :         virtual ~PlainTextFormatter();
      59             : 
      60             :         // XLogFormatter
      61             :         virtual OUString SAL_CALL getHead(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      62             :         virtual OUString SAL_CALL format( const LogRecord& Record ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      63             :         virtual OUString SAL_CALL getTail(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      64             : 
      65             :         // XServiceInfo
      66             :         virtual OUString SAL_CALL getImplementationName() throw(RuntimeException, std::exception) SAL_OVERRIDE;
      67             :         virtual sal_Bool SAL_CALL supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      68             :         virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException, std::exception) SAL_OVERRIDE;
      69             : 
      70             :     public:
      71             :         // XServiceInfo - static version
      72             :         static OUString SAL_CALL getImplementationName_static();
      73             :         static Sequence< OUString > SAL_CALL getSupportedServiceNames_static();
      74             :         static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
      75             :     };
      76             : 
      77          33 :     PlainTextFormatter::PlainTextFormatter()
      78             :     {
      79          33 :     }
      80             : 
      81             : 
      82          36 :     PlainTextFormatter::~PlainTextFormatter()
      83             :     {
      84          36 :     }
      85             : 
      86             : 
      87           0 :     OUString SAL_CALL PlainTextFormatter::getHead(  ) throw (RuntimeException, std::exception)
      88             :     {
      89           0 :         OUStringBuffer aHeader;
      90           0 :         aHeader.appendAscii( "  event no" );                 // column 1: the event number
      91           0 :         aHeader.appendAscii( " " );
      92           0 :         aHeader.appendAscii( "thread  " );                   // column 2: the thread ID
      93           0 :         aHeader.appendAscii( " " );
      94           0 :         aHeader.appendAscii( "date      " );                 // column 3: date
      95           0 :         aHeader.appendAscii( " " );
      96           0 :         aHeader.appendAscii( "time       " );         // column 4: time
      97           0 :         aHeader.appendAscii( " " );
      98           0 :         aHeader.appendAscii( "(class/method:) message" );    // column 5: class/method/message
      99           0 :         aHeader.appendAscii( "\n" );
     100           0 :         return aHeader.makeStringAndClear();
     101             :     }
     102             : 
     103             : 
     104           0 :     OUString SAL_CALL PlainTextFormatter::format( const LogRecord& _rRecord ) throw (RuntimeException, std::exception)
     105             :     {
     106             :         char buffer[ 30 ];
     107           0 :         const int buffer_size = sizeof( buffer );
     108           0 :         int used = snprintf( buffer, buffer_size, "%10i", (int)_rRecord.SequenceNumber );
     109           0 :         if ( used >= buffer_size || used < 0 )
     110           0 :             buffer[ buffer_size - 1 ] = 0;
     111             : 
     112           0 :         OUStringBuffer aLogEntry;
     113           0 :         aLogEntry.appendAscii( buffer );
     114           0 :         aLogEntry.appendAscii( " " );
     115             : 
     116           0 :         OString sThreadID( OUStringToOString( _rRecord.ThreadID, osl_getThreadTextEncoding() ) );
     117           0 :         snprintf( buffer, buffer_size, "%8s", sThreadID.getStr() );
     118           0 :         aLogEntry.appendAscii( buffer );
     119           0 :         aLogEntry.appendAscii( " " );
     120             : 
     121             :         snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%09i",
     122             :             (int)_rRecord.LogTime.Year, (int)_rRecord.LogTime.Month, (int)_rRecord.LogTime.Day,
     123           0 :             (int)_rRecord.LogTime.Hours, (int)_rRecord.LogTime.Minutes, (int)_rRecord.LogTime.Seconds, (int)_rRecord.LogTime.NanoSeconds );
     124           0 :         aLogEntry.appendAscii( buffer );
     125           0 :         aLogEntry.appendAscii( " " );
     126             : 
     127           0 :         if ( !(_rRecord.SourceClassName.isEmpty() || _rRecord.SourceMethodName.isEmpty()) )
     128             :         {
     129           0 :             aLogEntry.append( _rRecord.SourceClassName );
     130           0 :             aLogEntry.appendAscii( "::" );
     131           0 :             aLogEntry.append( _rRecord.SourceMethodName );
     132           0 :             aLogEntry.appendAscii( ": " );
     133             :         }
     134             : 
     135           0 :         aLogEntry.append( _rRecord.Message );
     136           0 :         aLogEntry.appendAscii( "\n" );
     137             : 
     138           0 :         return aLogEntry.makeStringAndClear();
     139             :     }
     140             : 
     141             : 
     142           0 :     OUString SAL_CALL PlainTextFormatter::getTail(  ) throw (RuntimeException, std::exception)
     143             :     {
     144             :         // no tail
     145           0 :         return OUString();
     146             :     }
     147             : 
     148           0 :     sal_Bool SAL_CALL PlainTextFormatter::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
     149             :     {
     150           0 :         return cppu::supportsService(this, _rServiceName);
     151             :     }
     152             : 
     153             : 
     154           1 :     OUString SAL_CALL PlainTextFormatter::getImplementationName() throw(RuntimeException, std::exception)
     155             :     {
     156           1 :         return getImplementationName_static();
     157             :     }
     158             : 
     159             : 
     160           1 :     Sequence< OUString > SAL_CALL PlainTextFormatter::getSupportedServiceNames() throw(RuntimeException, std::exception)
     161             :     {
     162           1 :         return getSupportedServiceNames_static();
     163             :     }
     164             : 
     165             : 
     166          14 :     OUString SAL_CALL PlainTextFormatter::getImplementationName_static()
     167             :     {
     168          14 :         return OUString( "com.sun.star.comp.extensions.PlainTextFormatter" );
     169             :     }
     170             : 
     171             : 
     172          14 :     Sequence< OUString > SAL_CALL PlainTextFormatter::getSupportedServiceNames_static()
     173             :     {
     174          14 :         Sequence< OUString > aServiceNames(1);
     175          14 :         aServiceNames[0] = "com.sun.star.logging.PlainTextFormatter";
     176          14 :         return aServiceNames;
     177             :     }
     178             : 
     179             : 
     180          33 :     Reference< XInterface > PlainTextFormatter::Create( const Reference< XComponentContext >& )
     181             :     {
     182          33 :         return *( new PlainTextFormatter );
     183             :     }
     184             : 
     185             : 
     186          40 :     void createRegistryInfo_PlainTextFormatter()
     187             :     {
     188          40 :         static OAutoRegistration< PlainTextFormatter > aAutoRegistration;
     189          40 :     }
     190             : 
     191             : 
     192             : } // namespace logging
     193             : 
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11