C ++ log class – Code Review Stack Exchange

I have created a simple class C ++ logging. It generates different levels of log and adjusts the output color accordingly. I am interested in tips to improve my coding style.

I am particularly concerned about my use of #defineis in the bottom of Logger.hpp. I was unable to find another way to pass __FILE__ and __LINE__ to function (apart from doing it manually of course), but I would not be surprised if this approach is a bad practice.

ConsoleColer.hpp

#include 

namespace AGE
{
    enum class BackgroundColor : int
    {
        Black   = 0,
        Blue    = 16,
        Green   = 32,
        Cyan    = 48,
        Red     = 64,
        Magenta = 80,
        Brown   = 96,
        White   = 112,
    };

    enum class ForegroundColor : int
    {
        Black = 0,
        Blue,
        Green,
        Cyan,
        Red,
        Magenta,
        Brown,
        White,
        Gray,
        Intense_blue,
        Intense_green,
        Intense_Cyan,
        Intense_red,
        Intense_magenta,
        Yellow,
        Intense_white,
    };

    // Used to combine background and foreground colors
    WORD operator &(const BackgroundColor& left, const ForegroundColor& right)
    {
        return static_cast(static_cast(left) + static_cast(right));
    }
}

LoggerSettings.hpp

#pragma once

namespace AGE
{
    struct LoggerSettings
    {
        explicit LoggerSettings(bool should_print_level = true, bool should_print_file_and_line = true,
                                bool should_print_color = true, bool should_print_time = true) :
        print_level(should_print_color),
        print_file_and_line(should_print_file_and_line),
        print_color(should_print_color),
        print_time(should_print_time)
        {}

        // TODO add ability to display time in Logger.hpp/cpp
        bool print_level;
        bool print_file_and_line;
        bool print_color;
        bool print_time;
    };
}

Logger.hpp

#pragma once

#include "LoggerSettings.hpp"

#include 
#include 

namespace AGE
{
    enum class LogLevel
    {
        Trace,
        Info,
        Warn,
        Error,
        Fatal
    };



    class Logger
    {
    public:
        Logger();

        void set_log_level(const LogLevel level);

        LoggerSettings& get_settings();

        void explicit_trace(const std::string_view message, const char* file, int line);
        void explicit_info (const std::string_view message, const char* file, int line);
        void explicit_warn (const std::string_view message, const char* file, int line);
        void explicit_error(const std::string_view message, const char* file, int line);
        void explicit_fatal(const std::string_view message, const char* file, int line);

    private:
        void log(const LogLevel level, const std::string_view message, const char* file, int line);

        WORD get_color(const LogLevel level);
        std::string get_error_string(const LogLevel level);
        std::string get_file_name(const char* filepath);

        const HANDLE m_console_handle;
        LogLevel     m_current_log_level;
        LoggerSettings m_settings;
    };
}

#define trace(message)  AGE::Logger::explicit_trace(message, __FILE__, __LINE__)
#define info(message)   AGE::Logger::explicit_info(message, __FILE__, __LINE__)
#define warn(message)   AGE::Logger::explicit_warn(message, __FILE__, __LINE__)
#define error(message)  AGE::Logger::explicit_error(message, __FILE__, __LINE__)
#define fatal(message)  AGE::Logger::explicit_fatal(message, __FILE__, __LINE__)

Logger.cpp

#include "Logger.hpp"

#include "ConsoleColor.hpp"

#include 

#include 

namespace AGE
{
    Logger::Logger() :
    m_console_handle   (GetStdHandle(STD_OUTPUT_HANDLE)),
    m_current_log_level(LogLevel::Trace)
    {
        m_settings = LoggerSettings();
    }



    void Logger::set_log_level(LogLevel level)
    {
        m_current_log_level = level;
    }



    LoggerSettings& Logger::get_settings()
    {
        return m_settings;
    }



    void Logger::explicit_trace(const std::string_view message, const char* file, int line)
    {
        if (m_current_log_level > LogLevel::Trace)
        {
            return;
        }

        log(LogLevel::Trace, message, file, line);
    }



    void Logger::explicit_info(const std::string_view message, const char* file, int line)
    {
        if (m_current_log_level > LogLevel::Info)
        {
            return;
        }

        log(LogLevel::Info, message, file, line);
    }



    void Logger::explicit_warn(const std::string_view message, const char* file, int line)
    {
        if (m_current_log_level > LogLevel::Warn)
        {
            return;
        }

        log(LogLevel::Warn, message, file, line);
    }



    void Logger::explicit_error(const std::string_view message, const char* file, int line)
    {
        if (m_current_log_level > LogLevel::Error)
        {
            return;
        }

        log(LogLevel::Error, message, file, line);
    }



    void Logger::explicit_fatal(const std::string_view message, const char* file, int line)
    {
        if (m_current_log_level > LogLevel::Fatal)
        {
            return;
        }

        log(LogLevel::Fatal, message, file, line);
    }



    void Logger::log(const LogLevel level, const std::string_view message, const char* file, int line)
    {

        if (m_settings.print_color)
        {
            WORD color = get_color(level);
            SetConsoleTextAttribute(m_console_handle, color);
        }
        if (m_settings.print_level)
        {
            std::cout << "(" << get_error_string(level) << ")";
        }
        if (m_settings.print_file_and_line)
        {
            std::cout << "(" << "In " << get_file_name(file) << " at line " << line << ") ";
        }

        std::cout << message << std::endl;
        SetConsoleTextAttribute(m_console_handle, BackgroundColor::Black & ForegroundColor::White);
    }



    WORD Logger::get_color(const LogLevel level)
    {
        switch (level)
        {
        default:
            return BackgroundColor::Black & ForegroundColor::White;
            break;

        case LogLevel::Trace:
            return BackgroundColor::Black & ForegroundColor::Intense_white;
            break;

        case LogLevel::Info:
            return BackgroundColor::Black & ForegroundColor::Intense_green;
            break;

        case LogLevel::Warn:
            return BackgroundColor::Black & ForegroundColor::Intense_red;
            break;

        case LogLevel::Error:
            return BackgroundColor::Black & ForegroundColor::Intense_Cyan;
            break;

        case LogLevel::Fatal:
            return BackgroundColor::Black & ForegroundColor::Intense_magenta;
            break;
        }
    }



    std::string Logger::get_error_string(const LogLevel level)
    {
        switch (level)
        {
        default:
            return std::string();
            break;

        case LogLevel::Trace:
            return std::string("Trace");
            break;

        case LogLevel::Info:
            return std::string("Info");
            break;

        case LogLevel::Warn:
            return std::string("Warning");
            break;

        case LogLevel::Error:
            return std::string("Error");
            break;

        case LogLevel::Fatal:
            return std::string("Fatal");
            break;
        }
    }



    std::string Logger::get_file_name(const char* filepath)
    {
        std::string path = std::string(filepath);

        int index = 0;
        for (int i = static_cast(path.size()) - 1; i > 0; i--)
        {
            if (path.at(i) == '\')
            {
                index = i;
                break;
            }
        }

        // For some reason the compiler complains if i dont cast to 64bit int
        return std::string(path, static_cast(index) + 1, path.size() - 1);
    }
}

stopovers – Log in to Düsseldorf (first time)

On November 1st, I will have my first flight (actually) to Düsseldorf. For this reason, I am pretty stressed and would like to ask a few questions. I will travel with a hand baggage that I will bring in the cabin and I am a citizen of the EU (Italian). My flight is on a single booking, with Eurowings.

EW9827 09:15 Milan Malpensa – 10:50 Dusseldorf

60 minutes connection

EW9732 11:50 Düsseldorf – 13:40 Krakow

I would like to ask how the transfer works in Dusseldorf – I've read a lot of topics about it, but I'd like to ask the question again (the flight can be in the same terminal or in different ports, it seems to be A or B). It seems like it's very easy after the bus / plane, but I'd like to hear someone else. Since I am going from Schengen to Schengen, I suppose I will not have passport control (or security check?) When transferring and that I will be able to go directly to the next door? Is it enough time?

Since the booking is made with one ticket, will Eurowings "wait" for me if there is a short delay? Or will I have some kind of protection? I booked a ticket with the SMART fare but I can not read anything about it in particular.

Log in to admin through the frontend form?

I am developing a website with wordpress. I want to create a custom login page and login by email and not by user name.
And the admin page with the custom URL & # 39; / manage / & # 39;

Below my login code:

$email = $_POST('email');
$pass = $_POST('password');
$user = get_user_by('email', $email);
if (wp_check_password($pass, $user->data->user_pass, $user->ID)) {
   wp_set_current_user($user->data->ID, $user->data->user_login);
   wp_set_auth_cookie($user->data->ID);
   do_action( 'wp_login', $user->data->user_login );
   $_SESSION('success') = 'Hello ' . $user->data->display_name . '!';
   wp_safe_redirect(wp_get_referer());
   exit();
}

My problem is:

When I submit, the website has been successfully returned and the current user on Frontend has been changed. But when I try to access the dashboard of the administrator, it redirects me to wp-login.php and requires me to reconnect.
I do not know what's wrong or how to solve this problem.

So, please, help me!

SQL Server 2012 – Backup of Log Shipping

By performing a full backup (non-copy only) in primary mode, does this affect the log backup LSN chain and prevent log shipping from working?

No never. The full backup has NO impact on the transaction log backup chain, it will not interrupt the log processing. I strongly suggest that you read Paul Randal's Backup Myths section.

can I perform a full backup and a differential backup at the main level, and then for the log backup, can I use the log backup performed by sending logs to a shared folder for recovery in case of failure the main server and the secondary server?

Yes, you can not, neither a full backup nor a diff backup would prevent the sending of the logs, although your request seems strange to me. If their database is LS and you want to restore a full backup, diff, and log, be sure not to delete the log backups from the shared drive after crossing the threshold in LS.

Deal – 75 BMF POINTS – Register, check your email and log in consecutively for 3 days | NewProxyLists

75 POINTS BMF – Registration, verification of e-mail and consecutive connection for 3 days

I think it says it all, you get the 75 BMF points after you:

1. REGISTRATION – with real information – no adblockers, no vpn, no proxy, no proxy, use the IP address of the ISP.

Code:

https://topdogsrotator.com/weblord

2. VERIFY EMAIL – check your e-mail address, this is a viral mailer. If you do not want to receive, do not subscribe at all.

3. DAILY CONNECTION FOR 3 DAYS – so your account can be marked as active.

4. AFTER MAKING THE 3, GET 75 POINTS BMF HERE – send your user name here

Do you like takers?

The engine engine email engine does not work, please check the log here

13:51:53: () Attention! No target to publish (no site list enabled, no engine for selected URL retrieval, no scheduled publishing)

I do not get it, I do not have any other engine selected than this one, as it is the mode of use

Naming log files – are there guiding principles on when to include a timestamp? When to include other information and no?

I was talking with a colleague about software with which our software interfaces were used. Call the other romeo software and our Juliet software. Romeo creates log files containing time-stamped data that we must collect and return to the user. We have a consumer who consumes our code, which then interacts with Romeo. So we can add documentation to our code to help you with some limitations of Romeo, but otherwise we can not change Romeo.

Together, Romeo has the following features:

  • Allows the client to define the location where the log files will be stored, but does not provide the file name
  • There is no interface to ask us which log file is being written
  • Name the file according to the time we asked it to start, but there is a little delay because Romeo runs on a different computer from us. It is possible that we may potentially recover the wrong log file.
  • Each line of the log file is time stamped. Therefore, a timestamp in the file name does not provide any additional information.

In general, I think that including a timestamp in the name of a file is usually used only to avoid the possibility of a name collision when creating a file. a file to connect to. I could also see people not wanting to lose information on the file creation date. However, in our case, each line of the log file is time stamped, so there is no added value to add here.

In this particular case, because of our restrictions, I think it's a bad choice, but that brought me to the question in my title. Which scenarios usually constitute adding a time stamp to a file name, a log file, a data file, and so on. Is it a good decision and when is it a bad decision? Is it still acceptable to add a timestamp to a file name? Also, how do people not want to have a potential file name collision in addition to using a timestamp in the file name? A potential that I have thought of is a UUID, are there any others?