This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from BojanKV/master
Initial logging support instead of direct stdout in w3c-visserver-api
- Loading branch information
Showing
20 changed files
with
610 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright (c) 2019 Robert Bosch GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* | ||
* Contributors: | ||
* Robert Bosch GmbH - initial API and functionality | ||
* ***************************************************************************** | ||
*/ | ||
|
||
|
||
#ifndef __LOGGER_H__ | ||
#define __LOGGER_H__ | ||
|
||
#include "ILogger.hpp" | ||
|
||
#include <mutex> | ||
|
||
|
||
/** | ||
* \class Logger | ||
* \brief Implementation class of logging utility | ||
* | ||
* Logger shall provide standardized way to put logging information | ||
* to standard output (stdout) | ||
* | ||
*/ | ||
class BasicLogger : public ILogger { | ||
private: | ||
std::mutex accessMutex; | ||
const uint8_t logLevels; | ||
|
||
public: | ||
BasicLogger(uint8_t logEventsEnabled); | ||
~BasicLogger(); | ||
|
||
void Log(LogLevel level, std::string logString); | ||
}; | ||
|
||
#endif /* __LOGGER_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright (c) 2019 Robert Bosch GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* | ||
* Contributors: | ||
* Robert Bosch GmbH - initial API and functionality | ||
* ***************************************************************************** | ||
*/ | ||
|
||
|
||
#ifndef __ILOGGER_H__ | ||
#define __ILOGGER_H__ | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
/** | ||
* \class LogLevel | ||
* \brief Supported logging levels | ||
* | ||
* Enumeration shall be used by implementations of \ref ILogger class to define | ||
* which events to log. | ||
* As enumeration is bitwise compatible, implementations can allow for combining | ||
* different log levels (e.g. INFO & ERROR, other levels shall be ignored) | ||
*/ | ||
enum class LogLevel : uint8_t { | ||
NONE = 0x0, //!< No logging allowed | ||
VERBOSE = 0x1, //!< Used for logging verbose or debug information, not relevant in normal execution | ||
INFO = 0x2, //!< Used for logging e.g. positive information relevant to execution | ||
WARNING = 0x4, //!< Used for logging warning states and information that is not critical | ||
ERROR = 0x8, //!< Used for logging any error or fail information | ||
ALL = 0xF //!< Used for selecting all log levels | ||
}; | ||
|
||
|
||
/** | ||
* \class ILogger | ||
* \brief Interface definition for logging utility | ||
* | ||
* Interface for logger allows to easily add support for logging through different | ||
* means or requirements (e.g. resource scarce platforms, socket, serial, ...) | ||
* | ||
*/ | ||
class ILogger { | ||
public: | ||
virtual ~ILogger() {} | ||
|
||
/** | ||
* \brief Log message of specified notification level | ||
* | ||
* \param[in] Level of importance of log message | ||
* \param[in] Log message | ||
*/ | ||
virtual void Log(LogLevel, std::string) = 0; | ||
|
||
}; | ||
|
||
#endif /* __ILOGGER_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* ****************************************************************************** | ||
* Copyright (c) 2019 Robert Bosch GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* | ||
* Contributors: | ||
* Robert Bosch GmbH - initial API and functionality | ||
* ***************************************************************************** | ||
*/ | ||
|
||
#include "BasicLogger.hpp" | ||
|
||
#include <iostream> | ||
|
||
|
||
using namespace std; | ||
|
||
namespace { | ||
std::string GetLevelString(LogLevel level) { | ||
std::string retStr; | ||
switch (level) { | ||
case LogLevel::VERBOSE: | ||
retStr = "VERBOSE: "; | ||
break; | ||
case LogLevel::INFO: | ||
retStr = "INFO: "; | ||
break; | ||
case LogLevel::WARNING: | ||
retStr = "WARNING: "; | ||
break; | ||
case LogLevel::ERROR: | ||
retStr = "ERROR: "; | ||
break; | ||
default: | ||
retStr = "UNKNOWN: "; | ||
break; | ||
} | ||
return retStr; | ||
} | ||
} | ||
|
||
|
||
BasicLogger::BasicLogger(uint8_t logEventsEnabled) : logLevels(logEventsEnabled) { | ||
cout << "Log START" << endl; | ||
} | ||
|
||
|
||
BasicLogger::~BasicLogger() { | ||
cout << "Log END" << endl; | ||
} | ||
|
||
void BasicLogger::Log(LogLevel level, std::string logString) { | ||
std::lock_guard<std::mutex> guard(accessMutex); | ||
|
||
/* log only if level in supported */ | ||
if (static_cast<uint8_t>(level) & logLevels) { | ||
cout << GetLevelString(level) + logString << endl; | ||
} | ||
} |
Oops, something went wrong.