2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef __VOM_LOGGER_H__
17 #define __VOM_LOGGER_H__
22 #include "vom/enum_base.hpp"
25 struct log_level_t : enum_base<log_level_t>
27 const static log_level_t CRITICAL;
28 const static log_level_t ERROR;
29 const static log_level_t WARNING;
30 const static log_level_t INFO;
31 const static log_level_t DEBUG;
35 * Private constructor taking the value and the string name
37 log_level_t(int v, const std::string& s);
41 * Ideally we'd use the boost logger but that is not prevelent
42 * in many distros. So something simple here instead.
55 std::ostream& stream(const char* file, int line);
58 * The configured level
60 const log_level_t& level() const;
63 * set the logging level
65 void set(const log_level_t& level);
68 * set a file to receive the logging data
70 void set(const std::string& ofile);
74 * the configured logging level
79 * Opened file for debugging
81 std::ofstream m_file_stream;
84 * Pointer to the output stream
86 std::ostream* m_o_stream;
90 * Return a log object into which VPP objects can write
94 #define VOM_LOG(lvl) \
95 if (lvl >= logger().level()) \
96 logger().stream(__FILE__, __LINE__)
100 * fd.io coding-style-patch-verification: ON
103 * eval: (c-set-style "mozilla")