blob: 08b8eb354afc3df4138f727a4bb0a36c017458fc [file] [log] [blame]
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_LOGGING_HELPERS_H
25#define ARM_COMPUTE_LOGGING_HELPERS_H
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010026
27#include "arm_compute/core/utils/logging/Types.h"
Matthew Bentham758b5ba2020-03-05 23:37:48 +000028#include "support/MemorySupport.h"
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010029#include "support/ToolchainSupport.h"
30
31#include <cstddef>
32#include <cstdio>
33#include <memory>
34#include <sstream>
35#include <string>
36
37namespace arm_compute
38{
39namespace logging
40{
41/** Create a string given a format
42 *
43 * @param[in] fmt String format
44 * @param[in] args Arguments
45 *
46 * @return The formatted string
47 */
48template <typename... Ts>
49inline std::string string_with_format(const std::string &fmt, Ts &&... args)
50{
51 size_t size = support::cpp11::snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
52 auto char_str = support::cpp14::make_unique<char[]>(size);
53 support::cpp11::snprintf(char_str.get(), size, fmt.c_str(), args...);
54 return std::string(char_str.get(), char_str.get() + size - 1);
55}
56/** Wraps a value with angles and returns the string
57 *
58 * @param[in] val Value to wrap
59 *
60 * @return Wrapped string
61 */
62template <typename T>
63inline std::string angle_wrap_value(const T &val)
64{
65 std::ostringstream ss;
66 ss << "[" << val << "]";
67 return ss.str();
68}
69/** Translates a given log level to a string.
70 *
71 * @param[in] log_level @ref LogLevel to be translated to string.
72 *
73 * @return The string describing the logging level.
74 */
75const std::string &string_from_log_level(LogLevel log_level);
76} // namespace logging
77} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000078#endif /* ARM_COMPUTE_LOGGING_HELPERS_H */