//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2014-2017 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Daniel H. Larkin //////////////////////////////////////////////////////////////////////////////// #include "Views/LoggerView.h" #include "Basics/Common.h" #include "Basics/Result.h" #include "Logger/Logger.h" #include "VocBase/LogicalView.h" #include "VocBase/ViewImplementation.h" #include "VocBase/voc-types.h" #include #include using namespace arangodb; static LogLevel LevelStringToEnum(std::string const& level) { if (level == "ERR") { return LogLevel::ERR; } if (level == "WARN") { return LogLevel::WARN; } if (level == "INFO") { return LogLevel::INFO; } if (level == "DEBUG") { return LogLevel::DEBUG; } return LogLevel::TRACE; } static std::string LevelEnumToString(LogLevel level) { switch (level) { case LogLevel::ERR: return "ERR"; case LogLevel::WARN: return "WARN"; case LogLevel::INFO: return "INFO"; case LogLevel::DEBUG: return "DEBUG"; default: return "TRACE"; } } std::string LoggerView::type("logger"); std::unique_ptr LoggerView::creator( LogicalView* view, arangodb::velocypack::Slice const& info) { LOG_TOPIC(INFO, Logger::FIXME) << "called LoggerView::creator"; return std::make_unique(view, info); } LoggerView::LoggerView(LogicalView* logical, arangodb::velocypack::Slice const& info) : ViewImplementation(logical, info) { VPackSlice properties = info.get("properties"); if (!properties.isObject()) { _level = LogLevel::TRACE; return; } VPackSlice levelSlice = properties.get("level"); if (!levelSlice.isString()) { _level = LogLevel::TRACE; return; } std::string levelString = levelSlice.copyString(); _level = LevelStringToEnum(levelString); } arangodb::Result LoggerView::updateProperties( arangodb::velocypack::Slice const& slice, bool doSync) { LOG_TOPIC(INFO, Logger::FIXME) << "called LoggerView::updateProperties with data " << slice.toJson() << ". view data: " << _logicalView->toVelocyPack(true, false).slice().toJson(); VPackSlice levelSlice = slice.get("level"); if (!levelSlice.isString()) { return {TRI_ERROR_BAD_PARAMETER, "expecting to be specified as string"}; } std::string levelString = levelSlice.copyString(); _level = LevelStringToEnum(levelString); return {}; } /// @brief export properties void LoggerView::getPropertiesVPack(velocypack::Builder& builder) const { LOG_TOPIC(INFO, Logger::FIXME) << "called LoggerView::getPropertiesVPack"; TRI_ASSERT(builder.isOpenObject()); builder.add("level", VPackValue(LevelEnumToString(_level))); TRI_ASSERT(builder.isOpenObject()); } /// @brief opens an existing view void LoggerView::open() { LOG_TOPIC(INFO, Logger::FIXME) << "called LoggerView::open. view data: " << _logicalView->toVelocyPack(true, false).slice().toJson(); } void LoggerView::drop() { LOG_TOPIC(INFO, Logger::FIXME) << "called LoggerView::drop. view data: " << _logicalView->toVelocyPack(true, false).slice().toJson(); }