Add log tags

This commit is contained in:
badaix 2020-02-23 19:12:27 +01:00
parent 0d4c58fb63
commit 9af7445da2
2 changed files with 22 additions and 18 deletions

View file

@ -23,6 +23,8 @@
#include <cstdlib>
static constexpr auto LOG_TAG = "Avahi";
static AvahiEntryGroup* group;
static AvahiSimplePoll* simple_poll;
static char* name;
@ -43,7 +45,7 @@ void PublishAvahi::publish(const std::vector<mDNSService>& services)
if (!(simple_poll = avahi_simple_poll_new()))
{
/// TODO: error handling
LOG(ERROR) << "Failed to create simple poll object.\n";
LOG(ERROR, LOG_TAG) << "Failed to create simple poll object.\n";
}
/// Allocate a new client
@ -53,7 +55,7 @@ void PublishAvahi::publish(const std::vector<mDNSService>& services)
/// Check wether creating the client object succeeded
if (!client_)
{
LOG(ERROR) << "Failed to create client: " << avahi_strerror(error) << "\n";
LOG(ERROR, LOG_TAG) << "Failed to create client: " << avahi_strerror(error) << "\n";
}
poll();
@ -94,7 +96,7 @@ void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState
{
case AVAHI_ENTRY_GROUP_ESTABLISHED:
/// The entry group has been established successfully
LOG(INFO) << "Service '" << name << "' successfully established.\n";
LOG(INFO, LOG_TAG) << "Service '" << name << "' successfully established.\n";
break;
case AVAHI_ENTRY_GROUP_COLLISION:
@ -106,7 +108,7 @@ void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState
avahi_free(name);
name = n;
LOG(NOTICE) << "Service name collision, renaming service to '" << name << "'\n";
LOG(NOTICE, LOG_TAG) << "Service name collision, renaming service to '" << name << "'\n";
/// And recreate the services
static_cast<PublishAvahi*>(userdata)->create_services(avahi_entry_group_get_client(g));
@ -115,7 +117,7 @@ void PublishAvahi::entry_group_callback(AvahiEntryGroup* g, AvahiEntryGroupState
case AVAHI_ENTRY_GROUP_FAILURE:
LOG(ERROR) << "Entry group failure: " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << "\n";
LOG(ERROR, LOG_TAG) << "Entry group failure: " << avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))) << "\n";
/// Some kind of failure happened while we were registering our services
avahi_simple_poll_quit(simple_poll);
@ -136,7 +138,7 @@ void PublishAvahi::create_services(AvahiClient* c)
{
if (!(group = avahi_entry_group_new(c, entry_group_callback, this)))
{
LOG(ERROR) << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << "\n";
LOG(ERROR, LOG_TAG) << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << "\n";
goto fail;
}
}
@ -145,7 +147,7 @@ void PublishAvahi::create_services(AvahiClient* c)
int ret;
if (avahi_entry_group_is_empty(group))
{
LOG(INFO) << "Adding service '" << name << "'\n";
LOG(INFO, LOG_TAG) << "Adding service '" << name << "'\n";
/// We will now add two services and one subtype to the entry group
for (const auto& service : services_)
@ -156,7 +158,7 @@ void PublishAvahi::create_services(AvahiClient* c)
if (ret == AVAHI_ERR_COLLISION)
goto collision;
LOG(ERROR) << "Failed to add " << service.name_ << " service: " << avahi_strerror(ret) << "\n";
LOG(ERROR, LOG_TAG) << "Failed to add " << service.name_ << " service: " << avahi_strerror(ret) << "\n";
goto fail;
}
}
@ -173,7 +175,7 @@ void PublishAvahi::create_services(AvahiClient* c)
/// Tell the server to register the service
if ((ret = avahi_entry_group_commit(group)) < 0)
{
LOG(ERROR) << "Failed to commit entry group: " << avahi_strerror(ret) << "\n";
LOG(ERROR, LOG_TAG) << "Failed to commit entry group: " << avahi_strerror(ret) << "\n";
goto fail;
}
}
@ -187,7 +189,7 @@ collision:
avahi_free(name);
name = n;
LOG(INFO) << "Service name collision, renaming service to '" << name << "'\n";
LOG(INFO, LOG_TAG) << "Service name collision, renaming service to '" << name << "'\n";
avahi_entry_group_reset(group);
@ -214,7 +216,7 @@ void PublishAvahi::client_callback(AvahiClient* c, AvahiClientState state, AVAHI
case AVAHI_CLIENT_FAILURE:
LOG(ERROR) << "Client failure: " << avahi_strerror(avahi_client_errno(c)) << "\n";
LOG(ERROR, LOG_TAG) << "Client failure: " << avahi_strerror(avahi_client_errno(c)) << "\n";
avahi_simple_poll_quit(simple_poll);
break;