Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify logging #60

Merged
merged 12 commits into from
Jul 18, 2023
Merged

Unify logging #60

merged 12 commits into from
Jul 18, 2023

Conversation

linaScience
Copy link
Member

No description provided.

@linaScience linaScience linked an issue Apr 26, 2023 that may be closed by this pull request
5 tasks
@Sohn123 Sohn123 marked this pull request as draft April 26, 2023 09:09
@Sohn123 Sohn123 changed the title [Draft] Unify logging Unify logging Apr 26, 2023
@linaScience linaScience marked this pull request as ready for review July 13, 2023 13:31
Copy link
Member

@Sohn123 Sohn123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the format you developed is good :) Just some minor corrections and nitpicks. So let's fix it and :shipit:

@@ -44,9 +44,9 @@ void Configuration::set_all_available_sockets_if_empty() {
}
}
if (socknames.empty()) {
throw std::runtime_error("No sockets were configured and no sockets could be found.");
throw std::runtime_error("Could not find and configure sockets.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this message is misleading now. It should state that no sockets were configured.

}
WMLOG(DEBUG) << "No sockets were configured. Using all " << socknames.size() << " sockets available.";
WMLOG(DEBUG) << "Could not configure sockets. Using all " << socknames.size() << " sockets available.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an error. There were no sockets specified and our auto-detection worked.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "Found" << socknames.size() << "available sockets". sound better?

<< event->station.vlan_id.value_or(0);
WMLOG(INFO) << "Station " << event->station << " connected to AP for VXLAN " << event->station.vni()
<< " at interface " << event->station.sockname;
WMLOG(DEBUG) << "Calling handle_connect() for MAC:" << event->station
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not calling the method it is already called. Maybe rather use entering?

caller.deauth_station(event->station);
}
}

void EventLoop::handle_disconnect(ipc::DisconnectEvent* event) {
WMLOG(INFO) << "Station " << event->station << " disconnected from AP";
WMLOG(INFO) << "Disconnected station: " << event->station.mac.string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like we disconnected the station but rather the station decided to disconnect.

@@ -74,29 +74,29 @@ ipc::Socket::Socket(const std::chrono::duration<int>& timeout, const std::string
local.sun_path[sizeof(local.sun_path) - 1] = '\0';
if (bind(sock_fd, reinterpret_cast<struct sockaddr*>(&local), sizeof(local)) == -1) {
close(sock_fd);
throw std::runtime_error("could not bind to socket " + dest_path + ": " + std::strerror(errno));
throw std::runtime_error("Could not bind to socket " + dest_path + ": " + std::strerror(errno));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colon missing.

@@ -118,7 +118,7 @@ void ipc::Socket::send_command(const std::vector<std::string>& args) {

ssize_t err = send(sock_fd, command.c_str(), command.size(), 0);
if (err < 0) {
throw std::runtime_error(std::string("could not send_command to socket: ") + std::strerror(errno));
throw std::runtime_error(std::string("Could not send_command() to socket: ") + std::strerror(errno));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write Could not send to socket:

@@ -122,7 +122,7 @@ void nl::Socket::delete_interface(const std::string &name) {
if (err < 0) {
throw std::runtime_error(std::string("Could not delete link: ") + nl_geterror(err));
}
WMLOG(INFO) << "Deleted " << name;
WMLOG(INFO) << "Deleted interface." << name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colon instead of dot

@Sohn123
Copy link
Member

Sohn123 commented Jul 14, 2023

Please also rebase onto latest main so the pipeline is green.


if (not station.vlan_id.has_value()) {
throw std::runtime_error("The station " + station.mac.string() + " has no vlan_id");
throw std::runtime_error("Station with MAC: " + station.mac.string() + " has no vlan_id.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we should use key-value pairs to give additional information, and move them to the end.
For this log message, I propose "Station has no vlan_id mac=", similar for the others

Copy link
Member

@rgwohlbold rgwohlbold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our goal here is to make our logs searchable.
For example, if I wanted to find all events relating to a MAC address 00:00:00:00:00:01, I would search for station=00:00:00:00:00:01.
For that reason, I propose the following changes:

  • We should use unified keys, for example station instead of station or mac
  • No whitespace between the = and the value
  • We should put the key-value pairs last and leave out prepositions like with before the pairs.

@@ -122,7 +122,7 @@ void nl::Socket::delete_interface(const std::string &name) {
if (err < 0) {
throw std::runtime_error(std::string("Could not delete link: ") + nl_geterror(err));
}
WMLOG(INFO) << "Deleted " << name;
WMLOG(INFO) << "Deleted interface:" << name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use iface=

}
WMLOG(INFO) << "Connected " << interface_name << " to " << bridge_name;
WMLOG(INFO) << "Connected interface=" << interface_name << " to bridge= " << bridge_name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put the KV-pairs last

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would "Connected iface=" << interface_name << " bridge=" << bridge_name; fit here?
Or do you suggest something else for this case?

Copy link
Member

@Sohn123 Sohn123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it is fine now. Thanks for all the work you put in @linaScience What do you think @rgwohlbold ?

Copy link
Member

@rgwohlbold rgwohlbold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

@linaScience linaScience merged commit 323a448 into main Jul 18, 2023
@linaScience linaScience deleted the 23-improve-logging-structure branch July 18, 2023 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve logging structure
3 participants