1
1
#include " modules/mpd.hpp"
2
2
3
3
#include < fmt/chrono.h>
4
- #include < iostream >
4
+ #include < spdlog/spdlog.h >
5
5
6
6
waybar::modules::MPD::MPD (const std::string& id, const Json::Value& config)
7
7
: ALabel(config, " {album} - {artist} - {title}" , 5 ),
@@ -14,11 +14,11 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
14
14
status_(nullptr, &mpd_status_free),
15
15
song_(nullptr, &mpd_song_free) {
16
16
if (!config_[" port" ].isNull() && !config_[" port" ].isUInt()) {
17
- std::cerr << module_name_ << " : `port` configuration should be an unsigned int " << std::endl ;
17
+ spdlog::warn( " {} : `port` configuration should be an unsigned int " , module_name_) ;
18
18
}
19
19
20
20
if (!config_[" timeout" ].isNull() && !config_[" timeout" ].isUInt()) {
21
- std::cerr << module_name_ << " : `timeout` configuration should be an unsigned int " << std::endl ;
21
+ spdlog::warn( " {} : `timeout` configuration should be an unsigned int " , module_name_) ;
22
22
}
23
23
24
24
label_.set_name(" mpd" );
@@ -28,7 +28,7 @@ waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config)
28
28
29
29
if (!config[" server" ].isNull()) {
30
30
if (!config_[" server" ].isString()) {
31
- std::cerr << module_name_ << " `server` configuration should be a string" << std::endl ;
31
+ spdlog::warn( " {}: `server` configuration should be a string" , module_name_) ;
32
32
}
33
33
server_ = config[" server" ].asCString();
34
34
}
@@ -51,7 +51,7 @@ auto waybar::modules::MPD::update() -> void {
51
51
periodic_updater().detach();
52
52
}
53
53
} catch (const std::exception& e) {
54
- std::cerr << module_name_ + " : " + e.what() << std::endl ;
54
+ spdlog::error( " {}: {} " , module_name_, e.what()) ;
55
55
state_ = MPD_STATE_UNKNOWN;
56
56
}
57
57
}
@@ -72,7 +72,7 @@ std::thread waybar::modules::MPD::event_listener() {
72
72
dp.emit();
73
73
}
74
74
} catch (const std::exception& e) {
75
- std::cerr << module_name_ + " : " + e.what() << std::endl ;
75
+ spdlog::warn( " {}: {} " , module_name_, e.what()) ;
76
76
}
77
77
}
78
78
});
@@ -206,12 +206,12 @@ std::string waybar::modules::MPD::getStateIcon() {
206
206
}
207
207
208
208
if (connection_ == nullptr) {
209
- std::cerr << module_name_ << " : Trying to fetch state icon while disconnected" << std::endl ;
209
+ spdlog::warn( " {} : Trying to fetch state icon while disconnected" , module_name_) ;
210
210
return " " ;
211
211
}
212
212
213
213
if (stopped()) {
214
- std::cerr << module_name_ << " : Trying to fetch state icon while stopped" << std::endl ;
214
+ spdlog::warn( " {} : Trying to fetch state icon while stopped" , module_name_) ;
215
215
return " " ;
216
216
}
217
217
@@ -228,7 +228,7 @@ std::string waybar::modules::MPD::getOptionIcon(std::string optionName, bool act
228
228
}
229
229
230
230
if (connection_ == nullptr) {
231
- std::cerr << module_name_ << " : Trying to fetch option icon while disconnected" << std::endl ;
231
+ spdlog::warn( " {} : Trying to fetch option icon while disconnected" , module_name_) ;
232
232
return " " ;
233
233
}
234
234
@@ -251,17 +251,17 @@ void waybar::modules::MPD::tryConnect() {
251
251
unique_connection(mpd_connection_new(server_, port_, timeout_), &mpd_connection_free);
252
252
253
253
if (connection_ == nullptr || alternate_connection_ == nullptr) {
254
- std::cerr << module_name_ << " : Failed to connect to MPD" << std::endl ;
254
+ spdlog::error( " {} : Failed to connect to MPD" , module_name_) ;
255
255
connection_.reset();
256
256
alternate_connection_.reset();
257
257
return;
258
258
}
259
259
260
260
try {
261
261
checkErrors(connection_.get());
262
- std::cerr << module_name_ << " : Connected to MPD" << std::endl ;
262
+ spdlog::info( " {} : Connected to MPD" , module_name_) ;
263
263
} catch (std::runtime_error& e) {
264
- std::cerr << module_name_ << " : Failed to connect to MPD: " << e.what() << std::endl ;
264
+ spdlog::error( " {} : Failed to connect to MPD: {} " , module_name_, e.what()) ;
265
265
connection_.reset();
266
266
alternate_connection_.reset();
267
267
}
0 commit comments