LibreOffice Module extensions (master) 1
simpletextformatter.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 <sal/config.h>
21
22#include <com/sun/star/logging/XLogFormatter.hpp>
23#include <com/sun/star/logging/LogLevel.hpp>
24#include <com/sun/star/uno/XComponentContext.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
26
29
30namespace logging
31{
32using css::logging::LogRecord;
33using namespace css::uno;
34
35namespace
36{
37class SimpleTextFormatter
38 : public cppu::WeakImplHelper<css::logging::XLogFormatter, css::lang::XServiceInfo>
39{
40public:
41 SimpleTextFormatter();
42
43private:
44 // XLogFormatter
45 virtual OUString SAL_CALL getHead() override;
46 virtual OUString SAL_CALL format(const LogRecord& Record) override;
47 virtual OUString SAL_CALL getTail() override;
48
49 // XServiceInfo
50 virtual OUString SAL_CALL getImplementationName() override;
51 virtual sal_Bool SAL_CALL supportsService(const OUString& _rServiceName) override;
52 virtual Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
53};
54}
55
56SimpleTextFormatter::SimpleTextFormatter() {}
57
58OUString SAL_CALL SimpleTextFormatter::getHead() { return OUString(); }
59
60OUString SAL_CALL SimpleTextFormatter::format(const LogRecord& _rRecord)
61{
62 OUString aLogEntry;
63 // Highlight warnings
64 if (_rRecord.Level == css::logging::LogLevel::SEVERE)
65 aLogEntry = "ERROR: ";
66 else if (_rRecord.Level == css::logging::LogLevel::WARNING)
67 aLogEntry = "WARNING: ";
68
69 return aLogEntry + _rRecord.Message + "\n";
70}
71
72OUString SAL_CALL SimpleTextFormatter::getTail() { return OUString(); }
73
74sal_Bool SAL_CALL SimpleTextFormatter::supportsService(const OUString& _rServiceName)
75{
76 return cppu::supportsService(this, _rServiceName);
77}
78
79OUString SAL_CALL SimpleTextFormatter::getImplementationName()
80{
81 return "com.sun.star.comp.extensions.SimpleTextFormatter";
82}
83
84Sequence<OUString> SAL_CALL SimpleTextFormatter::getSupportedServiceNames()
85{
86 return { "com.sun.star.logging.SimpleTextFormatter" };
87}
88
89} // namespace logging
90
91extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
93 css::uno::Sequence<css::uno::Any> const&)
94{
95 return cppu::acquire(new logging::SimpleTextFormatter());
96}
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_extensions_SimpleTextFormatter(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool