A simple Logging Library : MyLoggingLibrary

If have developed a simple logging library for console and file and multiple support of appenders. It’s called MyLoggingLibrary.

I have made it available to github: https://github.com/ChristophePichaud/MyLoggingLibrary

It was a sample for my students but it works and it’s simple to use. There is no configuration file.

// Client.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include "pch.h"

int main()
{
	CAppender appender1("log");
	appender1.SetLevel(Level::Debug);
	appender1.SetAppenderType(AppenderType::Console);

	// Appender 2 de type fichier
	CAppender appender2("log");
	appender2.SetLevel(Level::Info);
	appender2.SetAppenderType(AppenderType::File);

	// Objet de configuration
	CConfiguration config;
	config.AddAppender(appender1);
	config.AddAppender(appender2);

	// Get Logger(s) "log" & use => affichage en console et écriture en fichier
	std::unique_ptr<CLogger> logger = config.GetLogger("log", Level::Debug);
	for (int i = 0; i < 10; i++)
	{
		logger->Debug("Logging a Debug...");
		logger->Warning("Logging a Warning...");
		logger->Error("Logging an Error...");
		logger->Info("Logging an Info...");
	}
}

 

Advertisements

Programmez – My Articles from Oct 2017 to Jan 2019

Here are my articles for french Magazine Programmez:

  • N°225: Rookit key Logger – PDF
  • N°224: Space Invaders 1978 en C/C++ avec SFML – PDF
  • N°223: Windows Le Multithreading en C/C++ – PDF
  • N°222: Linux Le Multithreading en C++ – PDF
  • N°221: Au coeur d’un Service Windows NoSQL – PDF
  • N°220: Créer un service Windows – PDF
  • N°218: Migrer son code C/C++ en 64 bits – PDF
  • N°217: Les Tests en C++ – PDF
  • N°216: La Programmation Orientée Objet en C++ – PDF
  • N°215: Utiliser shared_ptr<T> en C++ pour la gestion des ressources – PDF
  • N°214: Développez un IDE en C++ Partie II – PDF
  • N°213: Développez un IDE en C++ Partie I – PDF
  • N°212: Un serveur REST Web API en C++ – PDF
  • N°211: Pourquoi C++ en 2017 ? – PDF

Surface Go feedback

After two weeks of using the Surface Go, I am very satisfied. I have installed Office suite 2019 for documents and messaging stuff.

The Microsoft multimedia keyboard is easy to use… The Pentium processor is enough to run Office, VS Code and Visual C++. I compile my teaching projects very fast and it works well. The memory of 4GB is just a problem if you open 20 Chrome windows but if you close and open at regular basis, it works perfectly well. This is definitively a good buy.

C++ developers need few resources…

I have installed Visual Studio 15.9.4 on my Surface Go with only Visual C++ features.

As a C++ developer, I only rely on small features:

  • an IDE for managing files, projects and the editor
  • an ISO C++ compiler

Surface Go comes with a Pentium processor and fast hard drive so it’s cool for C++ stuff.

Surface Go for developers !

My gift for Christmas is a Surface Go with a Microsoft Media Keyboard and two 128GB SanDisk MicroSD cards.

I have installed all the necessary tools:

  • 7zip
  • Acrobat Reader
  • VLC
  • Winamp
  • Notepad++
  • Chrome
  • TechSmith Camtasia 2018
  • SysInternals Suite

I have installed the following Microsoft products:

  • Office 2019
  • Visual Studio 2017 15.9.2 with Visual C++ only tools -> 10 GB

After that, remaining space is 10GB.

On SD cards, I put data, ebooks and multimedia files (mp3 and movies).

Search for files & folders

My boss wanted a tool for searching files and folders from a dedicated path… He used to write it using Powershell but took hours to run… Here is why system programming is important. No runtime, no framwork, no virtual machine, it runs direct on the metal. Fast !

#include <string>
#include <iostream>
#include <atlstr.h> 
#include <tchar.h>
#include <Windows.h>
#include <Shlwapi.h>

#pragma comment(lib, "Shlwapi.lib")


CString SearchDrive(const CString& strFile, const CString& strFilePath, const bool& bRecursive, const bool& bStopWhenFound) 
{
       CString strFoundFilePath;
       WIN32_FIND_DATA file;

       CString strPathToSearch = strFilePath;
       strPathToSearch += _T("\\");

       HANDLE hFile = FindFirstFile((strPathToSearch + "*"), &file);
       if (hFile != INVALID_HANDLE_VALUE)
       {
             do
             {
                    CString strTheNameOfTheFile = file.cFileName;

                    // It could be a directory we are looking at
                    // if so look into that dir
                    if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                    {
                           if ((strTheNameOfTheFile != ".") && (strTheNameOfTheFile != "..") && (bRecursive))
                           {
                                  strFoundFilePath = SearchDrive(strFile, strPathToSearch + strTheNameOfTheFile, bRecursive, bStopWhenFound);

                                  if (!strFoundFilePath.IsEmpty() && bStopWhenFound)
                                        break;
                           }
                    }
                    else
                    {
                           strFoundFilePath = strPathToSearch + strTheNameOfTheFile; //strFile;

                           long size = (file.nFileSizeHigh * (MAXDWORD + 1)) + file.nFileSizeLow;

                           TCHAR szPath[10240];
                           memset(szPath, 0, 10240);
                           _tcscpy_s(szPath, (LPCTSTR)strFoundFilePath);
                           ::PathRemoveFileSpec(szPath);
                           _tprintf(_T("%s;%s;%ld\n"), szPath, (LPCTSTR)strTheNameOfTheFile, size);


                           if (bStopWhenFound)
                                  break;
                    }
             } while (FindNextFile(hFile, &file));

             FindClose(hFile);
       }

       return strFoundFilePath;
}


int _tmain(int argc, TCHAR *argv[])
{
       if (argc != 2)
       {
             std::wcout << _T("Help") << std::endl;
             std::wcout << _T("usage: scanfiles <path>") << std::endl;
             return 0;
       }

       TCHAR strPath[1024];
       wcscpy_s(strPath, argv[1]);

       TCHAR strWildcard[255];
       wcscpy_s(strWildcard, _T("*.*"));

       SearchDrive(strWildcard, strPath, true, false);

       return 0;
}

 

Article in Programmez for January 2019

My next article will be in french Magazine Programmez in January 2019. It will talks about rootkits and key logger.

225