OpFlex Framework  1.3.0
OFLogHandler.h
Go to the documentation of this file.
1 /* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
6 /*
7  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
8  *
9  * This program and the accompanying materials are made available under the
10  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
11  * and is available at http://www.eclipse.org/legal/epl-v10.html
12  */
13 
14 #pragma once
15 #ifndef OPFLEX_LOGGING_OFLOGHANDLER_H
16 #define OPFLEX_LOGGING_OFLOGHANDLER_H
17 
18 #include <string>
19 
20 namespace opflex {
21 namespace logging {
22 
52 class OFLogHandler {
53 public:
54 
58  enum Level {
59  TRACE,
60  DEBUG7,
61  DEBUG6,
62  DEBUG5,
63  DEBUG4,
64  DEBUG3,
65  DEBUG2,
66  DEBUG1,
67  DEBUG0,
68  INFO,
69  WARNING,
70  ERROR,
71  FATAL,
72 
73  /* keep as the last one */
74  NO_LOGGING
75  };
76 
83  OFLogHandler(Level logLevel)
84  __attribute__((no_instrument_function));
85 
86  virtual ~OFLogHandler()
87  __attribute__((no_instrument_function));
88 
101  virtual void handleMessage(const std::string& file,
102  const int line,
103  const std::string& function,
104  const Level level,
105  const std::string& message) = 0;
106 
113  virtual bool shouldEmit(const Level level)
114  __attribute__((no_instrument_function));
115 
123  static void registerHandler(OFLogHandler& handler)
124  __attribute__((no_instrument_function));
125 
132  static OFLogHandler* getHandler()
133  __attribute__((no_instrument_function));
134 
135 protected:
140 };
141 
142 /* @} logging */
143 /* @} cpp */
144 
145 } /* namespace logging */
146 } /* namespace opflex */
147 
148 #endif /* OPFLEX_LOGGING_OFLOGHANDLER_H */
virtual bool shouldEmit(const Level level) __attribute__((no_instrument_function))
Check whether we should attempt to log at the given log level.
virtual void handleMessage(const std::string &file, const int line, const std::string &function, const Level level, const std::string &message)=0
Process a single log message.
static OFLogHandler * getHandler() __attribute__((no_instrument_function))
Get the currently-active log handler.
static void registerHandler(OFLogHandler &handler) __attribute__((no_instrument_function))
Register a custom handler as the log handler.
Level logLevel_
The log level for this logger.
Definition: OFLogHandler.h:139
Level
Log levels for OpFlex framework logging.
Definition: OFLogHandler.h:58
Interface for a log message handler for the OpFlex framework.
Definition: OFLogHandler.h:52
OFLogHandler(Level logLevel) __attribute__((no_instrument_function))
Allocate a log handler that will log any messages with equal or greater severity than the specified l...