LibreOffice Module extensions (master) 1
logrecord.cxx
Go to the documentation of this file.
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/thread.hxx>
25#include <osl/diagnose.h>
26
27
28namespace logging
29{
30
31
32 using ::com::sun::star::logging::LogRecord;
33 using ::com::sun::star::util::DateTime;
34
35 namespace
36 {
43 OUString getCurrentThreadID()
44 {
45 oslThreadIdentifier nThreadID( osl::Thread::getCurrentIdentifier() );
46 return OUString::number( static_cast<sal_Int64>(nThreadID) );
47 }
48 }
49
50
51 LogRecord createLogRecord( const OUString& _rLoggerName, const OUString& _rClassName,
52 const OUString& _rMethodName, const OUString& _rMessage,
53 sal_Int32 _nLogLevel, oslInterlockedCount _nEventNumber )
54 {
55 TimeValue aTimeValue;
56 osl_getSystemTime( &aTimeValue );
57
58 oslDateTime aDateTime;
59 OSL_VERIFY( osl_getDateTimeFromTimeValue( &aTimeValue, &aDateTime ) );
60
61 DateTime aTimeStamp;
62 aTimeStamp.Year = aDateTime.Year;
63 aTimeStamp.Month = aDateTime.Month;
64 aTimeStamp.Day = aDateTime.Day;
65 aTimeStamp.Hours = aDateTime.Hours;
66 aTimeStamp.Minutes = aDateTime.Minutes;
67 aTimeStamp.Seconds = aDateTime.Seconds;
68 aTimeStamp.NanoSeconds = aDateTime.NanoSeconds;
69
70 return LogRecord(
71 _rLoggerName,
72 _rClassName,
73 _rMethodName,
74 _rMessage,
75 aTimeStamp,
76 _nEventNumber,
77 getCurrentThreadID(),
78 _nLogLevel
79 );
80 }
81
82
83} // namespace logging
84
85
86/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
LogRecord createLogRecord(const OUString &_rLoggerName, const OUString &_rClassName, const OUString &_rMethodName, const OUString &_rMessage, sal_Int32 _nLogLevel, oslInterlockedCount _nEventNumber)
Definition: logrecord.cxx:51