1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10*2a97ec55SAndrew Rist * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*2a97ec55SAndrew Rist * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19*2a97ec55SAndrew Rist * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir #include "logrecord.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir /** === begin UNO includes === **/ 29cdf0e10cSrcweir /** === end UNO includes === **/ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <osl/time.h> 32cdf0e10cSrcweir #include <osl/thread.h> 33cdf0e10cSrcweir #include <osl/diagnose.h> 34cdf0e10cSrcweir 35cdf0e10cSrcweir //........................................................................ 36cdf0e10cSrcweir namespace logging 37cdf0e10cSrcweir { 38cdf0e10cSrcweir //........................................................................ 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** === begin UNO using === **/ 41cdf0e10cSrcweir using ::com::sun::star::logging::LogRecord; 42cdf0e10cSrcweir using ::com::sun::star::util::DateTime; 43cdf0e10cSrcweir /** === end UNO using === **/ 44cdf0e10cSrcweir 45cdf0e10cSrcweir //==================================================================== 46cdf0e10cSrcweir //= helper 47cdf0e10cSrcweir //==================================================================== 48cdf0e10cSrcweir //-------------------------------------------------------------------- 49cdf0e10cSrcweir namespace 50cdf0e10cSrcweir { 51cdf0e10cSrcweir /** returns a string representation of the current thread 52cdf0e10cSrcweir 53cdf0e10cSrcweir @todo 54cdf0e10cSrcweir We need a way to retrieve the current UNO thread ID as string, 55cdf0e10cSrcweir which is issue #i77342# 56cdf0e10cSrcweir */ getCurrentThreadID()57cdf0e10cSrcweir ::rtl::OUString getCurrentThreadID() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir oslThreadIdentifier nThreadID( osl_getThreadIdentifier( NULL ) ); 60cdf0e10cSrcweir return ::rtl::OUString::valueOf( (sal_Int64)nThreadID ); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir //-------------------------------------------------------------------- createLogRecord(const::rtl::OUString & _rLoggerName,const::rtl::OUString & _rClassName,const::rtl::OUString & _rMethodName,const::rtl::OUString & _rMessage,sal_Int32 _nLogLevel,oslInterlockedCount _nEventNumber)65cdf0e10cSrcweir LogRecord createLogRecord( const ::rtl::OUString& _rLoggerName, const ::rtl::OUString& _rClassName, 66cdf0e10cSrcweir const ::rtl::OUString& _rMethodName, const ::rtl::OUString& _rMessage, 67cdf0e10cSrcweir sal_Int32 _nLogLevel, oslInterlockedCount _nEventNumber ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir TimeValue aTimeValue; 70cdf0e10cSrcweir osl_getSystemTime( &aTimeValue ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir oslDateTime aDateTime; 73cdf0e10cSrcweir OSL_VERIFY( osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime ) ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir DateTime aTimeStamp; 76cdf0e10cSrcweir aTimeStamp.Year = aDateTime.Year; 77cdf0e10cSrcweir aTimeStamp.Month = aDateTime.Month; 78cdf0e10cSrcweir aTimeStamp.Day = aDateTime.Day; 79cdf0e10cSrcweir aTimeStamp.Hours = aDateTime.Hours; 80cdf0e10cSrcweir aTimeStamp.Minutes = aDateTime.Minutes; 81cdf0e10cSrcweir aTimeStamp.Seconds = aDateTime.Seconds; 82cdf0e10cSrcweir aTimeStamp.HundredthSeconds = ::sal::static_int_cast< sal_Int16 >( aDateTime.NanoSeconds / 10000000 ); 83cdf0e10cSrcweir 84cdf0e10cSrcweir return LogRecord( 85cdf0e10cSrcweir _rLoggerName, 86cdf0e10cSrcweir _rClassName, 87cdf0e10cSrcweir _rMethodName, 88cdf0e10cSrcweir _rMessage, 89cdf0e10cSrcweir aTimeStamp, 90cdf0e10cSrcweir _nEventNumber, 91cdf0e10cSrcweir getCurrentThreadID(), 92cdf0e10cSrcweir _nLogLevel 93cdf0e10cSrcweir ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir //........................................................................ 97cdf0e10cSrcweir } // namespace logging 98cdf0e10cSrcweir //........................................................................ 99cdf0e10cSrcweir 100