LCOV - code coverage report
Current view: top level - extensions/source/logging - plaintextformatter.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 15 59 25.4 %
Date: 2014-11-03 Functions: 7 13 53.8 %
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             : 
      52             :     //= PlainTextFormatter - declaration
      53             : 
      54             :     typedef ::cppu::WeakImplHelper2 <   XLogFormatter
      55             :                                     ,   XServiceInfo
      56             :                                     >   PlainTextFormatter_Base;
      57             :     class PlainTextFormatter : public PlainTextFormatter_Base
      58             :     {
      59             :     protected:
      60             :         PlainTextFormatter();
      61             :         virtual ~PlainTextFormatter();
      62             : 
      63             :         // XLogFormatter
      64             :         virtual OUString SAL_CALL getHead(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      65             :         virtual OUString SAL_CALL format( const LogRecord& Record ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      66             :         virtual OUString SAL_CALL getTail(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      67             : 
      68             :         // XServiceInfo
      69             :         virtual OUString SAL_CALL getImplementationName() throw(RuntimeException, std::exception) SAL_OVERRIDE;
      70             :         virtual sal_Bool SAL_CALL supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      71             :         virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException, std::exception) SAL_OVERRIDE;
      72             : 
      73             :     public:
      74             :         // XServiceInfo - static version
      75             :         static OUString SAL_CALL getImplementationName_static();
      76             :         static Sequence< OUString > SAL_CALL getSupportedServiceNames_static();
      77             :         static Reference< XInterface > Create( const Reference< XComponentContext >& _rxContext );
      78             :     };
      79             : 
      80             : 
      81             :     //= PlainTextFormatter - implementation
      82             : 
      83             : 
      84          34 :     PlainTextFormatter::PlainTextFormatter()
      85             :     {
      86          34 :     }
      87             : 
      88             : 
      89          36 :     PlainTextFormatter::~PlainTextFormatter()
      90             :     {
      91          36 :     }
      92             : 
      93             : 
      94           0 :     OUString SAL_CALL PlainTextFormatter::getHead(  ) throw (RuntimeException, std::exception)
      95             :     {
      96           0 :         OUStringBuffer aHeader;
      97           0 :         aHeader.appendAscii( "  event no" );                 // column 1: the event number
      98           0 :         aHeader.appendAscii( " " );
      99           0 :         aHeader.appendAscii( "thread  " );                   // column 2: the thread ID
     100           0 :         aHeader.appendAscii( " " );
     101           0 :         aHeader.appendAscii( "date      " );                 // column 3: date
     102           0 :         aHeader.appendAscii( " " );
     103           0 :         aHeader.appendAscii( "time       " );         // column 4: time
     104           0 :         aHeader.appendAscii( " " );
     105           0 :         aHeader.appendAscii( "(class/method:) message" );    // column 5: class/method/message
     106           0 :         aHeader.appendAscii( "\n" );
     107           0 :         return aHeader.makeStringAndClear();
     108             :     }
     109             : 
     110             : 
     111           0 :     OUString SAL_CALL PlainTextFormatter::format( const LogRecord& _rRecord ) throw (RuntimeException, std::exception)
     112             :     {
     113             :         char buffer[ 30 ];
     114           0 :         const int buffer_size = sizeof( buffer );
     115           0 :         int used = snprintf( buffer, buffer_size, "%10i", (int)_rRecord.SequenceNumber );
     116           0 :         if ( used >= buffer_size || used < 0 )
     117           0 :             buffer[ buffer_size - 1 ] = 0;
     118             : 
     119           0 :         OUStringBuffer aLogEntry;
     120           0 :         aLogEntry.appendAscii( buffer );
     121           0 :         aLogEntry.appendAscii( " " );
     122             : 
     123           0 :         OString sThreadID( OUStringToOString( _rRecord.ThreadID, osl_getThreadTextEncoding() ) );
     124           0 :         snprintf( buffer, buffer_size, "%8s", sThreadID.getStr() );
     125           0 :         aLogEntry.appendAscii( buffer );
     126           0 :         aLogEntry.appendAscii( " " );
     127             : 
     128             :         snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%09i",
     129             :             (int)_rRecord.LogTime.Year, (int)_rRecord.LogTime.Month, (int)_rRecord.LogTime.Day,
     130           0 :             (int)_rRecord.LogTime.Hours, (int)_rRecord.LogTime.Minutes, (int)_rRecord.LogTime.Seconds, (int)_rRecord.LogTime.NanoSeconds );
     131           0 :         aLogEntry.appendAscii( buffer );
     132           0 :         aLogEntry.appendAscii( " " );
     133             : 
     134           0 :         if ( !(_rRecord.SourceClassName.isEmpty() || _rRecord.SourceMethodName.isEmpty()) )
     135             :         {
     136           0 :             aLogEntry.append( _rRecord.SourceClassName );
     137           0 :             aLogEntry.appendAscii( "::" );
     138           0 :             aLogEntry.append( _rRecord.SourceMethodName );
     139           0 :             aLogEntry.appendAscii( ": " );
     140             :         }
     141             : 
     142           0 :         aLogEntry.append( _rRecord.Message );
     143           0 :         aLogEntry.appendAscii( "\n" );
     144             : 
     145           0 :         return aLogEntry.makeStringAndClear();
     146             :     }
     147             : 
     148             : 
     149           0 :     OUString SAL_CALL PlainTextFormatter::getTail(  ) throw (RuntimeException, std::exception)
     150             :     {
     151             :         // no tail
     152           0 :         return OUString();
     153             :     }
     154             : 
     155           0 :     sal_Bool SAL_CALL PlainTextFormatter::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
     156             :     {
     157           0 :         return cppu::supportsService(this, _rServiceName);
     158             :     }
     159             : 
     160             : 
     161           0 :     OUString SAL_CALL PlainTextFormatter::getImplementationName() throw(RuntimeException, std::exception)
     162             :     {
     163           0 :         return getImplementationName_static();
     164             :     }
     165             : 
     166             : 
     167           0 :     Sequence< OUString > SAL_CALL PlainTextFormatter::getSupportedServiceNames() throw(RuntimeException, std::exception)
     168             :     {
     169           0 :         return getSupportedServiceNames_static();
     170             :     }
     171             : 
     172             : 
     173          14 :     OUString SAL_CALL PlainTextFormatter::getImplementationName_static()
     174             :     {
     175          14 :         return OUString( "com.sun.star.comp.extensions.PlainTextFormatter" );
     176             :     }
     177             : 
     178             : 
     179          14 :     Sequence< OUString > SAL_CALL PlainTextFormatter::getSupportedServiceNames_static()
     180             :     {
     181          14 :         Sequence< OUString > aServiceNames(1);
     182          14 :         aServiceNames[0] = "com.sun.star.logging.PlainTextFormatter";
     183          14 :         return aServiceNames;
     184             :     }
     185             : 
     186             : 
     187          34 :     Reference< XInterface > PlainTextFormatter::Create( const Reference< XComponentContext >& )
     188             :     {
     189          34 :         return *( new PlainTextFormatter );
     190             :     }
     191             : 
     192             : 
     193          44 :     void createRegistryInfo_PlainTextFormatter()
     194             :     {
     195          44 :         static OAutoRegistration< PlainTextFormatter > aAutoRegistration;
     196          44 :     }
     197             : 
     198             : 
     199             : } // namespace logging
     200             : 
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10