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