Revert "Remove format lib all together it was a relic of spdlog anyway"

This reverts commit 487dccfddd6c14ad2c43bcc77af1a61c81e735f9.
This commit is contained in:
KimLS 2016-09-11 21:43:42 -07:00
parent 487dccfddd
commit 2fd439dd0b
9 changed files with 32 additions and 22 deletions

View File

@ -19,6 +19,7 @@
#ifndef EQEMU_LOGSYS_H #ifndef EQEMU_LOGSYS_H
#define EQEMU_LOGSYS_H #define EQEMU_LOGSYS_H
#include <fmt/format.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <stdio.h> #include <stdio.h>
@ -157,6 +158,13 @@ public:
void SetCurrentTimeStamp(char* time_stamp); /* Used in file logs to prepend a timestamp entry for logs */ void SetCurrentTimeStamp(char* time_stamp); /* Used in file logs to prepend a timestamp entry for logs */
void StartFileLogs(const std::string &log_name = ""); /* Used to declare the processes file log and to keep it open for later use */ void StartFileLogs(const std::string &log_name = ""); /* Used to declare the processes file log and to keep it open for later use */
template <typename... Args>
void OutF(Logs::DebugLevel debug_level, uint16 log_category, const char *fmt, const Args&... args)
{
std::string log_str = fmt::format(fmt, args...);
Out(debug_level, log_category, log_str);
}
/* /*
LogSettings Struct LogSettings Struct

View File

@ -165,7 +165,7 @@ void EQ::Net::DaybreakConnectionManager::ProcessResend()
void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoint, int port, const char *data, size_t size) void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoint, int port, const char *data, size_t size)
{ {
if (size < DaybreakHeader::size()) { if (size < DaybreakHeader::size()) {
Log.Out(Logs::Detail, Logs::Netcode, "Packet of size %u which is less than %u", size, DaybreakHeader::size()); Log.OutF(Logs::Detail, Logs::Netcode, "Packet of size {0} which is less than {1}", size, DaybreakHeader::size());
return; return;
} }
@ -195,7 +195,7 @@ void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoi
} }
} }
catch (std::exception &ex) { catch (std::exception &ex) {
Log.Out(Logs::Detail, Logs::Netcode, "Error processing packet: %s", ex.what()); Log.OutF(Logs::Detail, Logs::Netcode, "Error processing packet: {0}", ex.what());
} }
} }
@ -341,7 +341,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
} }
if (p.GetInt8(0) != 0) { if (p.GetInt8(0) != 0) {
Log.Out(Logs::Detail, Logs::Netcode, "Error parsing packet, did not start with a 0 frame, not a valid protocol packet."); Log.OutF(Logs::Detail, Logs::Netcode, "Error parsing packet, did not start with a 0 frame, not a valid protocol packet.");
return; return;
} }
@ -352,7 +352,7 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
if (PacketCanBeEncoded(p)) { if (PacketCanBeEncoded(p)) {
if (!ValidateCRC(p)) { if (!ValidateCRC(p)) {
Log.Out(Logs::Detail, Logs::Netcode, "Tossed packet that failed CRC of type 0x%x", p.Length() >= 2 ? p.GetInt8(1) : 0); Log.OutF(Logs::Detail, Logs::Netcode, "Tossed packet that failed CRC of type {0:#x}", p.Length() >= 2 ? p.GetInt8(1) : 0);
return; return;
} }
@ -664,7 +664,7 @@ void EQ::Net::DaybreakConnection::ProcessDecodedPacket(Packet &p)
break; break;
} }
default: default:
Log.Out(Logs::Detail, Logs::Netcode, "Unhandled opcode 0x%x", p.GetInt8(1)); Log.OutF(Logs::Detail, Logs::Netcode, "Unhandled opcode {0:#x}", p.GetInt8(1));
break; break;
} }
} }

View File

@ -48,7 +48,7 @@ void EQ::Net::EQStreamManager::DaybreakPacketRecv(std::shared_ptr<DaybreakConnec
if (match == EQ::Patches::IdentityMatchSuccess) { if (match == EQ::Patches::IdentityMatchSuccess) {
iter->second->RegisterPatch(pt.get()); iter->second->RegisterPatch(pt.get());
patch = pt.get(); patch = pt.get();
Log.Out(Logs::General, Logs::Debug, "Identified patch with name %s", pt->GetName().c_str()); Log.OutF(Logs::General, Logs::Debug, "Identified patch with name {0}", pt->GetName());
} }
} }
} }
@ -59,7 +59,7 @@ void EQ::Net::EQStreamManager::DaybreakPacketRecv(std::shared_ptr<DaybreakConnec
patch->Decode(&p, opcode, out); patch->Decode(&p, opcode, out);
if (opcode == OP_Unknown) { if (opcode == OP_Unknown) {
Log.Out(Logs::General, Logs::Netcode, "Incoming packet was not handled because the opcode was not found.\n%s", p.ToString().c_str()); Log.OutF(Logs::General, Logs::Netcode, "Incoming packet was not handled because the opcode was not found.\n{0}", p.ToString());
} }
else { else {
if (m_on_packet_recv) { if (m_on_packet_recv) {
@ -68,7 +68,7 @@ void EQ::Net::EQStreamManager::DaybreakPacketRecv(std::shared_ptr<DaybreakConnec
} }
} }
else { else {
Log.Out(Logs::General, Logs::Netcode, "Incoming packet was not handled because we don't have a patch set.\n%s", p.ToString().c_str()); Log.OutF(Logs::General, Logs::Netcode, "Incoming packet was not handled because we don't have a patch set.\n{0}", p.ToString());
} }
} }
} }

View File

@ -1,6 +1,6 @@
#include "packet.h" #include "packet.h"
#include <net/endian.h> #include <net/endian.h>
#include <string_util.h> #include <fmt/format.h>
#include <cctype> #include <cctype>
void EQ::Net::Packet::PutInt8(size_t offset, int8_t value) void EQ::Net::Packet::PutInt8(size_t offset, int8_t value)
@ -290,12 +290,12 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
char *data = (char*)Data(); char *data = (char*)Data();
for (i = 0; i < lines; ++i) { for (i = 0; i < lines; ++i) {
ret += StringFormat("%.5x |", i * line_length); ret += fmt::format("{:0>5x} |", i * line_length);
std::string hex; std::string hex;
std::string ascii; std::string ascii;
for (size_t j = 0; j < line_length; ++j) { for (size_t j = 0; j < line_length; ++j) {
hex += StringFormat(" %.2x", (uint8_t)data[(i * line_length) + j]); hex += fmt::format(" {:0>2x}", (uint8_t)data[(i * line_length) + j]);
ascii += StringFormat("%c", ToSafePrint(data[(i * line_length) + j])); ascii += fmt::format("{}", ToSafePrint(data[(i * line_length) + j]));
} }
ret += hex; ret += hex;
@ -305,7 +305,7 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
} }
if (Length() % line_length > 0) { if (Length() % line_length > 0) {
ret += StringFormat("%.5x |", i * line_length); ret += fmt::format("{:0>5x} |", i * line_length);
size_t non_blank_count = Length() % line_length; size_t non_blank_count = Length() % line_length;
size_t blank_count = line_length - non_blank_count; size_t blank_count = line_length - non_blank_count;
@ -313,8 +313,8 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
std::string ascii; std::string ascii;
for (size_t j = 0; j < non_blank_count; ++j) { for (size_t j = 0; j < non_blank_count; ++j) {
hex += StringFormat(" %.2x", (uint8_t)data[(i * line_length) + j]); hex += fmt::format(" {:0>2x}", (uint8_t)data[(i * line_length) + j]);
ascii += StringFormat("%x", ToSafePrint(data[(i * line_length) + j])); ascii += fmt::format("{}", ToSafePrint(data[(i * line_length) + j]));
} }
for (size_t j = 0; j < blank_count; ++j) { for (size_t j = 0; j < blank_count; ++j) {

View File

@ -3,3 +3,4 @@ IF(EQEMU_BUILD_LUA)
ENDIF(EQEMU_BUILD_LUA) ENDIF(EQEMU_BUILD_LUA)
ADD_SUBDIRECTORY(libuv) ADD_SUBDIRECTORY(libuv)
ADD_SUBDIRECTORY(format)

View File

@ -41,7 +41,7 @@ ADD_EXECUTABLE(loginserver ${eqlogin_sources} ${eqlogin_headers})
INSTALL(TARGETS loginserver RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) INSTALL(TARGETS loginserver RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
TARGET_LINK_LIBRARIES(loginserver common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} libuv) TARGET_LINK_LIBRARIES(loginserver common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} libuv fmt)
IF(WIN32) IF(WIN32)
TARGET_LINK_LIBRARIES(loginserver "ws2_32" "psapi" "iphlpapi" "userenv") TARGET_LINK_LIBRARIES(loginserver "ws2_32" "psapi" "iphlpapi" "userenv")

View File

@ -52,14 +52,14 @@ ClientManager::~ClientManager()
void ClientManager::HandleNewConnectionTitanium(std::shared_ptr<EQ::Net::EQStream> connection) void ClientManager::HandleNewConnectionTitanium(std::shared_ptr<EQ::Net::EQStream> connection)
{ {
Log.Out(Logs::General, Logs::Login_Server, "New Titanium client from %s:%d", connection->RemoteEndpoint().c_str(), connection->RemotePort()); Log.OutF(Logs::General, Logs::Login_Server, "New Titanium client from {0}:{1}", connection->RemoteEndpoint(), connection->RemotePort());
Client *c = new Client(connection, cv_titanium); Client *c = new Client(connection, cv_titanium);
clients.push_back(std::unique_ptr<Client>(c)); clients.push_back(std::unique_ptr<Client>(c));
} }
void ClientManager::HandleNewConnectionSod(std::shared_ptr<EQ::Net::EQStream> connection) void ClientManager::HandleNewConnectionSod(std::shared_ptr<EQ::Net::EQStream> connection)
{ {
Log.Out(Logs::General, Logs::Login_Server, "New SoD client from %s:%d", connection->RemoteEndpoint().c_str(), connection->RemotePort()); Log.OutF(Logs::General, Logs::Login_Server, "New SoD client from {0}:{1}", connection->RemoteEndpoint(), connection->RemotePort());
Client *c = new Client(connection, cv_sod); Client *c = new Client(connection, cv_sod);
clients.push_back(std::unique_ptr<Client>(c)); clients.push_back(std::unique_ptr<Client>(c));
} }
@ -67,7 +67,7 @@ void ClientManager::HandleNewConnectionSod(std::shared_ptr<EQ::Net::EQStream> co
void ClientManager::HandleConnectionChange(std::shared_ptr<EQ::Net::EQStream> connection, EQ::Net::DbProtocolStatus old_status, EQ::Net::DbProtocolStatus new_status) void ClientManager::HandleConnectionChange(std::shared_ptr<EQ::Net::EQStream> connection, EQ::Net::DbProtocolStatus old_status, EQ::Net::DbProtocolStatus new_status)
{ {
if (new_status == EQ::Net::DbProtocolStatus::StatusDisconnected) { if (new_status == EQ::Net::DbProtocolStatus::StatusDisconnected) {
Log.Out(Logs::General, Logs::Login_Server, "Client has been disconnected, removing %s:%d", connection->RemoteEndpoint().c_str(), connection->RemotePort()); Log.OutF(Logs::General, Logs::Login_Server, "Client has been disconnected, removing {0}:{1}", connection->RemoteEndpoint(), connection->RemotePort());
auto iter = clients.begin(); auto iter = clients.begin();
while (iter != clients.end()) { while (iter != clients.end()) {
if ((*iter)->GetConnection() == connection) { if ((*iter)->GetConnection() == connection) {

View File

@ -23,7 +23,7 @@ INSTALL(TARGETS ucs RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
ADD_DEFINITIONS(-DUCS) ADD_DEFINITIONS(-DUCS)
TARGET_LINK_LIBRARIES(ucs common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} libuv) TARGET_LINK_LIBRARIES(ucs common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} libuv fmt)
IF(WIN32) IF(WIN32)
TARGET_LINK_LIBRARIES(ucs "ws2_32" "psapi" "iphlpapi" "userenv") TARGET_LINK_LIBRARIES(ucs "ws2_32" "psapi" "iphlpapi" "userenv")

View File

@ -2114,7 +2114,7 @@ Client *Clientlist::IsCharacterOnline(std::string CharacterName) {
void Clientlist::HandleNewConnection(std::shared_ptr<EQ::Net::EQStream> connection) void Clientlist::HandleNewConnection(std::shared_ptr<EQ::Net::EQStream> connection)
{ {
Log.Out(Logs::Detail, Logs::UCS_Server, "New Client UDP connection from %s:%d", connection->RemoteEndpoint().c_str(), connection->RemotePort()); Log.OutF(Logs::Detail, Logs::UCS_Server, "New Client UDP connection from {0}:{1}", connection->RemoteEndpoint(), connection->RemotePort());
Client *c = new Client(connection); Client *c = new Client(connection);
ClientChatConnections.push_back(std::unique_ptr<Client>(c)); ClientChatConnections.push_back(std::unique_ptr<Client>(c));
} }
@ -2122,7 +2122,7 @@ void Clientlist::HandleNewConnection(std::shared_ptr<EQ::Net::EQStream> connecti
void Clientlist::HandleConnectionChange(std::shared_ptr<EQ::Net::EQStream> connection, EQ::Net::DbProtocolStatus old_status, EQ::Net::DbProtocolStatus new_status) void Clientlist::HandleConnectionChange(std::shared_ptr<EQ::Net::EQStream> connection, EQ::Net::DbProtocolStatus old_status, EQ::Net::DbProtocolStatus new_status)
{ {
if (new_status == EQ::Net::DbProtocolStatus::StatusDisconnected) { if (new_status == EQ::Net::DbProtocolStatus::StatusDisconnected) {
Log.Out(Logs::Detail, Logs::UCS_Server, "Client connection from %s:%d closed.", connection->RemoteEndpoint().c_str(), connection->RemotePort()); Log.OutF(Logs::Detail, Logs::UCS_Server, "Client connection from {0}:{1} closed.", connection->RemoteEndpoint(), connection->RemotePort());
auto iter = ClientChatConnections.begin(); auto iter = ClientChatConnections.begin();
while (iter != ClientChatConnections.end()) { while (iter != ClientChatConnections.end()) {
if ((*iter)->ClientStream == connection) { if ((*iter)->ClientStream == connection) {
@ -2139,6 +2139,7 @@ void Clientlist::HandlePacket(std::shared_ptr<EQ::Net::EQStream> connection, Emu
auto iter = ClientChatConnections.begin(); auto iter = ClientChatConnections.begin();
while (iter != ClientChatConnections.end()) { while (iter != ClientChatConnections.end()) {
if ((*iter)->ClientStream == connection) { if ((*iter)->ClientStream == connection) {
Log.OutF(Logs::General, Logs::UCS_Server, "{0}", p.ToString());
EQApplicationPacket app(opcode, (unsigned char*)p.Data(), (uint32)p.Length()); EQApplicationPacket app(opcode, (unsigned char*)p.Data(), (uint32)p.Length());
Process((*iter).get(), &app); Process((*iter).get(), &app);
return; return;