Skip to content
Snippets Groups Projects
easylogging++.h 278 KiB
Newer Older
  • Learn to ignore specific revisions
  • Radim Vavřík's avatar
    Radim Vavřík committed
    2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000
                for (auto&& curr : this->list()) {
                    base::utils::safeDelete(curr);
                }
                this->list().clear();
            }
        }
    
        virtual void unregister(T_Ptr*& ptr) ELPP_FINAL {  // NOLINT
            if (ptr) {
                iterator iter = this->begin();
                for (; iter != this->end(); ++iter) {
                    if (ptr == *iter) {
                        break;
                    }
                }
                if (iter != this->end() && *iter != nullptr) {
                    this->list().erase(iter);
                    base::utils::safeDelete(*iter);
                }
            }
        }
    
        virtual inline void registerNew(T_Ptr* ptr) ELPP_FINAL {
            this->list().push_back(ptr);
        }
    
        /// @brief Gets pointer from repository with speicifed arguments. Arguments are passed to predicate
        /// in order to validate pointer.
        template <typename T, typename T2>
        inline T_Ptr* get(const T& arg1, const T2 arg2) {
            iterator iter = std::find_if(this->list().begin(), this->list().end(), Pred(arg1, arg2));
            if (iter != this->list().end() && *iter != nullptr) {
                return *iter;
            }
            return nullptr;
        }
    
    private:
        virtual inline void deepCopy(const AbstractRegistry<T_Ptr, std::vector<T_Ptr*>>& sr) {
            for (const_iterator it = sr.list().begin(); it != sr.list().end(); ++it) {
                registerNew(new T_Ptr(**it));
            }
        }
    };
    
    }  // namespace utils
    } // namespace base
    /// @brief Base of Easylogging++ friendly class
    ///
    /// @detail After inheriting this class publicly, implement pure-virtual function `void log(std::ostream&) const`
    class Loggable {
    public:
        virtual ~Loggable(void) {}
        virtual void log(el::base::type::ostream_t&) const = 0;
    private:
        friend inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const Loggable& loggable) {
            loggable.log(os);
            return os;
        }
    };
    namespace base {
    /// @brief Represents log format containing flags and date format. This is used internally to start initial log
    class LogFormat : public Loggable {
    public:
        LogFormat(void) :
            m_level(Level::Unknown),
            m_userFormat(base::type::string_t()),
            m_format(base::type::string_t()),
            m_dateTimeFormat(std::string()),
            m_flags(0x0) {
        }
    
        LogFormat(Level level, const base::type::string_t& format)
                : m_level(level), m_userFormat(format) {
            parseFromFormat(m_userFormat);
        }
    
        LogFormat(const LogFormat& logFormat) {
            m_level = logFormat.m_level;
            m_userFormat = logFormat.m_userFormat;
            m_format = logFormat.m_format;
            m_dateTimeFormat = logFormat.m_dateTimeFormat;
            m_flags = logFormat.m_flags;
        }
    
        LogFormat(LogFormat&& logFormat) {
            m_level = std::move(logFormat.m_level);
            m_userFormat = std::move(logFormat.m_userFormat);
            m_format = std::move(logFormat.m_format);
            m_dateTimeFormat = std::move(logFormat.m_dateTimeFormat);
            m_flags = std::move(logFormat.m_flags);
        }
    
        LogFormat& operator=(const LogFormat& logFormat) {
            m_level = logFormat.m_level;
            m_userFormat = logFormat.m_userFormat;
            m_dateTimeFormat = logFormat.m_dateTimeFormat;
            m_flags = logFormat.m_flags;
            return *this;
        }
    
        virtual ~LogFormat(void) {
        }
    
        inline bool operator==(const LogFormat& other) {
            return m_level == other.m_level && m_userFormat == other.m_userFormat && m_format == other.m_format &&
                    m_dateTimeFormat == other.m_dateTimeFormat && m_flags == other.m_flags;
        }
    
        /// @brief Updates format to be used while logging.
        /// @param userFormat User provided format
        void parseFromFormat(const base::type::string_t& userFormat) {
            // We make copy because we will be changing the format
            // i.e, removing user provided date format from original format
            // and then storing it.
            base::type::string_t formatCopy = userFormat;
            m_flags = 0x0;
            auto conditionalAddFlag = [&](const base::type::char_t* specifier, base::FormatFlags flag) {
                std::size_t foundAt = base::type::string_t::npos;
                while ((foundAt = formatCopy.find(specifier, foundAt + 1)) != base::type::string_t::npos){
                    if (foundAt > 0 && formatCopy[foundAt - 1] == base::consts::kFormatSpecifierChar) {
                        if (hasFlag(flag)) {
                            // If we already have flag we remove the escape chars so that '%%' is turned to '%'
                            // even after specifier resolution - this is because we only replaceFirst specifier
                            formatCopy.erase(foundAt > 0 ? foundAt - 1 : 0, 1);
                            ++foundAt;
                        }
                    } else {
                        if (!hasFlag(flag)) addFlag(flag);
                    }
                }
            };  // NOLINT
            conditionalAddFlag(base::consts::kAppNameFormatSpecifier, base::FormatFlags::AppName);
            conditionalAddFlag(base::consts::kSeverityLevelFormatSpecifier, base::FormatFlags::Level);
            conditionalAddFlag(base::consts::kSeverityLevelShortFormatSpecifier, base::FormatFlags::LevelShort);
            conditionalAddFlag(base::consts::kLoggerIdFormatSpecifier, base::FormatFlags::LoggerId);
            conditionalAddFlag(base::consts::kThreadIdFormatSpecifier, base::FormatFlags::ThreadId);
            conditionalAddFlag(base::consts::kLogFileFormatSpecifier, base::FormatFlags::File);
            conditionalAddFlag(base::consts::kLogFileBaseFormatSpecifier, base::FormatFlags::FileBase);
            conditionalAddFlag(base::consts::kLogLineFormatSpecifier, base::FormatFlags::Line);
            conditionalAddFlag(base::consts::kLogLocationFormatSpecifier, base::FormatFlags::Location);
            conditionalAddFlag(base::consts::kLogFunctionFormatSpecifier, base::FormatFlags::Function);
            conditionalAddFlag(base::consts::kCurrentUserFormatSpecifier, base::FormatFlags::User);
            conditionalAddFlag(base::consts::kCurrentHostFormatSpecifier, base::FormatFlags::Host);
            conditionalAddFlag(base::consts::kMessageFormatSpecifier, base::FormatFlags::LogMessage);
            conditionalAddFlag(base::consts::kVerboseLevelFormatSpecifier, base::FormatFlags::VerboseLevel);
            // For date/time we need to extract user's date format first
            std::size_t dateIndex = std::string::npos;
            if ((dateIndex = formatCopy.find(base::consts::kDateTimeFormatSpecifier)) != std::string::npos) {
                while (dateIndex > 0 && formatCopy[dateIndex - 1] == base::consts::kFormatSpecifierChar) {
                    dateIndex = formatCopy.find(base::consts::kDateTimeFormatSpecifier, dateIndex + 1);
                }
                if (dateIndex != std::string::npos) {
                    addFlag(base::FormatFlags::DateTime);
                    updateDateFormat(dateIndex, formatCopy);
                }
            }
            m_format = formatCopy;
            updateFormatSpec();
        }
    
        inline Level level(void) const {
            return m_level;
        }
    
        inline const base::type::string_t& userFormat(void) const {
            return m_userFormat;
        }
    
        inline const base::type::string_t& format(void) const {
           return m_format;
        }
    
        inline const std::string& dateTimeFormat(void) const {
           return m_dateTimeFormat;
        }
    
        inline base::type::EnumType flags(void) const {
           return m_flags;
        }
    
        inline bool hasFlag(base::FormatFlags flag) const {
            return base::utils::hasFlag(flag, m_flags);
        }
    
        virtual void log(el::base::type::ostream_t& os) const {
            os << m_format;
        }
    
    protected:
        /// @brief Updates date time format if available in currFormat.
        /// @param index Index where %datetime, %date or %time was found
        /// @param [in,out] currFormat current format that is being used to format
        virtual void updateDateFormat(std::size_t index, base::type::string_t& currFormat) ELPP_FINAL {  // NOLINT
            if (hasFlag(base::FormatFlags::DateTime)) {
                index += ELPP_STRLEN(base::consts::kDateTimeFormatSpecifier);
            }
            const base::type::char_t* ptr = currFormat.c_str() + index;
            if ((currFormat.size() > index) && (ptr[0] == '{')) {
                // User has provided format for date/time
                ++ptr;
                int count = 1;  // Start by 1 in order to remove starting brace
                std::stringstream ss;
                for (; *ptr; ++ptr, ++count) {
                    if (*ptr == '}') {
                        ++count;  // In order to remove ending brace
                        break;
                    }
                    ss << *ptr;
                }
                currFormat.erase(index, count);
                m_dateTimeFormat = ss.str();
            } else {
                // No format provided, use default
                if (hasFlag(base::FormatFlags::DateTime)) {
                    m_dateTimeFormat = std::string(base::consts::kDefaultDateTimeFormat);
                }
            }
        }
    
        /// @brief Updates %level from format. This is so that we dont have to do it at log-writing-time. It uses m_format and m_level
        virtual void updateFormatSpec(void) ELPP_FINAL {
            // Do not use switch over strongly typed enums because Intel C++ compilers dont support them yet.
            if (m_level == Level::Debug) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelFormatSpecifier,
                        base::consts::kDebugLevelLogValue);
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelShortFormatSpecifier,
                        base::consts::kDebugLevelShortLogValue);
            } else if (m_level == Level::Info) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelFormatSpecifier,
                        base::consts::kInfoLevelLogValue);
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelShortFormatSpecifier,
                        base::consts::kInfoLevelShortLogValue);
            } else if (m_level == Level::Warning) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelFormatSpecifier,
                        base::consts::kWarningLevelLogValue);
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelShortFormatSpecifier,
                        base::consts::kWarningLevelShortLogValue);
            } else if (m_level == Level::Error) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelFormatSpecifier,
                        base::consts::kErrorLevelLogValue);
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelShortFormatSpecifier,
                        base::consts::kErrorLevelShortLogValue);
            } else if (m_level == Level::Fatal) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelFormatSpecifier,
                        base::consts::kFatalLevelLogValue);
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelShortFormatSpecifier,
                        base::consts::kFatalLevelShortLogValue);
            } else if (m_level == Level::Verbose) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelFormatSpecifier,
                        base::consts::kVerboseLevelLogValue);
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelShortFormatSpecifier,
                        base::consts::kVerboseLevelShortLogValue);
            } else if (m_level == Level::Trace) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelFormatSpecifier,
                        base::consts::kTraceLevelLogValue);
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kSeverityLevelShortFormatSpecifier,
                        base::consts::kTraceLevelShortLogValue);
            }
            if (hasFlag(base::FormatFlags::User)) {
                std::string s = base::utils::s_currentUser;
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kCurrentUserFormatSpecifier,
                        base::utils::s_currentUser);
            }
            if (hasFlag(base::FormatFlags::Host)) {
                base::utils::Str::replaceFirstWithEscape(m_format, base::consts::kCurrentHostFormatSpecifier,
                        base::utils::s_currentHost);
            }
            // Ignore Level::Global and Level::Unknown
        }
    
        inline void addFlag(base::FormatFlags flag) {
            base::utils::addFlag(flag, &m_flags);
        }
    
    private:
        Level m_level;
        base::type::string_t m_userFormat;
        base::type::string_t m_format;
        std::string m_dateTimeFormat;
        base::type::EnumType m_flags;
        friend class el::Logger;  // To resolve loggerId format specifier easily
    };
    }  // namespace base
    /// @brief Resolving function for format specifier
    typedef std::function<const char*(void)> FormatSpecifierValueResolver;
    /// @brief User-provided custom format specifier
    /// @see el::Helpers::installCustomFormatSpecifier
    /// @see FormatSpecifierValueResolver
    class CustomFormatSpecifier {
    public:
        CustomFormatSpecifier(const char* formatSpecifier, const FormatSpecifierValueResolver& resolver) :
            m_formatSpecifier(formatSpecifier), m_resolver(resolver) {}
        inline const char* formatSpecifier(void) const { return m_formatSpecifier; }
        inline const FormatSpecifierValueResolver& resolver(void) const { return m_resolver; }
        inline bool operator==(const char* formatSpecifier) {
            return strcmp(m_formatSpecifier, formatSpecifier) == 0;
        }
    
    private:
        const char* m_formatSpecifier;
        FormatSpecifierValueResolver m_resolver;
    };
    /// @brief Represents single configuration that has representing level, configuration type and a string based value.
    ///
    /// @detail String based value means any value either its boolean, integer or string itself, it will be embedded inside quotes
    /// and will be parsed later.
    ///
    /// Consider some examples below:
    ///   * el::Configuration confEnabledInfo(el::Level::Info, el::ConfigurationType::Enabled, "true");
    ///   * el::Configuration confMaxLogFileSizeInfo(el::Level::Info, el::ConfigurationType::MaxLogFileSize, "2048");
    ///   * el::Configuration confFilenameInfo(el::Level::Info, el::ConfigurationType::Filename, "/var/log/my.log");
    class Configuration : public Loggable {
    public:
        Configuration(const Configuration& c) :
                m_level(c.m_level),
                m_configurationType(c.m_configurationType),
                m_value(c.m_value) {
        }
    
        Configuration& operator=(const Configuration& c) {
            m_level = c.m_level;
            m_configurationType = c.m_configurationType;
            m_value = c.m_value;
            return *this;
        }
    
        virtual ~Configuration(void) {
        }
    
        /// @brief Full constructor used to sets value of configuration
        Configuration(Level level, ConfigurationType configurationType, const std::string& value) :
            m_level(level),
            m_configurationType(configurationType),
            m_value(value) {
        }
    
        /// @brief Gets level of current configuration
        inline Level level(void) const {
            return m_level;
        }
    
        /// @brief Gets configuration type of current configuration
        inline ConfigurationType configurationType(void) const {
            return m_configurationType;
        }
    
        /// @brief Gets string based configuration value
        inline const std::string& value(void) const {
            return m_value;
        }
    
        /// @brief Set string based configuration value
        /// @param value Value to set. Values have to be std::string; For boolean values use "true", "false", for any integral values
        ///        use them in quotes. They will be parsed when configuring
        inline void setValue(const std::string& value) {
            m_value = value;
        }
    
        virtual inline void log(el::base::type::ostream_t& os) const {
            os << LevelHelper::convertToString(m_level)
                << ELPP_LITERAL(" ") << ConfigurationTypeHelper::convertToString(m_configurationType)
                << ELPP_LITERAL(" = ") << m_value.c_str();
        }
    
        /// @brief Used to find configuration from configuration (pointers) repository. Avoid using it.
        class Predicate {
        public:
            Predicate(Level level, ConfigurationType configurationType) :
                m_level(level),
                m_configurationType(configurationType) {
            }
    
            inline bool operator()(const Configuration* conf) const {
                return ((conf != nullptr) && (conf->level() == m_level) && (conf->configurationType() == m_configurationType));
            }
    
        private:
            Level m_level;
            ConfigurationType m_configurationType;
        };
    
    private:
        Level m_level;
        ConfigurationType m_configurationType;
        std::string m_value;
    };
    
    /// @brief Thread-safe Configuration repository
    ///
    /// @detail This repository represents configurations for all the levels and configuration type mapped to a value.
    class Configurations : public base::utils::RegistryWithPred<Configuration, Configuration::Predicate> {
    public:
        /// @brief Default constructor with empty repository
        Configurations(void) :
                m_configurationFile(std::string()),
                m_isFromFile(false) {
        }
    
        /// @brief Constructor used to set configurations using configuration file.
        /// @param configurationFile Full path to configuration file
        /// @param useDefaultsForRemaining Lets you set the remaining configurations to default.
        /// @param base If provided, this configuration will be based off existing repository that this argument is pointing to.
        /// @see parseFromFile(const std::string&, Configurations* base)
        /// @see setRemainingToDefault()
        Configurations(const std::string& configurationFile, bool useDefaultsForRemaining = true, Configurations* base = nullptr) :
                m_configurationFile(configurationFile),
                m_isFromFile(false) {
            parseFromFile(configurationFile, base);
            if (useDefaultsForRemaining) {
                setRemainingToDefault();
            }
        }
    
        virtual ~Configurations(void) {
        }
    
        /// @brief Parses configuration from file.
        /// @param configurationFile Full path to configuration file
        /// @param base Configurations to base new configuration repository off. This value is used when you want to use
        ///        existing Configurations to base all the values and then set rest of configuration via configuration file.
        /// @return True if successfully parsed, false otherwise. You may define '_ELPP_DEBUG_ASSERT_FAILURE' to make sure you
        ///         do not proceed without successful parse.
        inline bool parseFromFile(const std::string& configurationFile, Configurations* base = nullptr) {
            bool assertionPassed = false;
            ELPP_ASSERT((assertionPassed = base::utils::File::pathExists(configurationFile.c_str(), true)),
                    "Configuration file [" << configurationFile << "] does not exist!");
            if (!assertionPassed) {
                return false;
            }
            bool success = Parser::parseFromFile(configurationFile, this, base);
            m_isFromFile = success;
            return success;
        }
    
        /// @brief Parse configurations from configuration string.
        ///
        /// @detail This configuration string has same syntax as configuration file contents. Make sure all the necessary
        /// new line characters are provided.
        /// @param base Configurations to base new configuration repository off. This value is used when you want to use
        ///        existing Configurations to base all the values and then set rest of configuration via configuration text.
        /// @return True if successfully parsed, false otherwise. You may define '_ELPP_DEBUG_ASSERT_FAILURE' to make sure you
        ///         do not proceed without successful parse.
        inline bool parseFromText(const std::string& configurationsString, Configurations* base = nullptr) {
            bool success = Parser::parseFromText(configurationsString, this, base);
            if (success) {
                m_isFromFile = false;
            }
            return success;
        }
    
        /// @brief Sets configuration based-off an existing configurations.
        /// @param base Pointer to existing configurations.
        inline void setFromBase(Configurations* base) {
            if (base == nullptr || base == this) {
                return;
            }
            base::threading::ScopedLock scopedLock(base->lock());
            for (Configuration*& conf : base->list()) {
                set(conf);
            }
        }
    
        /// @brief Determines whether or not specified configuration type exists in the repository.
        ///
        /// @detail Returns as soon as first level is found.
        /// @param configurationType Type of configuration to check existence for.
        bool hasConfiguration(ConfigurationType configurationType) {
            base::type::EnumType lIndex = LevelHelper::kMinValid;
            bool result = false;
            LevelHelper::forEachLevel(&lIndex, [&](void) -> bool {
                if (hasConfiguration(LevelHelper::castFromInt(lIndex), configurationType)) {
                    result = true;
                }
                return result;
            });
            return result;
        }
    
        /// @brief Determines whether or not specified configuration type exists for specified level
        /// @param level Level to check
        /// @param configurationType Type of configuration to check existence for.
        inline bool hasConfiguration(Level level, ConfigurationType configurationType) {
            base::threading::ScopedLock scopedLock(lock());
    #if _ELPP_COMPILER_INTEL
            // We cant specify template types here, Intel C++ throws compilation error
            // "error: type name is not allowed"
            return RegistryWithPred::get(level, configurationType) != nullptr;
    #else
            return RegistryWithPred<Configuration, Configuration::Predicate>::get(level, configurationType) != nullptr;
    #endif  // _ELPP_COMPILER_INTEL
        }
    
        /// @brief Sets value of configuration for specified level.
        ///
        /// @detail Any existing configuration for specified level will be replaced. Also note that configuration types
        /// ConfigurationType::MillisecondsWidth and ConfigurationType::PerformanceTracking will be ignored if not set for
        /// Level::Global because these configurations are not dependant on level.
        /// @param level Level to set configuration for (el::Level).
        /// @param configurationType Type of configuration (el::ConfigurationType)
        /// @param value A string based value. Regardless of what the data type of configuration is, it will always be string
        /// from users' point of view. This is then parsed later to be used internally.
        /// @see Configuration::setValue(const std::string& value)
        /// @see el::Level
        /// @see el::ConfigurationType
        inline void set(Level level, ConfigurationType configurationType, const std::string& value) {
            base::threading::ScopedLock scopedLock(lock());
            unsafeSet(level, configurationType, value);  // This is not unsafe anymore as we have locked mutex
            if (level == Level::Global) {
                unsafeSetGlobally(configurationType, value, false);  // Again this is not unsafe either
            }
        }
    
        /// @brief Sets single configuration based on other single configuration.
        /// @see set(Level level, ConfigurationType configurationType, const std::string& value)
        inline void set(Configuration* conf) {
            if (conf == nullptr) {
                return;
            }
            set(conf->level(), conf->configurationType(), conf->value());
        }
    
        inline Configuration* get(Level level, ConfigurationType configurationType) {
            base::threading::ScopedLock scopedLock(lock());
            return RegistryWithPred<Configuration, Configuration::Predicate>::get(level, configurationType);
        }
    
        /// @brief Sets configuration for all levels.
        /// @param configurationType Type of configuration
        /// @param value String based value
        /// @see Configurations::set(Level level, ConfigurationType configurationType, const std::string& value)
        inline void setGlobally(ConfigurationType configurationType, const std::string& value) {
            setGlobally(configurationType, value, false);
        }
    
        /// @brief Clears repository so that all the configurations are unset
        inline void clear(void) {
            base::threading::ScopedLock scopedLock(lock());
            unregisterAll();
        }
    
        /// @brief Gets configuration file used in parsing this configurations.
        ///
        /// @detail If this repository was set manually or by text this returns empty string.
        inline const std::string& configurationFile(void) const {
            return m_configurationFile;
        }
    
        /// @brief Sets configurations to "factory based" configurations.
        void setToDefault(void) {
            setGlobally(ConfigurationType::Enabled, std::string("true"), true);
    #if !defined(_ELPP_NO_DEFAULT_LOG_FILE)
            setGlobally(ConfigurationType::Filename, std::string(base::consts::kDefaultLogFile), true);
    #else
            _ELPP_UNUSED(base::consts::kDefaultLogFile);
    #endif  // !defined(_ELPP_NO_DEFAULT_LOG_FILE)
            setGlobally(ConfigurationType::ToFile, std::string("true"), true);
            setGlobally(ConfigurationType::ToStandardOutput, std::string("true"), true);
            setGlobally(ConfigurationType::MillisecondsWidth, std::string("3"), true);
            setGlobally(ConfigurationType::PerformanceTracking, std::string("true"), true);
            setGlobally(ConfigurationType::MaxLogFileSize, std::string("0"), true);
            setGlobally(ConfigurationType::LogFlushThreshold, std::string("0"), true);
    
            setGlobally(ConfigurationType::Format, std::string("%datetime %level [%logger] %msg"), true);
            set(Level::Debug, ConfigurationType::Format, std::string("%datetime %level [%logger] [%user@%host] [%func] [%loc] %msg"));
            // INFO and WARNING are set to default by Level::Global
            set(Level::Error, ConfigurationType::Format, std::string("%datetime %level [%logger] %msg"));
            set(Level::Fatal, ConfigurationType::Format, std::string("%datetime %level [%logger] %msg"));
            set(Level::Verbose, ConfigurationType::Format, std::string("%datetime %level-%vlevel [%logger] %msg"));
            set(Level::Trace, ConfigurationType::Format, std::string("%datetime %level [%logger] [%func] [%loc] %msg"));
        }
    
        /// @brief Lets you set the remaining configurations to default.
        ///
        /// @detail By remaining, it means that the level/type a configuration does not exist for.
        /// This function is useful when you want to minimize chances of failures, e.g, if you have a configuration file that sets
        /// configuration for all the configurations except for Enabled or not, we use this so that ENABLED is set to default i.e,
        /// true. If you dont do this explicitley (either by calling this function or by using second param in Constructor
        /// and try to access a value, an error is thrown
        void setRemainingToDefault(void) {
            base::threading::ScopedLock scopedLock(lock());
            unsafeSetIfNotExist(Level::Global, ConfigurationType::Enabled, std::string("true"));
    #if !defined(_ELPP_NO_DEFAULT_LOG_FILE)
            unsafeSetIfNotExist(Level::Global, ConfigurationType::Filename, std::string(base::consts::kDefaultLogFile));
    #endif  // !defined(_ELPP_NO_DEFAULT_LOG_FILE)
            unsafeSetIfNotExist(Level::Global, ConfigurationType::ToFile, std::string("true"));
            unsafeSetIfNotExist(Level::Global, ConfigurationType::ToStandardOutput, std::string("true"));
            unsafeSetIfNotExist(Level::Global, ConfigurationType::MillisecondsWidth, std::string("3"));
            unsafeSetIfNotExist(Level::Global, ConfigurationType::PerformanceTracking, std::string("true"));
            unsafeSetIfNotExist(Level::Global, ConfigurationType::MaxLogFileSize, std::string("0"));
            unsafeSetIfNotExist(Level::Global, ConfigurationType::Format, std::string("%datetime %level [%logger] %msg"));
            unsafeSetIfNotExist(Level::Debug, ConfigurationType::Format, 
                std::string("%datetime %level [%logger] [%user@%host] [%func] [%loc] %msg"));
            // INFO and WARNING are set to default by Level::Global
            unsafeSetIfNotExist(Level::Error, ConfigurationType::Format, std::string("%datetime %level [%logger] %msg"));
            unsafeSetIfNotExist(Level::Fatal, ConfigurationType::Format, std::string("%datetime %level [%logger] %msg"));
            unsafeSetIfNotExist(Level::Verbose, ConfigurationType::Format, std::string("%datetime %level-%vlevel [%logger] %msg"));
            unsafeSetIfNotExist(Level::Trace, ConfigurationType::Format, std::string("%datetime %level [%logger] [%func] [%loc] %msg"));
        }
    
        /// @brief Parser used internally to parse configurations from file or text.
        ///
        /// @detail This class makes use of base::utils::Str.
        /// You should not need this unless you are working on some tool for Easylogging++
        class Parser : base::StaticClass {
        public:
            /// @brief Parses configuration from file.
            /// @param configurationFile Full path to configuration file
            /// @param sender Sender configurations pointer. Usually 'this' is used from calling class
            /// @param base Configurations to base new configuration repository off. This value is used when you want to use
            ///        existing Configurations to base all the values and then set rest of configuration via configuration file.
            /// @return True if successfully parsed, false otherwise. You may define '_STOP_ON_FIRST_ELPP_ASSERTION' to make sure you
            ///         do not proceed without successful parse.
            static bool parseFromFile(const std::string& configurationFile, Configurations* sender, Configurations* base = nullptr) {
                sender->setFromBase(base);
                std::ifstream fileStream_(configurationFile.c_str(), std::ifstream::in);
                ELPP_ASSERT(fileStream_.is_open(), "Unable to open configuration file [" << configurationFile << "] for parsing.");
                bool parsedSuccessfully = false;
                std::string line = std::string();
                Level currLevel = Level::Unknown;
                std::string currConfigStr = std::string();
                std::string currLevelStr = std::string();
                while (fileStream_.good()) {
                    std::getline(fileStream_, line);
                    parsedSuccessfully = parseLine(&line, &currConfigStr, &currLevelStr, &currLevel, sender);
                    ELPP_ASSERT(parsedSuccessfully, "Unable to parse configuration line: " << line);
                }
                return parsedSuccessfully;
            }
    
            /// @brief Parse configurations from configuration string.
            ///
            /// @detail This configuration string has same syntax as configuration file contents. Make sure all the necessary
            /// new line characters are provided. You may define '_STOP_ON_FIRST_ELPP_ASSERTION' to make sure you
            /// do not proceed without successful parse (This is recommended)
            /// @param configurationsString
            /// @param sender Sender configurations pointer. Usually 'this' is used from calling class
            /// @param base Configurations to base new configuration repository off. This value is used when you want to use
            ///        existing Configurations to base all the values and then set rest of configuration via configuration text.
            /// @return True if successfully parsed, false otherwise.
            static bool parseFromText(const std::string& configurationsString, Configurations* sender, Configurations* base = nullptr) {
                sender->setFromBase(base);
                bool parsedSuccessfully = false;
                std::stringstream ss(configurationsString);
                std::string line = std::string();
                Level currLevel = Level::Unknown;
                std::string currConfigStr = std::string();
                std::string currLevelStr = std::string();
                while (std::getline(ss, line)) {
                    parsedSuccessfully = parseLine(&line, &currConfigStr, &currLevelStr, &currLevel, sender);
                    ELPP_ASSERT(parsedSuccessfully, "Unable to parse configuration line: " << line);
                }
                return parsedSuccessfully;
            }
    
        private:
            friend class el::Loggers;
            static void ignoreComments(std::string* line) {
                std::size_t foundAt = 0;
                std::size_t quotesStart = line->find("\"");
                std::size_t quotesEnd = std::string::npos;
                if (quotesStart != std::string::npos) {
                    quotesEnd = line->find("\"", quotesStart + 1);
                    while (quotesEnd != std::string::npos && line->at(quotesEnd - 1) == '\\') {
                        // Do not erase slash yet - we will erase it in parseLine(..) while loop
                        quotesEnd = line->find("\"", quotesEnd + 2);
                    }
                }
                if ((foundAt = line->find(base::consts::kConfigurationComment)) != std::string::npos) {
                    if (foundAt < quotesEnd) {
                        foundAt = line->find(base::consts::kConfigurationComment, quotesEnd + 1);
                    }
                    *line = line->substr(0, foundAt);
                }
            }
            static inline bool isLevel(const std::string& line) {
                return base::utils::Str::startsWith(line, std::string(base::consts::kConfigurationLevel));
            }
    
            static inline bool isComment(const std::string& line) {
                return base::utils::Str::startsWith(line, std::string(base::consts::kConfigurationComment));
            }
    
            static inline bool isConfig(const std::string& line) {
                std::size_t assignment = line.find('=');
                return line != "" &&
                        (line[0] >= 65 || line[0] <= 90 || line[0] >= 97 || line[0] <= 122) &&
                        (assignment != std::string::npos) &&
                        (line.size() > assignment);
            }
    
            static bool parseLine(std::string* line, std::string* currConfigStr, std::string* currLevelStr, Level* currLevel, Configurations* conf) {
                ConfigurationType currConfig = ConfigurationType::Unknown;
                std::string currValue = std::string();
                *line = base::utils::Str::trim(*line);
                if (isComment(*line)) return true;
                ignoreComments(line);
                *line = base::utils::Str::trim(*line);
                if (line->empty()) {
                    // Comment ignored
                    return true;
                }
                if (isLevel(*line)) {
                    if (line->size() <= 2) {
                        return true;
                    }
                    *currLevelStr = line->substr(1, line->size() - 2);
                    *currLevelStr = base::utils::Str::toUpper(*currLevelStr);
                    *currLevelStr = base::utils::Str::trim(*currLevelStr);
                    *currLevel = LevelHelper::convertFromString(currLevelStr->c_str());
                    return true;
                }
                if (isConfig(*line)) {
                    std::size_t assignment = line->find('=');
                    *currConfigStr = line->substr(0, assignment);
                    *currConfigStr = base::utils::Str::toUpper(*currConfigStr);
                    *currConfigStr = base::utils::Str::trim(*currConfigStr);
                    currConfig = ConfigurationTypeHelper::convertFromString(currConfigStr->c_str());
                    currValue = line->substr(assignment + 1);
                    currValue = base::utils::Str::trim(currValue);
                    std::size_t quotesStart = currValue.find("\"", 0);
                    std::size_t quotesEnd = std::string::npos;
                    if (quotesStart != std::string::npos) {
                        quotesEnd = currValue.find("\"", quotesStart + 1);
                        while (quotesEnd != std::string::npos && currValue.at(quotesEnd - 1) == '\\') {
                            currValue = currValue.erase(quotesEnd - 1, 1);
                            quotesEnd = currValue.find("\"", quotesEnd + 2);
                        }
                    }
                    if (quotesStart != std::string::npos && quotesEnd != std::string::npos) {
                        // Quote provided - check and strip if valid
                        ELPP_ASSERT((quotesStart < quotesEnd), "Configuration error - No ending quote found in [" 
                            << currConfigStr << "]");
                        ELPP_ASSERT((quotesStart + 1 != quotesEnd), "Empty configuration value for [" << currConfigStr << "]");
                        if ((quotesStart != quotesEnd) && (quotesStart + 1 != quotesEnd)) {
                            // Explicit check in case if assertion is disabled
                            currValue = currValue.substr(quotesStart + 1, quotesEnd - 1);
                        }
                    }
                }
                ELPP_ASSERT(*currLevel != Level::Unknown, "Unrecognized severity level [" << *currLevelStr << "]");
                ELPP_ASSERT(currConfig != ConfigurationType::Unknown, "Unrecognized configuration [" << *currConfigStr << "]");
                if (*currLevel == Level::Unknown || currConfig == ConfigurationType::Unknown) {
                    return false;  // unrecognizable level or config
                }
                conf->set(*currLevel, currConfig, currValue);
                return true;
            }
        };
    
    private:
        std::string m_configurationFile;
        bool m_isFromFile;
        friend class el::Loggers;
    
        /// @brief Unsafely sets configuration if does not already exist
        void unsafeSetIfNotExist(Level level, ConfigurationType configurationType, const std::string& value) {
            Configuration* conf = RegistryWithPred<Configuration, Configuration::Predicate>::get(level, configurationType);
            if (conf == nullptr) {
                unsafeSet(level, configurationType, value);
            }
        }
    
        /// @brief Thread unsafe set
        void unsafeSet(Level level, ConfigurationType configurationType, const std::string& value) {
            Configuration* conf = RegistryWithPred<Configuration, Configuration::Predicate>::get(level, configurationType);
            if (conf == nullptr) {
                registerNew(new Configuration(level, configurationType, value));
            } else {
                conf->setValue(value);
            }
            if (level == Level::Global) {
                unsafeSetGlobally(configurationType, value, false);
            }
        }
    
        /// @brief Sets configurations for all levels including Level::Global if includeGlobalLevel is true
        /// @see Configurations::setGlobally(ConfigurationType configurationType, const std::string& value)
        void setGlobally(ConfigurationType configurationType, const std::string& value, bool includeGlobalLevel) {
            if (includeGlobalLevel) {
                set(Level::Global, configurationType, value);
            }
            base::type::EnumType lIndex = LevelHelper::kMinValid;
            LevelHelper::forEachLevel(&lIndex, [&](void) -> bool {
                set(LevelHelper::castFromInt(lIndex), configurationType, value);
                return false;  // Do not break lambda function yet as we need to set all levels regardless
            });
        }
    
        /// @brief Sets configurations (Unsafely) for all levels including Level::Global if includeGlobalLevel is true
        /// @see Configurations::setGlobally(ConfigurationType configurationType, const std::string& value)
        void unsafeSetGlobally(ConfigurationType configurationType, const std::string& value, bool includeGlobalLevel) {
            if (includeGlobalLevel) {
                unsafeSet(Level::Global, configurationType, value);
            }
            base::type::EnumType lIndex = LevelHelper::kMinValid;
            LevelHelper::forEachLevel(&lIndex, [&](void) -> bool  {
                unsafeSet(LevelHelper::castFromInt(lIndex), configurationType, value);
                return false;  // Do not break lambda function yet as we need to set all levels regardless
            });
        }
    };
    
    namespace base {
    typedef std::shared_ptr<base::type::fstream_t> FileStreamPtr;
    typedef std::map<std::string, FileStreamPtr> LogStreamsReferenceMap;
    /// @brief Configurations with data types.
    ///
    /// @detail el::Configurations have string based values. This is whats used internally in order to read correct configurations.
    /// This is to perform faster while writing logs using correct configurations.
    ///
    /// This is thread safe and final class containing non-virtual destructor (means nothing should inherit this class)
    class TypedConfigurations : public base::threading::ThreadSafe {
    public:
        /// @brief Constructor to initialize (construct) the object off el::Configurations
        /// @param configurations Configurations pointer/reference to base this typed configurations off.
        /// @param logStreamsReference Use ELPP->registeredLoggers()->logStreamsReference()
        TypedConfigurations(Configurations* configurations, base::LogStreamsReferenceMap* logStreamsReference) {
            m_configurations = configurations;
            m_logStreamsReference = logStreamsReference;
            build(m_configurations);
        }
    
        TypedConfigurations(const TypedConfigurations& other) {
            this->m_configurations = other.m_configurations;
            this->m_logStreamsReference = other.m_logStreamsReference;
            build(m_configurations);
        }
    
        virtual ~TypedConfigurations(void) {
        }
    
        const Configurations* configurations(void) const {
            return m_configurations;
        }
    
        inline bool enabled(Level level) {
            return getConfigByVal<bool>(level, &m_enabledMap, "enabled");
        }
    
        inline bool toFile(Level level) {
            return getConfigByVal<bool>(level, &m_toFileMap, "toFile");
        }
    
        inline const std::string& filename(Level level) {
            return getConfigByRef<std::string>(level, &m_filenameMap, "filename");
        }
    
        inline bool toStandardOutput(Level level) {
            return getConfigByVal<bool>(level, &m_toStandardOutputMap, "toStandardOutput");
        }
    
        inline const base::LogFormat& logFormat(Level level) {
            return getConfigByRef<base::LogFormat>(level, &m_logFormatMap, "logFormat");
        }
    
        inline const base::MillisecondsWidth& millisecondsWidth(Level level = Level::Global) {
            return getConfigByRef<base::MillisecondsWidth>(level, &m_millisecondsWidthMap, "millisecondsWidth");
        }
    
        inline bool performanceTracking(Level level = Level::Global) {
            return getConfigByVal<bool>(level, &m_performanceTrackingMap, "performanceTracking");
        }
    
        inline base::type::fstream_t* fileStream(Level level) {
            return getConfigByRef<base::FileStreamPtr>(level, &m_fileStreamMap, "fileStream").get();
        }
    
        inline std::size_t maxLogFileSize(Level level) {
            return getConfigByVal<std::size_t>(level, &m_maxLogFileSizeMap, "maxLogFileSize");
        }
    
        inline std::size_t logFlushThreshold(Level level) {
            return getConfigByVal<std::size_t>(level, &m_logFlushThresholdMap, "logFlushThreshold");
        }
    
    private:
        Configurations* m_configurations;
        std::map<Level, bool> m_enabledMap;
        std::map<Level, bool> m_toFileMap;
        std::map<Level, std::string> m_filenameMap;
        std::map<Level, bool> m_toStandardOutputMap;
        std::map<Level, base::LogFormat> m_logFormatMap;
        std::map<Level, base::MillisecondsWidth> m_millisecondsWidthMap;
        std::map<Level, bool> m_performanceTrackingMap;
        std::map<Level, base::FileStreamPtr> m_fileStreamMap;
        std::map<Level, std::size_t> m_maxLogFileSizeMap;
        std::map<Level, std::size_t> m_logFlushThresholdMap;
        base::LogStreamsReferenceMap* m_logStreamsReference;
    
        friend class el::Helpers;
        friend class el::base::MessageBuilder;
        friend class el::base::Writer;
        friend class el::base::DefaultLogDispatchCallback;
        friend class el::base::LogDispatcher;
    
        template <typename Conf_T>
        inline Conf_T getConfigByVal(Level level, const std::map<Level, Conf_T>* confMap, const char* confName) {
            base::threading::ScopedLock scopedLock(lock());
            return unsafeGetConfigByVal(level, confMap, confName);  // This is not unsafe anymore - mutex locked in scope
        }
    
        template <typename Conf_T>
        inline Conf_T& getConfigByRef(Level level, std::map<Level, Conf_T>* confMap, const char* confName) {
            base::threading::ScopedLock scopedLock(lock());
            return unsafeGetConfigByRef(level, confMap, confName);  // This is not unsafe anymore - mutex locked in scope
        }
    
        template <typename Conf_T>
        inline Conf_T unsafeGetConfigByVal(Level level, const std::map<Level, Conf_T>* confMap, const char* confName) {
            _ELPP_UNUSED(confName);
            typename std::map<Level, Conf_T>::const_iterator it = confMap->find(level);
            if (it == confMap->end()) {
                try {
                    return confMap->at(Level::Global);
                } catch (...) {
                    ELPP_INTERNAL_ERROR("Unable to get configuration [" << confName << "] for level [" 
                        << LevelHelper::convertToString(level) << "]"
                            << std::endl << "Please ensure you have properly configured logger.", false);
                    return Conf_T();
                }
            }
            return it->second;
        }
    
        template <typename Conf_T>
        inline Conf_T& unsafeGetConfigByRef(Level level, std::map<Level, Conf_T>* confMap, const char* confName) {
            _ELPP_UNUSED(confName);
            typename std::map<Level, Conf_T>::iterator it = confMap->find(level);
            if (it == confMap->end()) {
                try {
                    return confMap->at(Level::Global);
                } catch (...) {
                    ELPP_INTERNAL_ERROR("Unable to get configuration [" << confName << "] for level [" 
                        << LevelHelper::convertToString(level) << "]"
                            << std::endl << "Please ensure you have properly configured logger.", false);
                }
            }
            return it->second;
        }
    
        template <typename Conf_T>
        void setValue(Level level, const Conf_T& value, std::map<Level, Conf_T>* confMap, bool includeGlobalLevel = true) {
            // If map is empty and we are allowed to add into generic level (Level::Global), do it!
            if (confMap->empty() && includeGlobalLevel) {
                confMap->insert(std::make_pair(Level::Global, value));
                return;
            }
            // If same value exist in generic level already, dont add it to explicit level
            typename std::map<Level, Conf_T>::iterator it = confMap->find(Level::Global);
            if (it != confMap->end() && it->second == value) {
                return;
            }
            // Now make sure we dont double up values if we really need to add it to explicit level
            it = confMap->find(level);
            if (it == confMap->end()) {
                // Value not found for level, add new
                confMap->insert(std::make_pair(level, value));
            } else {
                // Value found, just update value
                confMap->at(level) = value;
            }
        }
    
        void build(Configurations* configurations) {
            base::threading::ScopedLock scopedLock(lock());
            auto getBool = [] (std::string boolStr) -> bool {  // Pass by value for trimming
                base::utils::Str::trim(boolStr);
                return (boolStr == "TRUE" || boolStr == "true" || boolStr == "1");
            };
            std::vector<Configuration*> withFileSizeLimit;
            for (Configurations::const_iterator it = configurations->begin(); it != configurations->end(); ++it) {
                Configuration* conf = *it;
                // We cannot use switch on strong enums because Intel C++ dont support them yet
                if (conf->configurationType() == ConfigurationType::Enabled) {
                    setValue(conf->level(), getBool(conf->value()), &m_enabledMap);
                } else if (conf->configurationType() == ConfigurationType::ToFile) {
                    setValue(conf->level(), getBool(conf->value()), &m_toFileMap);
                } else if (conf->configurationType() == ConfigurationType::ToStandardOutput) {
                    setValue(conf->level(), getBool(conf->value()), &m_toStandardOutputMap);
                } else if (conf->configurationType() == ConfigurationType::Filename) {
                // We do not yet configure filename but we will configure in another
                // loop. This is because if file cannot be created, we will force ToFile
                // to be false. Because configuring logger is not necessarily performance
                // sensative operation, we can live with another loop; (by the way this loop
                // is not very heavy either)
                } else if (conf->configurationType() == ConfigurationType::Format) {
                    setValue(conf->level(), base::LogFormat(conf->level(), 
                        base::type::string_t(conf->value().begin(), conf->value().end())), &m_logFormatMap);
                } else if (conf->configurationType() == ConfigurationType::MillisecondsWidth) {
                    setValue(Level::Global, 
                        base::MillisecondsWidth(static_cast<int>(getULong(conf->value()))), &m_millisecondsWidthMap);
                } else if (conf->configurationType() == ConfigurationType::PerformanceTracking) {
                    setValue(Level::Global, getBool(conf->value()), &m_performanceTrackingMap);
                } else if (conf->configurationType() == ConfigurationType::MaxLogFileSize) {
                    setValue(conf->level(), static_cast<std::size_t>(getULong(conf->value())), &m_maxLogFileSizeMap);
    #if !defined(_ELPP_NO_DEFAULT_LOG_FILE)
                    withFileSizeLimit.push_back(conf);
    #endif  // !defined(_ELPP_NO_DEFAULT_LOG_FILE)
                } else if (conf->configurationType() == ConfigurationType::LogFlushThreshold) {