Log using DLog and not on stdout in sessiond 52/279752/1
authorMateusz Majewski <m.majewski2@samsung.com>
Wed, 17 Aug 2022 07:08:43 +0000 (09:08 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 17 Aug 2022 07:09:25 +0000 (09:09 +0200)
Change-Id: Id9db6b275da9964c221bcf54d36fe717deecd29f

sessiond/CMakeLists.txt
sessiond/src/fs_helpers.cpp
sessiond/src/main.cpp
sessiond/src/wait_manager.hpp

index 88111e00a387f3871d6c506c6de5cd6085015ced..4c134c3c61610d194be08520ca71b265462db929 100644 (file)
@@ -1,7 +1,8 @@
 find_package(PkgConfig)
 pkg_check_modules(DEPS REQUIRED IMPORTED_TARGET
-    gio-2.0
-    libsmack
+       gio-2.0
+       libsmack
+       dlog
 )
 
 set(
index 2f8f2d1e52342a0f2884e2a5d05252739a5cd353..7bf4890cb50d0a1cb57319549b3ad011d608a9cf 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
+#undef LOG_TAG
+#define LOG_TAG "SESSIOND"
+#include <dlog.h>
+
 #include <grp.h>
 #include <pwd.h>
 #include <sys/smack.h>
@@ -179,9 +183,7 @@ bool fs_helpers::subsession_exists(const int session_uid, const std::string_view
        return fs::exists(subsession_path);
 }
 catch (std::exception const &ex) {
-       std::cerr << "Exception " << ex.what() << std::endl
-               << "while executing subsession_exists function [session_uid=" << session_uid
-               << " subsession_id=" << subsession_id << "]" << std::endl;
+       LOGE("Exception %s\nwhile executing subsession_exists function [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
        return false;
 }
 
@@ -244,15 +246,11 @@ void fs_helpers::add_user_subsession(const int session_uid, const std::string_vi
 
        }
        catch (std::system_error const &ex) {
-               std::cerr << "Logic exception " << ex.what() << std::endl
-                       << "while copying user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Logic exception %s\nwhile copying user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw;
        }
        catch (std::exception const &ex) {
-               std::cerr << "Exception " << ex.what() << std::endl
-                       << "while copying user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Exception %s\nwhile copying user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw std::runtime_error("Couldn't add user subsession data");
        }
 }
@@ -272,15 +270,11 @@ void fs_helpers::remove_user_subsession(const int session_uid, const std::string
                fs::remove_all(subsession_path);
        }
        catch (std::system_error const &ex) {
-               std::cerr << "Logic exception " << ex.what() << std::endl
-                       << "while removing user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Logic exception %s\nwhile removing user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw;
        }
        catch (std::exception const &ex) {
-               std::cerr << "Exception " << ex.what() << std::endl
-                       << "while removing user subsession data [session_uid=" << session_uid
-                       << " subsession_id=" << subsession_id << "]" << std::endl;
+               LOGE("Exception %s\nwhile removing user subsession data [session_uid=%d subsession_id=%s]", ex.what(), session_uid, subsession_id.data());
                throw std::runtime_error("Couldn't remove user subsession data");
        }
 }
@@ -318,9 +312,7 @@ std::vector<std::string> fs_helpers::get_user_list(const int session_uid) try
 } catch (std::runtime_error &ex) {
        return {};
 } catch (std::exception const &ex) {
-       std::cerr << "Exception " << ex.what() << std::endl
-               << "while enumerating user subsessions [session_uid="
-               << session_uid << "]" << std::endl;
+       LOGE("Exception %s\nwhile enumerating user subsessions [session_uid=%d]", ex.what(), session_uid);
        throw std::runtime_error("Couldn't enumerate user subsessions");
 }
 
index ba0c53517eee73237cf199f5c59285758c0e211b..4254e1723a1967fd0a19790e26e8d38a268bbec1 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
+#undef LOG_TAG
+#define LOG_TAG "SESSIOND"
+#include <dlog.h>
+
 #include <algorithm>
-#include <iostream>
 #include <unordered_map>
 
 #include <gio/gio.h>
@@ -78,7 +81,7 @@ struct owner_id {
        {
                inner = g_bus_own_name_on_connection(connection, name.data(), G_BUS_NAME_OWNER_FLAGS_NONE,
                        on_name_acquired, on_name_lost, user_data, nullptr);
-               std::cout << "Acquiring " << name << std::endl;
+               LOGD("Acquiring %s", name.data());
        }
 
        ~owner_id()
@@ -134,7 +137,7 @@ struct sessiond_context {
 
        void on_name_acquired()
        {
-               std::cout << "Bus name acquired" << std::endl;
+               LOGD("Bus name acquired");
        }
 
        void on_name_lost()
@@ -400,7 +403,7 @@ struct sessiond_context {
                });
                if (to_call == methods.end())
                        throw std::runtime_error(std::string("Unknown method ") + method_name + " called");
-               std::cout << "Handling " << method_name << " call from " << sender << std::endl;
+               LOGD("Handling %s call from %s", method_name, sender);
                (self->*(to_call->second))(invocation, std::string_view(sender), parameters);
        } catch (const std::invalid_argument &ex) {
                g_dbus_method_invocation_return_dbus_error(invocation,
@@ -432,9 +435,7 @@ struct sessiond_context {
        }
        static void log_exception(const std::exception &ex, std::string_view sender, std::string_view method_name)
        {
-               // TODO: use dlog instead
-               std::cerr << "Exception " << ex.what() << std::endl <<
-                       "while handling " << method_name << " call from " << sender << std::endl;
+               LOGE("Exception %s\nwhile handling %s call from %s", ex.what(), method_name.data(), sender.data());
        }
 
        constexpr static GDBusInterfaceVTable table = {
@@ -555,6 +556,6 @@ struct sessiond_context {
 int main() try {
        sessiond_context().run();
 } catch (const std::exception &ex) {
-       std::cerr << "Exception " << ex.what() << " caught in top scope! Bailing out..." << std::endl;
+       LOGE("Exception %s caught in top scope! Bailing out...", ex.what());
        return EXIT_FAILURE;
 }
index a4aed59772561ac16cc5b8a313cc3a5a5f79e7c5..5beb90fc6d9d2efd6e3f32909061c1bfa6f96624 100644 (file)
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE. */
 
+#undef LOG_TAG
+#define LOG_TAG "SESSIOND"
+#include <dlog.h>
+
 #include <algorithm>
 #include <exception>
 #include <iostream>
@@ -105,8 +109,7 @@ public:
                                finalize_if_empty(waiting_for.first, waiting_for.second.second);
                        }
                } catch (const std::exception &ex) {
-                       std::cerr << "Exception " << ex.what() << "\n" <<
-                               "while finalizing the wait manager\n";
+                       LOGE("Exception %s\nwhile finalizing the wait manager", ex.what());
                }
 
                for (auto &timeout : timeouts)
@@ -225,8 +228,7 @@ private:
                auto self = static_cast<wait_manager *>(user_data);
                self->on_client_disappeared(std::string(name));
        } catch (const std::exception &ex) {
-               std::cerr << "Exception " << ex.what() << "\n" <<
-                       "while handling " << name << " disappearing\n";
+               LOGE("Exception %s\nwhile handling %s disappearing", ex.what(), name);
        }
 
        struct timeout_data {
@@ -243,8 +245,7 @@ private:
                data->active = false;
                return G_SOURCE_REMOVE;
        } catch (const std::exception &ex) {
-               std::cerr << "Exception " << ex.what() << "\n" <<
-                       "while timeout\n";
+               LOGE("Exception %s\nwhile timeout", ex.what());
                return G_SOURCE_REMOVE;
        }