void JLogger::doSetParent(JLogger* newParent) { treeLock->lock(); JLogger* ref = NULL; if (parent != NULL) { JIterator* iter=NULL; for (iter = parent->kids->iterator(); iter->hasNext(); ) { ref = (JLogger*)iter->next(); if (ref == this) { iter->remove(); break; } else { ref = NULL; } } delete iter; } parent = newParent; if (parent->kids == NULL) { parent->kids = new JArrayList(); } parent->kids->add(parent); updateEffectiveLevel(); treeLock->unlock(); }
void LogCategory::setLevelLocked(LogLevel level, bool inherit) { // Clamp the value to MIN_LEVEL and MAX_LEVEL. // // This makes sure that UNINITIALIZED is always less than any valid level // value, and that level values cannot conflict with our flag bits. level = constexpr_clamp(level, LogLevel::MIN_LEVEL, LogLevel::MAX_LEVEL); // Make sure the inherit flag is always off for the root logger. if (!parent_) { inherit = false; } auto newValue = static_cast<uint32_t>(level); if (inherit) { newValue |= FLAG_INHERIT; } // Update the stored value uint32_t oldValue = level_.exchange(newValue, std::memory_order_acq_rel); // Break out early if the value has not changed. if (oldValue == newValue) { return; } // Update the effective log level LogLevel newEffectiveLevel; if (inherit) { newEffectiveLevel = std::min(level, parent_->getEffectiveLevel()); } else { newEffectiveLevel = level; } updateEffectiveLevel(newEffectiveLevel); }
void LogCategory::parentLevelUpdated(LogLevel parentEffectiveLevel) { uint32_t levelValue = level_.load(std::memory_order_acquire); auto inherit = (levelValue & FLAG_INHERIT); if (!inherit) { return; } auto myLevel = static_cast<LogLevel>(levelValue & ~FLAG_INHERIT); auto newEffectiveLevel = std::min(myLevel, parentEffectiveLevel); updateEffectiveLevel(newEffectiveLevel); }
void JLogger::setLevel(JLevel* newLevel) { treeLock->lock(); levelObject = newLevel; updateEffectiveLevel(); treeLock->unlock(); }