SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PacketFileLogger.cpp
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2016-2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
16 #include "slikenet/NativeFeatureIncludes.h"
17 #if _RAKNET_SUPPORT_PacketLogger==1
18
19 #include "slikenet/PacketFileLogger.h"
20 #include "slikenet/GetTime.h"
21 #include "slikenet/linux_adapter.h"
22 #include "slikenet/osx_adapter.h"
23 #include "slikenet/memoryoverride.h"
24
25 using namespace SLNet;
26
27 STATIC_FACTORY_DEFINITIONS(PacketFileLogger,PacketFileLogger);
28
29 PacketFileLogger::PacketFileLogger()
30 {
31 packetLogFile=0;
32 }
33 PacketFileLogger::~PacketFileLogger()
34 {
35 if (packetLogFile)
36 {
37 fflush(packetLogFile);
38 fclose(packetLogFile);
39 }
40 }
41 void PacketFileLogger::StartLog(const char *filenamePrefix)
42 {
43 // Open file for writing
44 char filename[256];
45 if (filenamePrefix)
46 sprintf_s(filename, "%s_%i.csv", filenamePrefix, (int)SLNet::GetTimeMS());
47 else
48 sprintf_s(filename, "PacketLog_%i.csv", (int)SLNet::GetTimeMS());
49 errno_t error = fopen_s(&packetLogFile, filename, "wt");
50 LogHeader();
51 if (error == 0)
52 {
53 fflush(packetLogFile);
54 }
55 }
56
57 void PacketFileLogger::WriteLog(const char *str)
58 {
59 if (packetLogFile)
60 {
61 fprintf(packetLogFile, "%s\n", str);
62 fflush(packetLogFile);
63 }
64 }
65
66 #endif // _RAKNET_SUPPORT_*