//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2013 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 Dr. Frank Celler //////////////////////////////////////////////////////////////////////////////// #include "LogTopic.h" #include "Basics/MutexLocker.h" #include "Logger/Logger.h" #ifdef USE_ENTERPRISE #include "Enterprise/Audit/AuditFeature.h" #endif using namespace arangodb; namespace { std::atomic NEXT_TOPIC_ID(0); } Mutex LogTopic::_namesLock; std::map LogTopic::_names; LogTopic Logger::AGENCY("agency", LogLevel::INFO); LogTopic Logger::AGENCYCOMM("agencycomm", LogLevel::INFO); LogTopic Logger::CLUSTER("cluster", LogLevel::INFO); LogTopic Logger::COLLECTOR("collector"); LogTopic Logger::COMMUNICATION("communication", LogLevel::INFO); LogTopic Logger::COMPACTOR("compactor"); LogTopic Logger::CONFIG("config"); LogTopic Logger::DATAFILES("datafiles", LogLevel::INFO); LogTopic Logger::DEVEL("development", LogLevel::DEBUG); LogTopic Logger::GRAPHS("graphs", LogLevel::INFO); LogTopic Logger::HEARTBEAT("heartbeat", LogLevel::INFO); LogTopic Logger::MEMORY("memory", LogLevel::FATAL); // suppress LogTopic Logger::MMAP("mmap"); LogTopic Logger::PERFORMANCE("performance", LogLevel::FATAL); // suppress LogTopic Logger::QUERIES("queries", LogLevel::INFO); LogTopic Logger::REPLICATION("replication", LogLevel::INFO); LogTopic Logger::REQUESTS("requests", LogLevel::FATAL); // suppress LogTopic Logger::STARTUP("startup", LogLevel::INFO); LogTopic Logger::THREADS("threads", LogLevel::WARN); LogTopic Logger::V8("v8", LogLevel::WARN); #ifdef USE_ENTERPRISE LogTopic AuditFeature::AUDIT_AUTHENTICATION("audit-authentication", LogLevel::INFO); LogTopic AuditFeature::AUDIT_DATABASE("audit-database", LogLevel::INFO); LogTopic AuditFeature::AUDIT_COLLECTION("audit-collection", LogLevel::INFO); LogTopic AuditFeature::AUDIT_DOCUMENT("audit-documentation", LogLevel::INFO); LogTopic AuditFeature::AUDIT_SERVICE("audit-service", LogLevel::INFO); #endif std::vector> LogTopic::logLevelTopics() { std::vector> levels; MUTEX_LOCKER(guard, _namesLock); for (auto const& topic : _names) { levels.emplace_back(std::make_pair(topic.first, topic.second->level())); } return levels; } void LogTopic::setLogLevel(std::string const& name, LogLevel level) { MUTEX_LOCKER(guard, _namesLock); auto it = _names.find(name); if (it == _names.end()) { LOG(ERR) << "strange topic '" << name << "'"; return; } auto topic = it->second; if (topic != nullptr) { topic->setLogLevel(level); } } LogTopic* LogTopic::lookup(std::string const& name) { MUTEX_LOCKER(guard, _namesLock); auto it = _names.find(name); if (it == _names.end()) { return nullptr; } return it->second; } LogTopic::LogTopic(std::string const& name) : LogTopic(name, LogLevel::DEFAULT) {} LogTopic::LogTopic(std::string const& name, LogLevel level) : _id(NEXT_TOPIC_ID.fetch_add(1, std::memory_order_seq_cst)), _name(name), _level(level) { try { MUTEX_LOCKER(guard, _namesLock); _names[name] = this; } catch (...) { } }