Skip to content

Commit 79a3fa5

Browse files
committed
Add a logger to the application
1 parent ba49db7 commit 79a3fa5

File tree

6 files changed

+365
-0
lines changed

6 files changed

+365
-0
lines changed

LaunchBounce.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.34009.444
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LaunchBounce", "LaunchBounce\LaunchBounce.vcxproj", "{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Debug|x64.ActiveCfg = Debug|x64
17+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Debug|x64.Build.0 = Debug|x64
18+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Debug|x86.ActiveCfg = Debug|Win32
19+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Debug|x86.Build.0 = Debug|Win32
20+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Release|x64.ActiveCfg = Release|x64
21+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Release|x64.Build.0 = Release|x64
22+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Release|x86.ActiveCfg = Release|Win32
23+
{3A7088ED-2F18-4D3D-BE2F-CA7B7E1A5E75}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {B4306302-A214-4C16-B60B-2397AC9D2DFF}
30+
EndGlobalSection
31+
EndGlobal

LaunchBounce/LaunchBounce.vcxproj

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClCompile Include="Source\LaunchBounce.cpp" />
23+
<ClCompile Include="Source\Logger.cpp" />
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClInclude Include="Source\Logger.h" />
27+
</ItemGroup>
28+
<PropertyGroup Label="Globals">
29+
<VCProjectVersion>17.0</VCProjectVersion>
30+
<Keyword>Win32Proj</Keyword>
31+
<ProjectGuid>{3a7088ed-2f18-4d3d-be2f-ca7b7e1a5e75}</ProjectGuid>
32+
<RootNamespace>LaunchBounce</RootNamespace>
33+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
34+
</PropertyGroup>
35+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
36+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
37+
<ConfigurationType>Application</ConfigurationType>
38+
<UseDebugLibraries>true</UseDebugLibraries>
39+
<PlatformToolset>v143</PlatformToolset>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>false</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<WholeProgramOptimization>true</WholeProgramOptimization>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
49+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
50+
<ConfigurationType>Application</ConfigurationType>
51+
<UseDebugLibraries>true</UseDebugLibraries>
52+
<PlatformToolset>v143</PlatformToolset>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
56+
<ConfigurationType>Application</ConfigurationType>
57+
<UseDebugLibraries>false</UseDebugLibraries>
58+
<PlatformToolset>v143</PlatformToolset>
59+
<WholeProgramOptimization>true</WholeProgramOptimization>
60+
<CharacterSet>Unicode</CharacterSet>
61+
</PropertyGroup>
62+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
63+
<ImportGroup Label="ExtensionSettings">
64+
</ImportGroup>
65+
<ImportGroup Label="Shared">
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
71+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72+
</ImportGroup>
73+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
75+
</ImportGroup>
76+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
77+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
78+
</ImportGroup>
79+
<PropertyGroup Label="UserMacros" />
80+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
81+
<OutDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\</OutDir>
82+
<IntDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\Artefacts\</IntDir>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
85+
<OutDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\</OutDir>
86+
<IntDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\Artefacts\</IntDir>
87+
</PropertyGroup>
88+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
89+
<OutDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\</OutDir>
90+
<IntDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\Artefacts\</IntDir>
91+
</PropertyGroup>
92+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
93+
<OutDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\</OutDir>
94+
<IntDir>$(SolutionDir)BuildOutput\$(Platform)\$(Configuration)\Artefacts\</IntDir>
95+
</PropertyGroup>
96+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
97+
<ClCompile>
98+
<WarningLevel>Level3</WarningLevel>
99+
<SDLCheck>true</SDLCheck>
100+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
101+
<ConformanceMode>true</ConformanceMode>
102+
<LanguageStandard>stdcpp20</LanguageStandard>
103+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
104+
</ClCompile>
105+
<Link>
106+
<SubSystem>Console</SubSystem>
107+
<GenerateDebugInformation>true</GenerateDebugInformation>
108+
</Link>
109+
</ItemDefinitionGroup>
110+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
111+
<ClCompile>
112+
<WarningLevel>Level3</WarningLevel>
113+
<FunctionLevelLinking>true</FunctionLevelLinking>
114+
<IntrinsicFunctions>true</IntrinsicFunctions>
115+
<SDLCheck>true</SDLCheck>
116+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
117+
<ConformanceMode>true</ConformanceMode>
118+
<LanguageStandard>stdcpp20</LanguageStandard>
119+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
120+
</ClCompile>
121+
<Link>
122+
<SubSystem>Console</SubSystem>
123+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
124+
<OptimizeReferences>true</OptimizeReferences>
125+
<GenerateDebugInformation>true</GenerateDebugInformation>
126+
</Link>
127+
</ItemDefinitionGroup>
128+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
129+
<ClCompile>
130+
<WarningLevel>Level3</WarningLevel>
131+
<SDLCheck>true</SDLCheck>
132+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
133+
<ConformanceMode>true</ConformanceMode>
134+
<LanguageStandard>stdcpp20</LanguageStandard>
135+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
136+
</ClCompile>
137+
<Link>
138+
<SubSystem>Console</SubSystem>
139+
<GenerateDebugInformation>true</GenerateDebugInformation>
140+
</Link>
141+
</ItemDefinitionGroup>
142+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
143+
<ClCompile>
144+
<WarningLevel>Level3</WarningLevel>
145+
<FunctionLevelLinking>true</FunctionLevelLinking>
146+
<IntrinsicFunctions>true</IntrinsicFunctions>
147+
<SDLCheck>true</SDLCheck>
148+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
149+
<ConformanceMode>true</ConformanceMode>
150+
<LanguageStandard>stdcpp20</LanguageStandard>
151+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
152+
</ClCompile>
153+
<Link>
154+
<SubSystem>Console</SubSystem>
155+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
156+
<OptimizeReferences>true</OptimizeReferences>
157+
<GenerateDebugInformation>true</GenerateDebugInformation>
158+
</Link>
159+
</ItemDefinitionGroup>
160+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
161+
<ImportGroup Label="ExtensionTargets">
162+
</ImportGroup>
163+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="Source\LaunchBounce.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
<ClCompile Include="Source\Logger.cpp">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClInclude Include="Source\Logger.h">
27+
<Filter>Header Files</Filter>
28+
</ClInclude>
29+
</ItemGroup>
30+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright 2024 David Roller
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
#include "Logger.h"
17+
18+
using Therena::LaunchBounce::Logger;
19+
20+
int wmain(int argc, wchar_t* argv[])
21+
{
22+
Logger::Info(L"##################################################################################");
23+
Logger::Info(L"Execute launch bounce");
24+
Logger::Info(L"##################################################################################");
25+
}
26+

LaunchBounce/Source/Logger.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//
2+
// Copyright 2024 David Roller
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
#include "Logger.h"
17+
#include <format>
18+
#include <chrono>
19+
#include <Windows.h>
20+
#include <iostream>
21+
#include <filesystem>
22+
#include <fstream>
23+
24+
using Therena::LaunchBounce::Logger;
25+
26+
void Logger::Info(const std::wstring& message)
27+
{
28+
std::unique_lock lock(GetMutex());
29+
WriteLog(GetTime() + L" [INFO] [" + std::to_wstring(GetCurrentThreadId()) + L"] " + message);
30+
}
31+
32+
void Logger::Warning(const std::wstring& message)
33+
{
34+
std::unique_lock lock(GetMutex());
35+
WriteLog(GetTime() + L" [WARN] [" + std::to_wstring(GetCurrentThreadId()) + L"] " + message);
36+
}
37+
38+
void Logger::Error(const std::wstring& message)
39+
{
40+
std::unique_lock lock(GetMutex());
41+
WriteLog(GetTime() + L" [ERROR] [" + std::to_wstring(GetCurrentThreadId()) + L"] " + message);
42+
}
43+
44+
45+
void Logger::WriteLog(const std::wstring& message)
46+
{
47+
std::wcout << message << std::endl;
48+
49+
wchar_t pathBuffer[MAX_PATH + 1];
50+
::GetModuleFileNameW(nullptr, pathBuffer, MAX_PATH);
51+
52+
std::filesystem::path path = pathBuffer;
53+
const auto logFilePath = path.replace_extension(L".log");
54+
55+
56+
std::wofstream fileStream(logFilePath, std::ios_base::app);
57+
58+
fileStream << message << std::endl;
59+
60+
fileStream.flush();
61+
fileStream.close();
62+
}
63+
64+
std::wstring Logger::GetTime()
65+
{
66+
const auto currentTime = std::chrono::system_clock::now();
67+
return std::format(L"{:%Y-%m-%d %X}", currentTime);
68+
}
69+
70+
std::mutex& Logger::GetMutex()
71+
{
72+
static std::mutex mutex;
73+
return mutex;
74+
}

LaunchBounce/Source/Logger.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Copyright 2024 David Roller
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
#pragma once
17+
18+
#include <string>
19+
#include <mutex>
20+
21+
namespace Therena::LaunchBounce
22+
{
23+
class Logger final
24+
{
25+
public:
26+
Logger() = delete;
27+
28+
static void Info(const std::wstring& message);
29+
30+
static void Warning(const std::wstring& message);
31+
32+
static void Error(const std::wstring& message);
33+
34+
private:
35+
static std::mutex& GetMutex();
36+
37+
static std::wstring GetTime();
38+
39+
static void WriteLog(const std::wstring& message);
40+
};
41+
}

0 commit comments

Comments
 (0)