Avoid potential negative array index access to cached text.
[LibreOffice.git] / extensions / source / logging / simpletextformatter.cxx
blobb54fea5a645b17504974b0b7e68a47084c399294
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
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>
27 #include <cppuhelper/implbase.hxx>
28 #include <cppuhelper/supportsservice.hxx>
30 namespace logging
32 using css::logging::LogRecord;
33 using namespace css::uno;
35 namespace
37 class SimpleTextFormatter
38 : public cppu::WeakImplHelper<css::logging::XLogFormatter, css::lang::XServiceInfo>
40 public:
41 SimpleTextFormatter();
43 private:
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;
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;
56 SimpleTextFormatter::SimpleTextFormatter() {}
58 OUString SAL_CALL SimpleTextFormatter::getHead() { return OUString(); }
60 OUString SAL_CALL SimpleTextFormatter::format(const LogRecord& _rRecord)
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: ";
69 return aLogEntry + _rRecord.Message + "\n";
72 OUString SAL_CALL SimpleTextFormatter::getTail() { return OUString(); }
74 sal_Bool SAL_CALL SimpleTextFormatter::supportsService(const OUString& _rServiceName)
76 return cppu::supportsService(this, _rServiceName);
79 OUString SAL_CALL SimpleTextFormatter::getImplementationName()
81 return "com.sun.star.comp.extensions.SimpleTextFormatter";
84 Sequence<OUString> SAL_CALL SimpleTextFormatter::getSupportedServiceNames()
86 return { "com.sun.star.logging.SimpleTextFormatter" };
89 } // namespace logging
91 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
92 com_sun_star_comp_extensions_SimpleTextFormatter(css::uno::XComponentContext*,
93 css::uno::Sequence<css::uno::Any> const&)
95 return cppu::acquire(new logging::SimpleTextFormatter());
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */