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 : #include "logrecord.hxx"
21 :
22 : #include <osl/time.h>
23 : #include <osl/thread.h>
24 : #include <osl/diagnose.h>
25 :
26 : //........................................................................
27 : namespace logging
28 : {
29 : //........................................................................
30 :
31 : using ::com::sun::star::logging::LogRecord;
32 : using ::com::sun::star::util::DateTime;
33 :
34 : //====================================================================
35 : //= helper
36 : //====================================================================
37 : //--------------------------------------------------------------------
38 : namespace
39 : {
40 : /** returns a string representation of the current thread
41 :
42 : @todo
43 : We need a way to retrieve the current UNO thread ID as string,
44 : which is issue #i77342#
45 : */
46 0 : OUString getCurrentThreadID()
47 : {
48 0 : oslThreadIdentifier nThreadID( osl_getThreadIdentifier( NULL ) );
49 0 : return OUString::valueOf( (sal_Int64)nThreadID );
50 : }
51 : }
52 :
53 : //--------------------------------------------------------------------
54 0 : LogRecord createLogRecord( const OUString& _rLoggerName, const OUString& _rClassName,
55 : const OUString& _rMethodName, const OUString& _rMessage,
56 : sal_Int32 _nLogLevel, oslInterlockedCount _nEventNumber )
57 : {
58 : TimeValue aTimeValue;
59 0 : osl_getSystemTime( &aTimeValue );
60 :
61 : oslDateTime aDateTime;
62 0 : OSL_VERIFY( osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime ) );
63 :
64 0 : DateTime aTimeStamp;
65 0 : aTimeStamp.Year = aDateTime.Year;
66 0 : aTimeStamp.Month = aDateTime.Month;
67 0 : aTimeStamp.Day = aDateTime.Day;
68 0 : aTimeStamp.Hours = aDateTime.Hours;
69 0 : aTimeStamp.Minutes = aDateTime.Minutes;
70 0 : aTimeStamp.Seconds = aDateTime.Seconds;
71 0 : aTimeStamp.NanoSeconds = aDateTime.NanoSeconds;
72 :
73 : return LogRecord(
74 : _rLoggerName,
75 : _rClassName,
76 : _rMethodName,
77 : _rMessage,
78 : aTimeStamp,
79 : _nEventNumber,
80 : getCurrentThreadID(),
81 : _nLogLevel
82 0 : );
83 : }
84 :
85 : //........................................................................
86 : } // namespace logging
87 : //........................................................................
88 :
89 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|