| 1591 | } |
| 1592 | |
| 1593 | void TypedConfigurations::build(Configurations* configurations) { |
| 1594 | base::threading::ScopedLock scopedLock(lock()); |
| 1595 | auto getBool = [] (std::string boolStr) -> bool { // Pass by value for trimming |
| 1596 | base::utils::Str::trim(boolStr); |
| 1597 | return (boolStr == "TRUE" || boolStr == "true" || boolStr == "1"); |
| 1598 | }; |
| 1599 | std::vector<Configuration*> withFileSizeLimit; |
| 1600 | for (Configurations::const_iterator it = configurations->begin(); it != configurations->end(); ++it) { |
| 1601 | Configuration* conf = *it; |
| 1602 | // We cannot use switch on strong enums because Intel C++ dont support them yet |
| 1603 | if (conf->configurationType() == ConfigurationType::Enabled) { |
| 1604 | setValue(conf->level(), getBool(conf->value()), &m_enabledMap); |
| 1605 | } else if (conf->configurationType() == ConfigurationType::ToFile) { |
| 1606 | setValue(conf->level(), getBool(conf->value()), &m_toFileMap); |
| 1607 | } else if (conf->configurationType() == ConfigurationType::ToStandardOutput) { |
| 1608 | setValue(conf->level(), getBool(conf->value()), &m_toStandardOutputMap); |
| 1609 | } else if (conf->configurationType() == ConfigurationType::Filename) { |
| 1610 | // We do not yet configure filename but we will configure in another |
| 1611 | // loop. This is because if file cannot be created, we will force ToFile |
| 1612 | // to be false. Because configuring logger is not necessarily performance |
| 1613 | // sensative operation, we can live with another loop; (by the way this loop |
| 1614 | // is not very heavy either) |
| 1615 | } else if (conf->configurationType() == ConfigurationType::Format) { |
| 1616 | setValue(conf->level(), base::LogFormat(conf->level(), |
| 1617 | base::type::string_t(conf->value().begin(), conf->value().end())), &m_logFormatMap); |
| 1618 | } else if (conf->configurationType() == ConfigurationType::SubsecondPrecision) { |
| 1619 | setValue(Level::Global, |
| 1620 | base::SubsecondPrecision(static_cast<int>(getULong(conf->value()))), &m_subsecondPrecisionMap); |
| 1621 | } else if (conf->configurationType() == ConfigurationType::PerformanceTracking) { |
| 1622 | setValue(Level::Global, getBool(conf->value()), &m_performanceTrackingMap); |
| 1623 | } else if (conf->configurationType() == ConfigurationType::MaxLogFileSize) { |
| 1624 | setValue(conf->level(), static_cast<std::size_t>(getULong(conf->value())), &m_maxLogFileSizeMap); |
| 1625 | #if !defined(ELPP_NO_DEFAULT_LOG_FILE) |
| 1626 | withFileSizeLimit.push_back(conf); |
| 1627 | #endif // !defined(ELPP_NO_DEFAULT_LOG_FILE) |
| 1628 | } else if (conf->configurationType() == ConfigurationType::LogFlushThreshold) { |
| 1629 | setValue(conf->level(), static_cast<std::size_t>(getULong(conf->value())), &m_logFlushThresholdMap); |
| 1630 | } |
| 1631 | } |
| 1632 | // As mentioned earlier, we will now set filename configuration in separate loop to deal with non-existent files |
| 1633 | for (Configurations::const_iterator it = configurations->begin(); it != configurations->end(); ++it) { |
| 1634 | Configuration* conf = *it; |
| 1635 | if (conf->configurationType() == ConfigurationType::Filename) { |
| 1636 | insertFile(conf->level(), conf->value()); |
| 1637 | } |
| 1638 | } |
| 1639 | for (std::vector<Configuration*>::iterator conf = withFileSizeLimit.begin(); |
| 1640 | conf != withFileSizeLimit.end(); ++conf) { |
| 1641 | // This is not unsafe as mutex is locked in currect scope |
| 1642 | unsafeValidateFileRolling((*conf)->level(), base::defaultPreRollOutCallback); |
| 1643 | } |
| 1644 | } |
| 1645 | |
| 1646 | unsigned long TypedConfigurations::getULong(std::string confVal) { |
| 1647 | bool valid = true; |
no test coverage detected