>From a06051ce5777d6af937181c96aa9ffcbd48971fd Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Fri, 18 Sep 2009 12:35:34 +0200
Subject: [PATCH] Use syslog for logging error conditions in SSSD

This is just a band-aid until ELAPI is fully functional and ready to
use.
---
 server/confdb/confdb.c                     |   36 +++---
 server/confdb/confdb_setup.c               |   24 ++--
 server/db/sysdb.c                          |   66 +++++-----
 server/db/sysdb_ops.c                      |   10 +-
 server/monitor/monitor.c                   |  185 ++++++++++++++-------------
 server/monitor/monitor_sbus.c              |   12 +-
 server/providers/data_provider.c           |   64 ++++++----
 server/providers/data_provider_be.c        |   76 ++++++-----
 server/providers/dp_auth_util.c            |   12 +-
 server/providers/krb5/krb5_auth.c          |    4 +-
 server/providers/ldap/ldap_id.c            |    4 +-
 server/providers/ldap/sdap.c               |   66 +++++-----
 server/providers/ldap/sdap_async.c         |    6 +-
 server/providers/proxy.c                   |   24 ++--
 server/responder/common/responder_common.c |   52 ++++----
 server/responder/common/responder_dp.c     |   24 ++--
 server/responder/nss/nsssrv.c              |   28 +++--
 server/responder/nss/nsssrv_cmd.c          |   52 ++++----
 server/responder/pam/pam_LOCAL_domain.c    |    2 +-
 server/responder/pam/pamsrv.c              |   14 ++-
 server/responder/pam/pamsrv_cache.c        |    2 +-
 server/responder/pam/pamsrv_cmd.c          |    6 +-
 server/responder/pam/pamsrv_dp.c           |   12 +-
 server/sbus/sssd_dbus_common.c             |    8 +-
 server/sbus/sssd_dbus_connection.c         |   10 +-
 server/tools/tools_util.c                  |    3 +
 server/util/debug.c                        |    1 +
 server/util/server.c                       |   34 +++---
 server/util/util.h                         |   16 +++
 29 files changed, 455 insertions(+), 398 deletions(-)

diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c
index 324946d..8cfdf95 100644
--- a/server/confdb/confdb.c
+++ b/server/confdb/confdb.c
@@ -658,15 +658,15 @@ int confdb_init(TALLOC_CTX *mem_ctx,
 
     ret = ldb_set_debug(cdb->ldb, ldb_debug_messages, NULL);
     if (ret != LDB_SUCCESS) {
-        DEBUG(0,("Could not set up debug fn.\n"));
+        SYSLOG_ERROR("Could not set up debug fn.\n");
         talloc_free(cdb);
         return EIO;
     }
 
     ret = ldb_connect(cdb->ldb, confdb_location, 0, NULL);
     if (ret != LDB_SUCCESS) {
-        DEBUG(0, ("Unable to open config database [%s]\n",
-                  confdb_location));
+        SYSLOG_ERROR("Unable to open config database [%s]\n",
+                     confdb_location);
         talloc_free(cdb);
         return EIO;
     }
@@ -739,7 +739,7 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
     }
 
     if (res->count != 1) {
-        DEBUG(0, ("Unknown domain [%s]\n", name));
+        SYSLOG_ERROR("Unknown domain [%s]\n", name);
         ret = ENOENT;
         goto done;
     }
@@ -752,7 +752,7 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
 
     tmp = ldb_msg_find_attr_as_string(res->msgs[0], "cn", NULL);
     if (!tmp) {
-        DEBUG(0, ("Invalid configuration entry, fatal error!\n"));
+        SYSLOG_ERROR("Invalid configuration entry, fatal error!\n");
         ret = EINVAL;
         goto done;
     }
@@ -771,8 +771,8 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
         }
     }
     else {
-        DEBUG(0, ("Domain [%s] does not specify a provider, disabling!\n",
-                  domain->name));
+        SYSLOG_ERROR("Domain [%s] does not specify a provider, disabling!\n",
+                     domain->name);
         ret = EINVAL;
         goto done;
     }
@@ -786,9 +786,9 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
      * superceeded. */
     val = ldb_msg_find_attr_as_int(res->msgs[0], "enumerate", 0);
     if (val > 0) { /* ok there was a number in here */
-        DEBUG(0, ("Warning: enumeration parameter in %s still uses integers! "
-                  "Enumeration is now a boolean and takes true/false values. "
-                  "Interpreting as true\n", domain->name));
+        SYSLOG_ERROR("Warning: enumeration parameter in %s still uses integers! "
+                     "Enumeration is now a boolean and takes true/false values. "
+                     "Interpreting as true\n", domain->name);
         domain->enumerate = true;
     } else { /* assume the new format */
         if (ldb_msg_find_attr_as_bool(res->msgs[0], "enumerate", 0)) {
@@ -814,7 +814,7 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
     ret = get_entry_as_uint32(res->msgs[0], &domain->id_min,
                               "minId", SSSD_MIN_ID);
     if (ret != EOK) {
-        DEBUG(0, ("Invalid value for minId\n"));
+        SYSLOG_ERROR("Invalid value for minId\n");
         ret = EINVAL;
         goto done;
     }
@@ -822,13 +822,13 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
     ret = get_entry_as_uint32(res->msgs[0], &domain->id_max,
                               "maxId", 0);
     if (ret != EOK) {
-        DEBUG(0, ("Invalid value for maxId\n"));
+        SYSLOG_ERROR("Invalid value for maxId\n");
         ret = EINVAL;
         goto done;
     }
 
     if (domain->id_max && (domain->id_max < domain->id_min)) {
-        DEBUG(0, ("Invalid domain range\n"));
+        SYSLOG_ERROR("Invalid domain range\n");
         ret = EINVAL;
         goto done;
     }
@@ -869,19 +869,19 @@ int confdb_get_domains(struct confdb_ctx *cdb,
     ret = confdb_get_string_as_list(cdb, tmp_ctx,
                                     CONFDB_DOMAINS_PATH, "domains", &domlist);
     if (ret == ENOENT) {
-        DEBUG(0, ("No domains configured, fatal error!\n"));
+        SYSLOG_ERROR("No domains configured, fatal error!\n");
         goto done;
     }
     if (ret != EOK ) {
-        DEBUG(0, ("Fatal error retrieving domains list!\n"));
+        SYSLOG_ERROR("Fatal error retrieving domains list!\n");
         goto done;
     }
 
     for (i = 0; domlist[i]; i++) {
         ret = confdb_get_domain_internal(cdb, cdb, domlist[i], &domain);
         if (ret) {
-            DEBUG(0, ("Error (%d [%s]) retrieving domain [%s], skipping!\n",
-                      ret, strerror(ret), domlist[i]));
+            SYSLOG_ERROR("Error (%d [%s]) retrieving domain [%s], skipping!\n",
+                         ret, strerror(ret), domlist[i]);
             ret = EOK;
             continue;
         }
@@ -896,7 +896,7 @@ int confdb_get_domains(struct confdb_ctx *cdb,
     }
 
     if (cdb->doms == NULL) {
-        DEBUG(0, ("No properly configured domains, fatal error!\n"));
+        SYSLOG_ERROR("No properly configured domains, fatal error!\n");
         ret = ENOENT;
         goto done;
     }
diff --git a/server/confdb/confdb_setup.c b/server/confdb/confdb_setup.c
index 00bba7f..3c2cb71 100644
--- a/server/confdb/confdb_setup.c
+++ b/server/confdb/confdb_setup.c
@@ -110,8 +110,8 @@ int confdb_create_base(struct confdb_ctx *cdb)
     while ((ldif = ldb_ldif_read_string(cdb->ldb, &base_ldif))) {
         ret = ldb_add(cdb->ldb, ldif->msg);
         if (ret != LDB_SUCCESS) {
-            DEBUG(0, ("Failed to initialize DB (%d,[%s]), aborting!\n",
-                      ret, ldb_errstring(cdb->ldb)));
+            SYSLOG_ERROR("Failed to initialize DB (%d,[%s]), aborting!\n",
+                         ret, ldb_errstring(cdb->ldb));
             return EIO;
         }
         ldb_ldif_read_free(cdb->ldb, ldif);
@@ -279,13 +279,13 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
     /* ok, first of all stat conf file */
     ret = stat(config_file, &cstat);
     if (ret != 0) {
-        DEBUG(0, ("Unable to stat config file [%s]! (%d [%s])\n",
-                  config_file, errno, strerror(errno)));
+        SYSLOG_ERROR("Unable to stat config file [%s]! (%d [%s])\n",
+                     config_file, errno, strerror(errno));
         return errno;
     }
     ret = snprintf(timestr, 21, "%llu", (long long unsigned)cstat.st_mtime);
     if (ret <= 0 || ret >= 21) {
-        DEBUG(0, ("Failed to convert time_t to string ??\n"));
+        SYSLOG_ERROR("Failed to convert time_t to string ??\n");
         return errno ? errno: EFAULT;
     }
 
@@ -303,7 +303,7 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
     /* Set up a transaction to replace the configuration */
     ret = ldb_transaction_start(cdb->ldb);
     if (ret != LDB_SUCCESS) {
-        DEBUG(0, ("Failed to start a transaction for updating the configuration\n"));
+        SYSLOG_ERROR("Failed to start a transaction for updating the configuration\n");
         talloc_free(tmp_ctx);
         return sysdb_error_to_errno(ret);
     }
@@ -311,7 +311,7 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
     /* Purge existing database */
     ret = confdb_purge(cdb);
     if (ret != EOK) {
-        DEBUG(0, ("Could not purge existing configuration\n"));
+        SYSLOG_ERROR("Could not purge existing configuration\n");
         goto done;
     }
 
@@ -319,8 +319,8 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
     ret = config_from_file("sssd", config_file, &sssd_config,
                            INI_STOP_ON_ANY, &error_list);
     if (ret != EOK) {
-        DEBUG(0, ("Parse error reading configuration file [%s]\n",
-                  config_file));
+        SYSLOG_ERROR("Parse error reading configuration file [%s]\n",
+                     config_file);
         print_file_parsing_errors(stderr, error_list);
         free_ini_config_errors(error_list);
         free_ini_config(sssd_config);
@@ -330,7 +330,7 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
     ret = confdb_create_ldif(tmp_ctx, sssd_config, &config_ldif);
     free_ini_config(sssd_config);
     if (ret != EOK) {
-        DEBUG(0, ("Could not create LDIF for confdb\n"));
+        SYSLOG_ERROR("Could not create LDIF for confdb\n");
         goto done;
     }
 
@@ -340,8 +340,8 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
     while ((ldif = ldb_ldif_read_string(cdb->ldb, (const char **)&config_ldif))) {
         ret = ldb_add(cdb->ldb, ldif->msg);
         if (ret != LDB_SUCCESS) {
-            DEBUG(0, ("Failed to initialize DB (%d,[%s]), aborting!\n",
-                      ret, ldb_errstring(cdb->ldb)));
+            SYSLOG_ERROR("Failed to initialize DB (%d,[%s]), aborting!\n",
+                         ret, ldb_errstring(cdb->ldb));
             ret = EIO;
             goto done;
         }
diff --git a/server/db/sysdb.c b/server/db/sysdb.c
index 87d0de9..b63a5a4 100644
--- a/server/db/sysdb.c
+++ b/server/db/sysdb.c
@@ -808,16 +808,16 @@ static int sysdb_upgrade_02(struct confdb_ctx *cdb,
         }
 
         if (strcmp(version, SYSDB_VERSION_0_2) != 0) {
-            DEBUG(0,("Wrong DB version [%s],"
-                     " expected [%s] for this upgrade!\n",
-                     version, SYSDB_VERSION));
+            SYSLOG_ERROR("Wrong DB version [%s],"
+                         " expected [%s] for this upgrade!\n",
+                         version, SYSDB_VERSION);
             ret = EINVAL;
             goto done;
         }
     }
     talloc_zfree(res);
 
-    DEBUG(0, ("UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_3));
+    SYSLOG_NOTICE("UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_3);
 
     /* ldb uses posix locks,
      * posix is stupid and kills all locks when you close *any* file
@@ -924,18 +924,18 @@ static int sysdb_upgrade_02(struct confdb_ctx *cdb,
 
             ret = ldb_add(ctx->ldb, msg);
             if (ret != LDB_SUCCESS) {
-                DEBUG(0, ("WARNING: Could not add entry %s,"
-                          " to new ldb file! (%d [%s])\n",
-                          ldb_dn_get_linearized(msg->dn),
-                          ret, ldb_errstring(ctx->ldb)));
+                SYSLOG_ERROR("WARNING: Could not add entry %s,"
+                             " to new ldb file! (%d [%s])\n",
+                             ldb_dn_get_linearized(msg->dn),
+                             ret, ldb_errstring(ctx->ldb));
             }
 
             ret = ldb_delete(local->ldb, msg->dn);
             if (ret != LDB_SUCCESS) {
-                DEBUG(0, ("WARNING: Could not remove entry %s,"
-                          " from old ldb file! (%d [%s])\n",
-                          ldb_dn_get_linearized(msg->dn),
-                          ret, ldb_errstring(local->ldb)));
+                SYSLOG_ERROR("WARNING: Could not remove entry %s,"
+                             " from old ldb file! (%d [%s])\n",
+                             ldb_dn_get_linearized(msg->dn),
+                             ret, ldb_errstring(local->ldb));
             }
         }
 
@@ -1129,8 +1129,8 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
             }
 
             if (!allow_upgrade) {
-                DEBUG(0, ("Wrong DB version (got %s expected %s)\n",
-                          version, SYSDB_VERSION));
+                SYSLOG_ERROR("Wrong DB version (got %s expected %s)\n",
+                             version, SYSDB_VERSION);
                 ret = EINVAL;
                 goto done;
             }
@@ -1144,8 +1144,8 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
             if (strcmp(version, SYSDB_VERSION_0_2) == 0) {
                 /* if this is not local we have a big problem */
                 if (strcasecmp(domain->provider, "local") != 0) {
-                    DEBUG(0, ("Fatal: providers other than 'local'"
-                              " shouldn't present v0.2, db corrupted?\n"));
+                    SYSLOG_ERROR("Fatal: providers other than 'local'"
+                                 " shouldn't present v0.2, db corrupted?\n");
                     ret = EFAULT;
                     goto done;
                 }
@@ -1155,9 +1155,9 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
                 if (need_02_upgrade) {
                     *need_02_upgrade = true;
                 } else {
-                    DEBUG(0, ("DB file seem to need an upgrade,"
-                              " but upgrade flag is not provided,"
-                              " db corrupted?\n"));
+                    SYSLOG_ERROR("DB file seem to need an upgrade,"
+                                 " but upgrade flag is not provided,"
+                                 " db corrupted?\n");
                     ret = EFAULT;
                     goto done;
                 }
@@ -1168,8 +1168,8 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
 
         }
 
-        DEBUG(0,("Unknown DB version [%s], expected [%s] for domain %s!\n",
-                 version?version:"not found", SYSDB_VERSION, domain->name));
+        SYSLOG_ERROR("Unknown DB version [%s], expected [%s] for domain %s!\n",
+                     version?version:"not found", SYSDB_VERSION, domain->name);
         ret = EINVAL;
         goto done;
     }
@@ -1180,8 +1180,8 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
     while ((ldif = ldb_ldif_read_string(ctx->ldb, &base_ldif))) {
         ret = ldb_add(ctx->ldb, ldif->msg);
         if (ret != LDB_SUCCESS) {
-            DEBUG(0, ("Failed to initialize DB (%d, [%s]) for domain %s!",
-                      ret, ldb_errstring(ctx->ldb), domain->name));
+            SYSLOG_ERROR("Failed to initialize DB (%d, [%s]) for domain %s!",
+                         ret, ldb_errstring(ctx->ldb), domain->name);
             ret = EIO;
             goto done;
         }
@@ -1208,8 +1208,8 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
     /* do a synchronous add */
     ret = ldb_add(ctx->ldb, msg);
     if (ret != LDB_SUCCESS) {
-        DEBUG(0, ("Failed to initialize DB (%d, [%s]) for domain %s!",
-                  ret, ldb_errstring(ctx->ldb), domain->name));
+        SYSLOG_ERROR("Failed to initialize DB (%d, [%s]) for domain %s!",
+                     ret, ldb_errstring(ctx->ldb), domain->name);
         ret = EIO;
         goto done;
     }
@@ -1236,8 +1236,8 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
     /* do a synchronous add */
     ret = ldb_add(ctx->ldb, msg);
     if (ret != LDB_SUCCESS) {
-        DEBUG(0, ("Failed to initialize DB (%d, [%s]) for domain %s!",
-                  ret, ldb_errstring(ctx->ldb), domain->name));
+        SYSLOG_ERROR("Failed to initialize DB (%d, [%s]) for domain %s!",
+                     ret, ldb_errstring(ctx->ldb), domain->name);
         ret = EIO;
         goto done;
     }
@@ -1264,8 +1264,8 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
     /* do a synchronous add */
     ret = ldb_add(ctx->ldb, msg);
     if (ret != LDB_SUCCESS) {
-        DEBUG(0, ("Failed to initialize DB (%d, [%s]) for domain %s!",
-                  ret, ldb_errstring(ctx->ldb), domain->name));
+        SYSLOG_ERROR("Failed to initialize DB (%d, [%s]) for domain %s!",
+                     ret, ldb_errstring(ctx->ldb), domain->name);
         ret = EIO;
         goto done;
     }
@@ -1360,10 +1360,10 @@ int sysdb_init(TALLOC_CTX *mem_ctx,
 
         ret = sysdb_upgrade_02(cdb, ev, ctx, ctx_list);
         if (ret != EOK) {
-            DEBUG(0, ("FATAL: Upgrade form db version %d failed!\n",
-                      SYSDB_VERSION_0_2));
-            DEBUG(0, ("You can find a backup of the database here: %s\n",
-                      backup_file));
+            SYSLOG_ERROR("FATAL: Upgrade form db version %s failed!\n",
+                         SYSDB_VERSION_0_2);
+            SYSLOG_ERROR("You can find a backup of the database "
+                         "in file named %s.bak", ctx->ldb_file);
             talloc_zfree(ctx_list);
             return ret;
         }
diff --git a/server/db/sysdb_ops.c b/server/db/sysdb_ops.c
index 3a53c9e..c0a4832 100644
--- a/server/db/sysdb_ops.c
+++ b/server/db/sysdb_ops.c
@@ -1352,8 +1352,8 @@ static void sysdb_get_new_id_base(struct tevent_req *subreq)
 
         if ((state->domain->id_max != 0) &&
             (state->new_id > state->domain->id_max)) {
-            DEBUG(0, ("Failed to allocate new id, out of range (%u/%u)\n",
-                      state->new_id, state->domain->id_max));
+            SYSLOG_ERROR("Failed to allocate new id, out of range (%u/%u)\n",
+                         state->new_id, state->domain->id_max);
             tevent_req_error(req, ERANGE);
             return;
         }
@@ -1484,8 +1484,8 @@ static void sysdb_get_new_id_verify(struct tevent_req *subreq)
         /* check again we are not falling out of range */
         if ((state->domain->id_max != 0) &&
             (state->new_id > state->domain->id_max)) {
-            DEBUG(0, ("Failed to allocate new id, out of range (%u/%u)\n",
-                      state->new_id, state->domain->id_max));
+            SYSLOG_ERROR("Failed to allocate new id, out of range (%u/%u)\n",
+                         state->new_id, state->domain->id_max);
             tevent_req_error(req, ERANGE);
             return;
         }
@@ -1733,7 +1733,7 @@ struct tevent_req *sysdb_add_user_send(TALLOC_CTX *mem_ctx,
 
     if (domain->mpg) {
         if (gid != 0) {
-            DEBUG(0, ("Cannot add user with arbitrary GID in MPG domain!\n"));
+            SYSLOG_ERROR("Cannot add user with arbitrary GID in MPG domain!\n");
             ERROR_OUT(ret, EINVAL, fail);
         }
         state->gid = state->uid;
diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c
index 44ce5f2..b052865 100644
--- a/server/monitor/monitor.c
+++ b/server/monitor/monitor.c
@@ -59,6 +59,8 @@
 #define MONITOR_DEF_PING_TIME 10
 #define MONITOR_CONF_ENTRY "config/services/monitor"
 
+#define PRG_NAME    "sssd"
+
 struct svc_spy;
 
 struct mt_svc {
@@ -197,7 +199,7 @@ static int client_registration(DBusMessage *message,
     data = sbus_conn_get_private_data(conn);
     mini = talloc_get_type(data, struct mon_init_conn);
     if (!mini) {
-        DEBUG(0, ("Connection holds no valid init data\n"));
+        SYSLOG_ERROR("Connection holds no valid init data\n");
         return EINVAL;
     }
 
@@ -230,8 +232,8 @@ static int client_registration(DBusMessage *message,
         svc = svc->next;
     }
     if (!svc) {
-        DEBUG(0, ("Unable to find peer [%s] in list of services,"
-                  " killing connection!\n", svc_name));
+        SYSLOG_ERROR("Unable to find peer [%s] in list of services,"
+                  " killing connection!\n", svc_name);
         sbus_disconnect(conn);
         /* FIXME: should we just talloc_zfree(conn) ? */
         goto done;
@@ -245,7 +247,7 @@ static int client_registration(DBusMessage *message,
      * try to access or even free, freed memory. */
     ret = add_svc_conn_spy(svc);
     if (ret) {
-        DEBUG(0, ("Failed to attch spy\n"));
+        SYSLOG_ERROR("Failed to attch spy\n");
         goto done;
     }
 
@@ -369,7 +371,7 @@ static void svc_try_restart(struct mt_svc *svc, time_t now)
 
     /* restart the process */
     if (svc->restarts > 3) { /* TODO: get val from config */
-        DEBUG(0, ("Process [%s], definitely stopped!\n", svc->name));
+        SYSLOG_ERROR("Process [%s], definitely stopped!\n", svc->name);
         talloc_free(svc);
         return;
     }
@@ -381,7 +383,7 @@ static void svc_try_restart(struct mt_svc *svc, time_t now)
 
     ret = start_service(svc, false);
     if (ret != EOK) {
-        DEBUG(0,("Failed to restart service '%s'\n", svc->name));
+        SYSLOG_ERROR("Failed to restart service '%s'\n", svc->name);
         talloc_free(svc);
         return;
     }
@@ -466,8 +468,8 @@ static void set_tasks_checker(struct mt_svc *svc)
     tv.tv_usec = 0;
     te = tevent_add_timer(svc->mt_ctx->ev, svc, tv, tasks_check_handler, svc);
     if (te == NULL) {
-        DEBUG(0, ("failed to add event, monitor offline for [%s]!\n",
-                  svc->name));
+        SYSLOG_ERROR("failed to add event, monitor offline for [%s]!\n",
+                     svc->name);
         /* FIXME: shutdown ? */
     }
     svc->ping_ev = te;
@@ -489,8 +491,8 @@ static void global_checks_handler(struct tevent_context *ev,
     }
 
     if (pid == -1) {
-        DEBUG(0, ("waitpid returned -1 (errno:%d[%s])\n",
-                  errno, strerror(errno)));
+        SYSLOG_ERROR("waitpid returned -1 (errno:%d[%s])\n",
+                     errno, strerror(errno));
         goto done;
     }
 
@@ -504,7 +506,7 @@ static void global_checks_handler(struct tevent_context *ev,
         }
     }
     if (svc == NULL) {
-        DEBUG(0, ("Unknown child (%d) did exit\n", pid));
+        SYSLOG_ERROR("Unknown child (%d) did exit\n", pid);
     }
 
 done:
@@ -521,7 +523,7 @@ static void set_global_checker(struct mt_ctx *ctx)
     tv.tv_usec = 0;
     te = tevent_add_timer(ctx->ev, ctx, tv, global_checks_handler, ctx);
     if (te == NULL) {
-        DEBUG(0, ("failed to add global checker event! PANIC TIME!\n"));
+        SYSLOG_ERROR("failed to add global checker event! PANIC TIME!\n");
         /* FIXME: is this right ? shoulkd we try to clean up first ?*/
         exit(-1);
     }
@@ -532,9 +534,9 @@ static int monitor_kill_service (struct mt_svc *svc)
     int ret;
     ret = kill(svc->pid, SIGTERM);
     if (ret != EOK) {
-        DEBUG(0,("Sending signal to child (%s:%d) failed! "
-                 "Ignore and pretend child is dead.\n",
-                 svc->name, svc->pid));
+        SYSLOG_ERROR("Sending signal to child (%s:%d) failed! "
+                     "Ignore and pretend child is dead.\n",
+                     svc->name, svc->pid);
     }
 
     return ret;
@@ -552,8 +554,8 @@ static void shutdown_reply(DBusPendingCall *pending, void *data)
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("A reply callback was called but no reply was received"
-                  " and no timeout occurred\n"));
+        SYSLOG_ERROR("A reply callback was called but no reply was received"
+                     " and no timeout occurred\n");
 
         /* Destroy this connection */
         monitor_kill_service(svc);
@@ -570,7 +572,7 @@ static void shutdown_reply(DBusPendingCall *pending, void *data)
         /* Something went wrong on the client side
          * Time to forcibly kill the service
          */
-        DEBUG(0, ("Received an error shutting down service.\n"));
+        SYSLOG_ERROR("Received an error shutting down service.\n");
         monitor_kill_service(svc);
     }
 
@@ -604,7 +606,7 @@ static int monitor_shutdown_service(struct mt_svc *svc)
                                        MONITOR_INTERFACE,
                                        MON_CLI_METHOD_SHUTDOWN);
     if (!msg) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         monitor_kill_service(svc);
         talloc_free(svc);
         return ENOMEM;
@@ -613,7 +615,7 @@ static int monitor_shutdown_service(struct mt_svc *svc)
     dbret = dbus_connection_send_with_reply(dbus_conn, msg, &pending_reply,
                                             svc->mt_ctx->service_id_timeout);
     if (!dbret || pending_reply == NULL) {
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         monitor_kill_service(svc);
         talloc_free(svc);
@@ -638,8 +640,8 @@ static void reload_reply(DBusPendingCall *pending, void *data)
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("A reply callback was called but no reply was received"
-                  " and no timeout occurred\n"));
+        SYSLOG_ERROR("A reply callback was called but no reply was received"
+                     " and no timeout occurred\n");
 
         /* Destroy this connection */
         sbus_disconnect(svc->conn);
@@ -663,7 +665,7 @@ static int monitor_signal_reconf(struct config_file_ctx *file_ctx,
     /* Update the confdb configuration */
     ret = confdb_init_db(filename, file_ctx->mt_ctx->cdb);
     if (ret != EOK) {
-        DEBUG(0, ("Could not reload configuration!"));
+        SYSLOG_ERROR("Could not reload configuration!");
         kill(getpid(), SIGTERM);
         return ret;
     }
@@ -719,7 +721,7 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal)
                                        MONITOR_INTERFACE,
                                        svc_signal);
     if (!msg) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         monitor_kill_service(svc);
         talloc_free(svc);
         return ENOMEM;
@@ -728,7 +730,7 @@ static int service_signal(struct mt_svc *svc, const char *svc_signal)
     dbret = dbus_connection_send_with_reply(dbus_conn, msg, &pending_reply,
                                             svc->mt_ctx->service_id_timeout);
     if (!dbret || pending_reply == NULL) {
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         monitor_kill_service(svc);
         talloc_free(svc);
@@ -854,12 +856,12 @@ int get_monitor_config(struct mt_ctx *ctx)
                                     SERVICE_CONF_ENTRY, "activeServices",
                                     &ctx->services);
     if (ret != EOK) {
-        DEBUG(0, ("No services configured!\n"));
+        SYSLOG_ERROR("No services configured\n");
         return EINVAL;
     }
     ret = append_data_provider(ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Could not add Data Provider to the list of services!\n"));
+        SYSLOG_ERROR("Could not add Data Provider to the list of services!\n");
         return ret;
     }
 
@@ -869,13 +871,13 @@ int get_monitor_config(struct mt_ctx *ctx)
     }
     ret = confdb_get_domains(ctx->cdb, &ctx->domains);
     if (ret != EOK) {
-        DEBUG(0, ("No domains configured.\n"));
+        SYSLOG_ERROR("No domains configured.\n");
         return ret;
     }
 
     ret = check_local_domain_unique(ctx->domains);
     if (ret != EOK) {
-        DEBUG(0, ("More than one local domain configured.\n"));
+        SYSLOG_ERROR("More than one local domain configured.\n");
         return ret;
     }
 
@@ -924,7 +926,7 @@ static int get_service_config(struct mt_ctx *ctx, const char *name,
     ret = confdb_get_string(ctx->cdb, svc, path, "command",
                             NULL, &svc->command);
     if (ret != EOK) {
-        DEBUG(0,("Failed to start service '%s'\n", svc->name));
+        SYSLOG_ERROR("Failed to start service '%s'\n", svc->name);
         talloc_free(svc);
         return ret;
     }
@@ -944,7 +946,7 @@ static int get_service_config(struct mt_ctx *ctx, const char *name,
     ret = confdb_get_int(ctx->cdb, svc, path, "timeout",
                          MONITOR_DEF_PING_TIME, &svc->ping_time);
     if (ret != EOK) {
-        DEBUG(0,("Failed to start service '%s'\n", svc->name));
+        SYSLOG_ERROR("Failed to start service '%s'\n", svc->name);
         talloc_free(svc);
         return ret;
     }
@@ -964,7 +966,7 @@ static int add_new_service(struct mt_ctx *ctx, const char *name, bool startup)
 
     ret = start_service(svc, startup);
     if (ret != EOK) {
-        DEBUG(0,("Failed to start service '%s'\n", svc->name));
+        SYSLOG_ERROR("Failed to start service '%s'\n", svc->name);
         talloc_free(svc);
     }
 
@@ -1009,7 +1011,7 @@ static int get_provider_config(struct mt_ctx *ctx, const char *name,
     ret = confdb_get_string(ctx->cdb, svc, path,
                             "provider", NULL, &svc->provider);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to find provider from [%s] configuration\n", name));
+        SYSLOG_ERROR("Failed to find provider from [%s] configuration\n", name);
         talloc_free(svc);
         return ret;
     }
@@ -1017,7 +1019,7 @@ static int get_provider_config(struct mt_ctx *ctx, const char *name,
     ret = confdb_get_string(ctx->cdb, svc, path,
                             "command", NULL, &svc->command);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to find command from [%s] configuration\n", name));
+        SYSLOG_ERROR("Failed to find command from [%s] configuration\n", name);
         talloc_free(svc);
         return ret;
     }
@@ -1025,7 +1027,7 @@ static int get_provider_config(struct mt_ctx *ctx, const char *name,
     ret = confdb_get_int(ctx->cdb, svc, path, "timeout",
                          MONITOR_DEF_PING_TIME, &svc->ping_time);
     if (ret != EOK) {
-        DEBUG(0,("Failed to start service '%s'\n", svc->name));
+        SYSLOG_ERROR("Failed to start service '%s'\n", svc->name);
         talloc_free(svc);
         return ret;
     }
@@ -1062,14 +1064,14 @@ static int add_new_provider(struct mt_ctx *ctx, const char *name, bool startup)
 
     ret = get_provider_config(ctx, name, &svc);
     if (ret != EOK) {
-        DEBUG(0, ("Could not get provider configuration for [%s]\n",
-                  name));
+        SYSLOG_ERROR("Could not get provider configuration for [%s]\n",
+                  name);
         return ret;
     }
 
     ret = start_service(svc, startup);
     if (ret != EOK) {
-        DEBUG(0,("Failed to start service '%s'\n", svc->name));
+        SYSLOG_ERROR("Failed to start service '%s'\n", svc->name);
         talloc_free(svc);
     }
 
@@ -1095,8 +1097,7 @@ static void remove_service(struct mt_ctx *ctx, const char *name)
         /* Shut it down */
         ret = monitor_shutdown_service(cur_svc);
         if (ret != EOK) {
-            DEBUG(0, ("Unable to shut down service [%s]!",
-                      name));
+            SYSLOG_ERROR("Unable to shut down service [%s]!", name);
             /* TODO: Handle this better */
         }
     }
@@ -1158,7 +1159,7 @@ static int update_monitor_config(struct mt_ctx *ctx)
                     break;
             }
             if (cur_svc == NULL) {
-                DEBUG(0, ("Service entry missing data\n"));
+                SYSLOG_ERROR("Service entry missing data\n");
                 /* This shouldn't be possible, but if it happens
                  * we'll throw an error
                  */
@@ -1171,9 +1172,9 @@ static int update_monitor_config(struct mt_ctx *ctx)
              */
             ret = get_service_config(ctx, new_config->services[i], &new_svc);
             if (ret != EOK) {
-                DEBUG(0, ("Unable to determine if service has changed.\n"));
-                DEBUG(0, ("Disabling service [%s].\n",
-                          new_config->services[i]));
+                SYSLOG_ERROR("Unable to determine if service has changed.\n");
+                SYSLOG_ERROR("Disabling service [%s].\n",
+                             new_config->services[i]);
                 /* Not much we can do here, no way to know whether the
                  * current configuration is safe, and restarting the
                  * service won't work because the new startup requires
@@ -1246,7 +1247,7 @@ static int update_monitor_config(struct mt_ctx *ctx)
                 cur_svc = cur_svc->next;
             }
             if (cur_svc == NULL) {
-                DEBUG(0, ("Service entry missing data for [%s]\n", new_dom->name));
+                SYSLOG_ERROR("Service entry missing data for [%s]\n", new_dom->name);
                 /* This shouldn't be possible
                  */
                 talloc_free(new_config);
@@ -1258,9 +1259,9 @@ static int update_monitor_config(struct mt_ctx *ctx)
              */
             ret = get_provider_config(ctx, new_dom->name, &new_svc);
             if (ret != EOK) {
-                DEBUG(0, ("Unable to determine if service has changed.\n"));
-                DEBUG(0, ("Disabling service [%s].\n",
-                          new_config->services[i]));
+                SYSLOG_ERROR("Unable to determine if service has changed.\n");
+                SYSLOG_ERROR("Disabling service [%s].\n",
+                             new_config->services[i]);
                 /* Not much we can do here, no way to know whether the
                  * current configuration is safe, and restarting the
                  * service won't work because the new startup requires
@@ -1337,12 +1338,15 @@ static int monitor_cleanup(void)
     ret = unlink(file);
     if (ret == -1) {
         ret = errno;
-        DEBUG(0, ("Error removing pidfile! (%d [%s])\n",
-                ret, strerror(ret)));
+        SYSLOG_ERROR("Error removing pidfile! (%d [%s])\n",
+                     ret, strerror(ret));
         talloc_free(file);
         return errno;
     }
 
+    /* close syslog */
+    closelog();
+
     talloc_free(file);
     return EOK;
 }
@@ -1358,7 +1362,7 @@ static void monitor_quit(struct tevent_context *ev,
 
 #if HAVE_GETPGRP
     if (getpgrp() == getpid()) {
-        DEBUG(0,("%s: killing children\n", strsignal(signum)));
+        SYSLOG_NOTICE("%s: killing children\n", strsignal(signum));
         kill(-getpgrp(), SIGTERM);
     }
 #endif
@@ -1376,8 +1380,8 @@ int read_config_file(const char *config_file)
     ret = config_from_file("sssd", config_file, &sssd_config,
                            INI_STOP_ON_ANY, &error_list);
     if (ret != EOK) {
-        DEBUG(0, ("Parse error reading configuration file [%s]\n",
-                  config_file));
+        SYSLOG_ERROR("Parse error reading configuration file [%s]\n",
+                     config_file)
         print_file_parsing_errors(stderr, error_list);
     }
 
@@ -1401,14 +1405,14 @@ static errno_t load_configuration(TALLOC_CTX *mem_ctx,
 
     cdb_file = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
     if (cdb_file == NULL) {
-        DEBUG(0,("Out of memory, aborting!\n"));
+        SYSLOG_ERROR("Out of memory, aborting!\n");
         ret = ENOMEM;
         goto done;
     }
 
     ret = confdb_init(ctx, &ctx->cdb, cdb_file);
     if (ret != EOK) {
-        DEBUG(0,("The confdb initialization failed\n"));
+        SYSLOG_ERROR("The confdb initialization failed\n");
         goto done;
     }
 
@@ -1425,26 +1429,26 @@ static errno_t load_configuration(TALLOC_CTX *mem_ctx,
 
         ret = confdb_init(ctx, &ctx->cdb, cdb_file);
         if (ret != EOK) {
-            DEBUG(0,("The confdb initialization failed\n"));
+            SYSLOG_ERROR("The confdb initialization failed\n");
             goto done;
         }
 
         /* Load special entries */
         ret = confdb_create_base(ctx->cdb);
         if (ret != EOK) {
-            DEBUG(0, ("Unable to load special entries into confdb\n"));
+            SYSLOG_ERROR("Unable to load special entries into confdb\n");
             goto done;
         }
     } else if (ret != EOK) {
-        DEBUG(0, ("Fatal error initializing confdb\n"));
+        SYSLOG_ERROR("Fatal error initializing confdb\n");
         goto done;
     }
     talloc_zfree(cdb_file);
 
     ret = confdb_init_db(config_file, ctx->cdb);
     if (ret != EOK) {
-        DEBUG(0, ("ConfDB initialization has failed [%s]\n",
-              strerror(ret)));
+        SYSLOG_ERROR("ConfDB initialization has failed [%s]\n",
+                     strerror(ret))
         goto done;
     }
 
@@ -1496,7 +1500,7 @@ static void config_file_changed(struct tevent_context *ev,
 
     te = tevent_add_timer(ev, ev, tv, process_config_file, file_ctx);
     if (!te) {
-        DEBUG(0, ("Unable to queue config file update! Exiting."));
+        SYSLOG_ERROR("Unable to queue config file update! Exiting.");
         kill(getpid(), SIGTERM);
         return;
     }
@@ -1543,7 +1547,7 @@ static void process_config_file(struct tevent_context *ev,
         len = read(file_ctx->mt_ctx->inotify_fd, buf+total_len,
                    event_size-total_len);
         if (len == -1 && errno != EINTR) {
-            DEBUG(0, ("Critical error reading inotify file descriptor.\n"));
+            SYSLOG_ERROR("Critical error reading inotify file descriptor.\n");
             talloc_free(tmp_ctx);
             return;
         }
@@ -1565,7 +1569,7 @@ static void process_config_file(struct tevent_context *ev,
         while (total_len < in_event->len) {
             len = read(file_ctx->mt_ctx->inotify_fd, &name, in_event->len);
             if (len == -1 && errno != EINTR) {
-                DEBUG(0, ("Critical error reading inotify file descriptor.\n"));
+                SYSLOG_ERROR("Critical error reading inotify file descriptor.\n");
                 talloc_free(tmp_ctx);
                 return;
             }
@@ -1581,7 +1585,7 @@ static void process_config_file(struct tevent_context *ev,
         }
     }
     if (!cb) {
-        DEBUG(0, ("Unknown watch descriptor\n"));
+        SYSLOG_ERROR("Unknown watch descriptor\n");
         return;
     }
 
@@ -1600,7 +1604,7 @@ static void process_config_file(struct tevent_context *ev,
         cb->retries = 0;
         rw_ctx = talloc(file_ctx, struct rewatch_ctx);
         if(!rw_ctx) {
-            DEBUG(0, ("Could not restore inotify watch. Quitting!\n"));
+            SYSLOG_ERROR("Could not restore inotify watch. Quitting!\n");
             close(file_ctx->mt_ctx->inotify_fd);
             kill(getpid(), SIGTERM);
             return;
@@ -1610,7 +1614,7 @@ static void process_config_file(struct tevent_context *ev,
 
         tev = tevent_add_timer(ev, rw_ctx, tv, rewatch_config_file, rw_ctx);
         if (te == NULL) {
-            DEBUG(0, ("Could not restore inotify watch. Quitting!\n"));
+            SYSLOG_ERROR("Could not restore inotify watch. Quitting!\n");
             close(file_ctx->mt_ctx->inotify_fd);
             kill(getpid(), SIGTERM);
         }
@@ -1642,7 +1646,7 @@ static void rewatch_config_file(struct tevent_context *ev,
     /* Retry six times at five-second intervals before giving up */
     cb->retries++;
     if (cb->retries > 6) {
-        DEBUG(0, ("Could not restore inotify watch. Quitting!\n"));
+        SYSLOG_ERROR("Could not restore inotify watch. Quitting!\n");
         close(file_ctx->mt_ctx->inotify_fd);
         kill(getpid(), SIGTERM);
     }
@@ -1660,7 +1664,7 @@ static void rewatch_config_file(struct tevent_context *ev,
 
         tev = tevent_add_timer(ev, ev, tv, rewatch_config_file, rw_ctx);
         if (te == NULL) {
-            DEBUG(0, ("Could not restore inotify watch. Quitting!\n"));
+            SYSLOG_ERROR("Could not restore inotify watch. Quitting!\n");
             close(file_ctx->mt_ctx->inotify_fd);
             kill(getpid(), SIGTERM);
         }
@@ -1693,8 +1697,8 @@ static void poll_config_file(struct tevent_context *ev,
         ret = stat(cb->filename, &file_stat);
         if (ret < 0) {
             err = errno;
-            DEBUG(0, ("Could not stat file [%s]. Error [%d:%s]\n",
-                      cb->filename, err, strerror(err)));
+            SYSLOG_ERROR("Could not stat file [%s]. Error [%d:%s]\n",
+                         cb->filename, err, strerror(err))
             /* TODO: If the config file is missing, should we shut down? */
             return;
         }
@@ -1718,7 +1722,7 @@ static void poll_config_file(struct tevent_context *ev,
     file_ctx->timer = tevent_add_timer(ev, file_ctx->parent_ctx, tv,
                              poll_config_file, file_ctx);
     if (!file_ctx->timer) {
-        DEBUG(0, ("Error: Config file no longer monitored for changes!"));
+        SYSLOG_ERROR("Error: Config file no longer monitored for changes!");
     }
 }
 
@@ -1736,8 +1740,8 @@ static int try_inotify(struct config_file_ctx *file_ctx, const char *filename,
         file_ctx->mt_ctx->inotify_fd = inotify_init();
         if (file_ctx->mt_ctx->inotify_fd < 0) {
             err = errno;
-            DEBUG(0, ("Could not initialize inotify, error [%d:%s]\n",
-                      err, strerror(err)));
+            SYSLOG_ERROR("Could not initialize inotify, error [%d:%s]\n",
+                      err, strerror(err))
             return err;
         }
 
@@ -1782,8 +1786,8 @@ static int try_inotify(struct config_file_ctx *file_ctx, const char *filename,
                                cb->filename, IN_MODIFY);
     if (cb->wd < 0) {
         err = errno;
-        DEBUG(0, ("Could not add inotify watch for file [%s]. Error [%d:%s]\n",
-                  cb->filename, err, strerror(err)));
+        SYSLOG_ERROR("Could not add inotify watch for file [%s]. Error [%d:%s]\n",
+                     cb->filename, err, strerror(err))
         close(file_ctx->mt_ctx->inotify_fd);
         return err;
     }
@@ -1810,8 +1814,8 @@ static int monitor_config_file(TALLOC_CTX *mem_ctx,
     ret = stat(file, &file_stat);
     if (ret < 0) {
         err = errno;
-        DEBUG(0, ("Could not stat file [%s]. Error [%d:%s]\n",
-                  file, err, strerror(err)));
+        SYSLOG_ERROR("Could not stat file [%s]. Error [%d:%s]\n",
+                     file, err, strerror(err))
         return err;
     }
     if (!ctx->file_ctx) {
@@ -1968,7 +1972,7 @@ static int monitor_service_init(struct sbus_connection *conn, void *data)
 
     mini = talloc(conn, struct mon_init_conn);
     if (!mini) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         talloc_zfree(conn);
         return ENOMEM;
     }
@@ -1980,7 +1984,7 @@ static int monitor_service_init(struct sbus_connection *conn, void *data)
 
     mini->timeout = tevent_add_timer(ctx->ev, mini, tv, init_timeout, mini);
     if (!mini->timeout) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         talloc_zfree(conn);
         return ENOMEM;
     }
@@ -2022,7 +2026,7 @@ static int service_send_ping(struct mt_svc *svc)
                                        MONITOR_INTERFACE,
                                        MON_CLI_METHOD_PING);
     if (!msg) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         talloc_zfree(svc->conn);
         return ENOMEM;
     }
@@ -2035,7 +2039,7 @@ static int service_send_ping(struct mt_svc *svc)
          * We can't communicate on this connection
          * We'll drop it using the default destructor.
          */
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         talloc_zfree(svc->conn);
         return EIO;
     }
@@ -2062,8 +2066,8 @@ static void ping_check(DBusPendingCall *pending, void *data)
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("A reply callback was called but no reply was received"
-                  " and no timeout occurred\n"));
+        SYSLOG_ERROR("A reply callback was called but no reply was received"
+                  " and no timeout occurred\n");
 
         /* Destroy this connection */
         sbus_disconnect(svc->conn);
@@ -2089,8 +2093,8 @@ static void ping_check(DBusPendingCall *pending, void *data)
         if (strcmp(dbus_error_name, DBUS_ERROR_TIMEOUT) == 0)
             break;
 
-        DEBUG(0,("A service PING returned an error [%s], closing connection.\n",
-                 dbus_error_name));
+        SYSLOG_ERROR("A service PING returned an error [%s], closing connection.\n",
+                     dbus_error_name);
         /* Falling through to default intentionally*/
     default:
         /*
@@ -2135,7 +2139,7 @@ static int service_check_alive(struct mt_svc *svc)
     if (WIFEXITED(status)) { /* children exited on it's own */
         /* TODO: check configuration to see if it was removed
          * from the list of process to run */
-        DEBUG(0,("Process [%s] exited\n", svc->name));
+        SYSLOG_NOTICE("Process [%s] exited\n", svc->name);
     }
 
     return ECHILD;
@@ -2272,7 +2276,7 @@ static int start_service(struct mt_svc *svc, bool startup)
     te = tevent_add_timer(svc->mt_ctx->ev, svc, tv,
                           service_startup_handler, svc);
     if (te == NULL) {
-        DEBUG(0, ("Unable to queue service %s for startup\n", svc->name));
+        SYSLOG_ERROR("Unable to queue service %s for startup\n", svc->name);
         return ENOMEM;
     }
     return EOK;
@@ -2310,7 +2314,7 @@ static void service_startup_handler(struct tevent_context *ev,
     mt_svc->pid = fork();
     if (mt_svc->pid != 0) {
         if (mt_svc->pid == -1) {
-            DEBUG(0, ("Could not fork child to start service [%s]. Continuing.\n", mt_svc->name))
+            SYSLOG_ERROR("Could not fork child to start service [%s]. Continuing.\n", mt_svc->name);
             return;
         }
 
@@ -2330,7 +2334,7 @@ static void service_startup_handler(struct tevent_context *ev,
 
     /* If we are here, exec() has failed
      * Print errno and abort quickly */
-    DEBUG(0,("Could not exec %s, reason: %s\n", mt_svc->command, strerror(errno)));
+    SYSLOG_ERROR("Could not exec %s, reason: %s\n", mt_svc->command, strerror(errno));
 
     /* We have to call _exit() instead of exit() here
      * because a bug in D-BUS will cause the server to
@@ -2409,6 +2413,9 @@ int main(int argc, const char *argv[])
     /* we want a pid file check */
     flags |= FLAGS_PID_FILE;
 
+    /* enable syslog logging */
+    openlog(PRG_NAME, LOG_PID, LOG_DAEMON);
+
     /* Parse config file, fail if cannot be done */
     ret = load_configuration(tmp_ctx, config_file, &monitor);
     if (ret != EOK) return 4;
diff --git a/server/monitor/monitor_sbus.c b/server/monitor/monitor_sbus.c
index 9995986..6e9a0e0 100644
--- a/server/monitor/monitor_sbus.c
+++ b/server/monitor/monitor_sbus.c
@@ -74,8 +74,8 @@ static void id_callback(DBusPendingCall *pending, void *ptr)
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("Severe error. A reply callback was called but no"
-                  " reply was received and no timeout occurred\n"));
+        SYSLOG_ERROR("Severe error. A reply callback was called but no"
+                  " reply was received and no timeout occurred\n");
 
         /* FIXME: Destroy this connection ? */
         goto done;
@@ -99,8 +99,8 @@ static void id_callback(DBusPendingCall *pending, void *ptr)
         break;
 
     case DBUS_MESSAGE_TYPE_ERROR:
-        DEBUG(0,("The Monitor returned an error [%s]\n",
-                 dbus_message_get_error_name(reply)));
+        SYSLOG_ERROR("The Monitor returned an error [%s]\n",
+                     dbus_message_get_error_name(reply));
         /* Falling through to default intentionally*/
     default:
         /*
@@ -136,7 +136,7 @@ int monitor_common_send_id(struct sbus_connection *conn,
                                        MON_SRV_INTERFACE,
                                        MON_SRV_METHOD_REGISTER);
     if (msg == NULL) {
-        DEBUG(0, ("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         return ENOMEM;
     }
 
@@ -159,7 +159,7 @@ int monitor_common_send_id(struct sbus_connection *conn,
          * We can't communicate on this connection
          * We'll drop it using the default destructor.
          */
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         return EIO;
     }
diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c
index f8efcc8..f4affd1 100644
--- a/server/providers/data_provider.c
+++ b/server/providers/data_provider.c
@@ -43,6 +43,8 @@
 
 #define DP_CONF_ENTRY "config/services/dp"
 
+#define PRG_NAME    "sssd"
+
 struct dp_backend;
 struct dp_frontend;
 
@@ -151,7 +153,7 @@ static int dp_monitor_init(struct dp_ctx *dpctx)
     /* Set up SBUS connection to the monitor */
     ret = monitor_get_sbus_address(dpctx, dpctx->cdb, &sbus_address);
     if (ret != EOK) {
-        DEBUG(0, ("Could not locate monitor address.\n"));
+        SYSLOG_ERROR("Could not locate monitor address.\n");
         return ret;
     }
 
@@ -159,7 +161,7 @@ static int dp_monitor_init(struct dp_ctx *dpctx)
                            &monitor_dp_interface, &conn,
                            NULL, NULL);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to connect to monitor services.\n"));
+        SYSLOG_ERROR("Failed to connect to monitor services.\n");
         return ret;
     }
 
@@ -168,7 +170,7 @@ static int dp_monitor_init(struct dp_ctx *dpctx)
                                  DATA_PROVIDER_SERVICE_NAME,
                                  DATA_PROVIDER_VERSION);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to identify to the monitor!\n"));
+        SYSLOG_ERROR("Failed to identify to the monitor!\n");
         return ret;
     }
 
@@ -202,7 +204,7 @@ static int dp_client_init(struct sbus_connection *conn, void *data)
 
     dpcli = talloc(conn, struct dp_client);
     if (!dpcli) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         talloc_zfree(conn);
         return ENOMEM;
     }
@@ -216,7 +218,7 @@ static int dp_client_init(struct sbus_connection *conn, void *data)
     dpcli->timeout = tevent_add_timer(dpctx->ev, dpcli,
                                       tv, init_timeout, dpcli);
     if (!dpcli->timeout) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         talloc_zfree(conn);
         return ENOMEM;
     }
@@ -248,7 +250,7 @@ static int client_registration(DBusMessage *message,
     data = sbus_conn_get_private_data(conn);
     dpcli = talloc_get_type(data, struct dp_client);
     if (!dpcli) {
-        DEBUG(0, ("Connection holds no valid init data\n"));
+        SYSLOG_ERROR("Connection holds no valid init data\n");
         return EINVAL;
     }
 
@@ -276,14 +278,14 @@ static int client_registration(DBusMessage *message,
     case DP_CLI_BACKEND:
         dpbe = talloc_zero(dpcli->dpctx, struct dp_backend);
         if (!dpbe) {
-            DEBUG(0, ("Out of memory!\n"));
+            SYSLOG_ERROR("Out of memory!\n");
             sbus_disconnect(conn);
             return ENOMEM;
         }
 
         dpbe->domain = talloc_strdup(dpbe, cli_domain);
         if (!dpbe->domain) {
-            DEBUG(0, ("Out of memory!\n"));
+            SYSLOG_ERROR("Out of memory!\n");
             sbus_disconnect(conn);
             return ENOMEM;
         }
@@ -300,14 +302,14 @@ static int client_registration(DBusMessage *message,
     case DP_CLI_FRONTEND:
         dpfe = talloc_zero(dpcli->dpctx, struct dp_frontend);
         if (!dpfe) {
-            DEBUG(0, ("Out of memory!\n"));
+            SYSLOG_ERROR("Out of memory!\n");
             sbus_disconnect(conn);
             return ENOMEM;
         }
 
         dpfe->name = talloc_strdup(dpfe, cli_name);
         if (!dpfe->name) {
-            DEBUG(0, ("Out of memory!\n"));
+            SYSLOG_ERROR("Out of memory!\n");
             sbus_disconnect(conn);
             return ENOMEM;
         }
@@ -330,7 +332,7 @@ static int client_registration(DBusMessage *message,
     /* reply that all is ok */
     reply = dbus_message_new_method_return(message);
     if (!reply) {
-        DEBUG(0, ("Dbus Out of memory!\n"));
+        SYSLOG_ERROR("Dbus Out of memory!\n");
         return ENOMEM;
     }
 
@@ -338,7 +340,7 @@ static int client_registration(DBusMessage *message,
                                      DBUS_TYPE_UINT16, &version,
                                      DBUS_TYPE_INVALID);
     if (!dbret) {
-        DEBUG(0, ("Failed to build dbus reply\n"));
+        SYSLOG_ERROR("Failed to build dbus reply\n");
         dbus_message_unref(reply);
         sbus_disconnect(conn);
         return EIO;
@@ -373,7 +375,7 @@ static void be_got_account_info(DBusPendingCall *pending, void *data)
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("Severe error. A reply callback was called but no reply was received and no timeout occurred\n"));
+        SYSLOG_ERROR("Severe error. A reply callback was called but no reply was received and no timeout occurred\n");
 
         /* Destroy this connection */
         sbus_disconnect(bereq->be->dpcli->conn);
@@ -402,8 +404,8 @@ static void be_got_account_info(DBusPendingCall *pending, void *data)
         break;
 
     case DBUS_MESSAGE_TYPE_ERROR:
-        DEBUG(0,("The Data Provider returned an error [%s], closing connection.\n",
-                 dbus_message_get_error_name(reply)));
+        SYSLOG_ERROR("The Data Provider returned an error [%s], closing connection.\n",
+                     dbus_message_get_error_name(reply));
         /* Falling through to default intentionally*/
     default:
         /*
@@ -468,7 +470,7 @@ static int dp_send_acct_req(struct dp_be_request *bereq,
                                        DP_CLI_INTERFACE,
                                        DP_CLI_METHOD_GETACCTINFO);
     if (msg == NULL) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         return ENOMEM;
     }
 
@@ -492,7 +494,7 @@ static int dp_send_acct_req(struct dp_be_request *bereq,
          * We can't communicate on this connection
          * We'll drop it using the default destructor.
          */
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         return EIO;
     }
@@ -688,7 +690,7 @@ static void be_got_pam_reply(DBusPendingCall *pending, void *data)
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("Severe error. A reply callback was called but no reply was received and no timeout occurred\n"));
+        SYSLOG_ERROR("Severe error. A reply callback was called but no reply was received and no timeout occurred\n");
 
         /* Destroy this connection */
         sbus_disconnect(bereq->be->dpcli->conn);
@@ -715,8 +717,8 @@ static void be_got_pam_reply(DBusPendingCall *pending, void *data)
         break;
 
     case DBUS_MESSAGE_TYPE_ERROR:
-        DEBUG(0,("The Data Provider returned an error [%s], closing connection.\n",
-                 dbus_message_get_error_name(reply)));
+        SYSLOG_ERROR("The Data Provider returned an error [%s], closing connection.\n",
+                     dbus_message_get_error_name(reply));
         /* Falling through to default intentionally*/
     default:
         /*
@@ -765,7 +767,7 @@ static int dp_call_pamhandler(struct dp_be_request *bereq, struct pam_data *pd)
                                        DP_CLI_INTERFACE,
                                        DP_CLI_METHOD_PAMHANDLER);
     if (msg == NULL) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         return ENOMEM;
     }
 
@@ -786,7 +788,7 @@ static int dp_call_pamhandler(struct dp_be_request *bereq, struct pam_data *pd)
          * We can't communicate on this connection
          * We'll drop it using the default destructor.
          */
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         return EIO;
     }
@@ -827,7 +829,7 @@ static int dp_pamhandler(DBusMessage *message, struct sbus_connection *conn)
 
     ret = dp_unpack_pam_request(message, pd, &dbus_error);
     if (!ret) {
-        DEBUG(0,("Failed, to parse message!\n"));
+        SYSLOG_ERROR("Failed, to parse message!\n");
         if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
         talloc_free(pd);
         return EIO;
@@ -838,7 +840,7 @@ static int dp_pamhandler(DBusMessage *message, struct sbus_connection *conn)
 
     reply = dbus_message_new_method_return(message);
     if (!reply) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         talloc_free(pd);
         return ENOMEM;
     }
@@ -964,7 +966,7 @@ static int dp_process_init(TALLOC_CTX *mem_ctx,
 
     dpctx = talloc_zero(mem_ctx, struct dp_ctx);
     if (!dpctx) {
-        DEBUG(0, ("fatal error initializing dp_ctx\n"));
+        SYSLOG_ERROR("fatal error initializing dp_ctx\n");
         return ENOMEM;
     }
     dpctx->ev = ev;
@@ -972,13 +974,13 @@ static int dp_process_init(TALLOC_CTX *mem_ctx,
 
     ret = dp_monitor_init(dpctx);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error setting up monitor bus\n"));
+        SYSLOG_ERROR("fatal error setting up monitor bus\n");
         return ret;
     }
 
     ret = dp_srv_init(dpctx);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error setting up server bus\n"));
+        SYSLOG_ERROR("fatal error setting up server bus\n");
         return ret;
     }
 
@@ -1011,8 +1013,11 @@ int main(int argc, const char *argv[])
 
 	poptFreeContext(pc);
 
+    /* enable syslog logging */
+    openlog(PRG_NAME, LOG_PID, LOG_DAEMON);
+
     /* set up things like debug , signals, daemonization, etc... */
-    ret = server_setup("sssd[dp]", 0, DP_CONF_ENTRY, &main_ctx);
+    ret = server_setup(PRG_NAME, 0, DP_CONF_ENTRY, &main_ctx);
     if (ret != EOK) return 2;
 
     ret = die_if_parent_died();
@@ -1029,6 +1034,9 @@ int main(int argc, const char *argv[])
     /* loop on main */
     server_loop(main_ctx);
 
+    /* close syslog */
+    closelog();
+
     return 0;
 }
 
diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c
index 2e83ab6..b8630e6 100644
--- a/server/providers/data_provider_be.c
+++ b/server/providers/data_provider_be.c
@@ -516,7 +516,7 @@ static int mon_cli_init(struct be_ctx *ctx)
     /* Set up SBUS connection to the monitor */
     ret = monitor_get_sbus_address(ctx, ctx->cdb, &sbus_address);
     if (ret != EOK) {
-        DEBUG(0, ("Could not locate monitor address.\n"));
+        SYSLOG_ERROR("Could not locate monitor address.\n");
         return ret;
     }
 
@@ -524,7 +524,7 @@ static int mon_cli_init(struct be_ctx *ctx)
                            &monitor_be_interface, &ctx->mon_conn,
                            NULL, ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to connect to monitor services.\n"));
+        SYSLOG_ERROR("Failed to connect to monitor services.\n");
         return ret;
     }
 
@@ -533,7 +533,7 @@ static int mon_cli_init(struct be_ctx *ctx)
                                  ctx->identity,
                                  DATA_PROVIDER_VERSION);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to identify to the monitor!\n"));
+        SYSLOG_ERROR("Failed to identify to the monitor!\n");
         return ret;
     }
 
@@ -552,7 +552,7 @@ static int be_cli_init(struct be_ctx *ctx)
     /* Set up SBUS connection to the monitor */
     ret = dp_get_sbus_address(ctx, ctx->cdb, &sbus_address);
     if (ret != EOK) {
-        DEBUG(0, ("Could not locate monitor address.\n"));
+        SYSLOG_ERROR("Could not locate monitor address.\n");
         return ret;
     }
 
@@ -560,7 +560,7 @@ static int be_cli_init(struct be_ctx *ctx)
                            &be_interface, &ctx->dp_conn,
                            NULL, ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to connect to monitor services.\n"));
+        SYSLOG_ERROR("Failed to connect to monitor services.\n");
         return ret;
     }
 
@@ -569,7 +569,7 @@ static int be_cli_init(struct be_ctx *ctx)
                             DP_CLI_BACKEND, DATA_PROVIDER_VERSION,
                             "", ctx->domain->name);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to identify to the data provider!\n"));
+        SYSLOG_ERROR("Failed to identify to the data provider!\n");
         return ret;
     }
 
@@ -577,7 +577,7 @@ static int be_cli_init(struct be_ctx *ctx)
     ret = confdb_get_int(ctx->cdb, ctx, SERVICE_CONF_ENTRY,
                          "reconnection_retries", 3, &max_retries);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to set up automatic reconnection\n"));
+        SYSLOG_ERROR("Failed to set up automatic reconnection\n");
         return ret;
     }
 
@@ -604,20 +604,20 @@ static void be_cli_reconnect_init(struct sbus_connection *conn, int status, void
                                 DP_CLI_BACKEND, DATA_PROVIDER_VERSION,
                                 "", be_ctx->domain->name);
         if (ret != EOK) {
-            DEBUG(0, ("Failed to send id to the data provider!\n"));
+            SYSLOG_ERROR("Failed to send id to the data provider!\n");
         } else {
             return;
         }
     }
 
     /* Handle failure */
-    DEBUG(0, ("Could not reconnect to data provider.\n"));
+    SYSLOG_ERROR("Could not reconnect to data provider.\n");
 
     /* Kill the backend and let the monitor restart it */
     ret = be_finalize(be_ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Finalizing back-end failed with error [%d] [%s]\n",
-                  ret, strerror(ret)));
+        SYSLOG_ERROR("Finalizing back-end failed with error [%d] [%s]\n",
+                     ret, strerror(ret));
         be_shutdown(NULL, ret, NULL);
     }
 }
@@ -629,8 +629,8 @@ static void be_shutdown(struct be_req *req, int status, const char *errstr)
         exit(0);
 
     /* Something went wrong in finalize */
-    DEBUG(0, ("Finalizing auth module failed with error [%d] [%s]\n",
-              status, errstr ? : strerror(status)));
+    SYSLOG_ERROR("Finalizing auth module failed with error [%d] [%s]\n",
+                 status, errstr ? : strerror(status));
 
     exit(1);
 }
@@ -643,8 +643,8 @@ static void be_id_shutdown(struct be_req *req, int status, const char *errstr)
 
     if (status != EOK) {
         /* Something went wrong in finalize */
-        DEBUG(0, ("Finalizing auth module failed with error [%d] [%s]\n",
-                  status, errstr ? : strerror(status)));
+        SYSLOG_ERROR("Finalizing auth module failed with error [%d] [%s]\n",
+                     status, errstr ? : strerror(status));
     }
 
     ctx = req->be_ctx;
@@ -690,7 +690,7 @@ static int be_finalize(struct be_ctx *ctx)
 
 fail:
     /* If we got here, we couldn't shut down cleanly. */
-    DEBUG(0, ("ERROR: could not shut down cleanly.\n"));
+    SYSLOG_ERROR("ERROR: could not shut down cleanly.\n");
     return ret;
 }
 
@@ -784,8 +784,8 @@ static int load_backend_module(struct be_ctx *ctx,
         DEBUG(7, ("Loading backend [%s] with path [%s].\n", mod_name, path));
         handle = dlopen(path, RTLD_NOW);
         if (!handle) {
-            DEBUG(0, ("Unable to load %s module with path (%s), error: %s\n",
-                      mod_name, path, dlerror()));
+            SYSLOG_ERROR("Unable to load %s module with path (%s), error: %s\n",
+                         mod_name, path, dlerror());
             ret = ELIBACC;
             goto done;
         }
@@ -797,16 +797,16 @@ static int load_backend_module(struct be_ctx *ctx,
     mod_init_fn = (bet_init_fn_t)dlsym(ctx->loaded_be[lb].handle,
                                            mod_init_fn_name);
     if (mod_init_fn == NULL) {
-        DEBUG(0, ("Unable to load init fn %s from module %s, error: %s\n",
-                  mod_init_fn_name, mod_name, dlerror()));
+        SYSLOG_ERROR("Unable to load init fn %s from module %s, error: %s\n",
+                     mod_init_fn_name, mod_name, dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ret = mod_init_fn(ctx, be_ops, be_pvt_data);
     if (ret != EOK) {
-        DEBUG(0, ("Error (%d) in module (%s) initialization (%s)!\n",
-                  ret, mod_name, mod_init_fn_name));
+        SYSLOG_ERROR("Error (%d) in module (%s) initialization (%s)!\n",
+                     ret, mod_name, mod_init_fn_name);
         goto done;
     }
 
@@ -877,7 +877,7 @@ int be_process_init(TALLOC_CTX *mem_ctx,
 
     ctx = talloc_zero(mem_ctx, struct be_ctx);
     if (!ctx) {
-        DEBUG(0, ("fatal error initializing be_ctx\n"));
+        SYSLOG_ERROR("fatal error initializing be_ctx\n");
         return ENOMEM;
     }
     ctx->ev = ev;
@@ -885,37 +885,37 @@ int be_process_init(TALLOC_CTX *mem_ctx,
     ctx->identity = talloc_asprintf(ctx, "%%BE_%s", be_domain);
     ctx->conf_path = talloc_asprintf(ctx, "config/domains/%s", be_domain);
     if (!ctx->identity || !ctx->conf_path) {
-        DEBUG(0, ("Out of memory!?\n"));
+        SYSLOG_ERROR("Out of memory!?\n");
         return ENOMEM;
     }
 
     ret = confdb_get_domain(cdb, be_domain, &ctx->domain);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error retrieving domain configuration\n"));
+        SYSLOG_ERROR("fatal error retrieving domain configuration\n");
         return ret;
     }
 
     ret = sysdb_domain_init(ctx, ev, ctx->domain, DB_PATH, &ctx->sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error opening cache database\n"));
+        SYSLOG_ERROR("fatal error opening cache database\n");
         return ret;
     }
 
     ret = mon_cli_init(ctx);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error setting up monitor bus\n"));
+        SYSLOG_ERROR("fatal error setting up monitor bus\n");
         return ret;
     }
 
     ret = be_cli_init(ctx);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error setting up server bus\n"));
+        SYSLOG_ERROR("fatal error setting up server bus\n");
         return ret;
     }
 
     ret = be_rewrite(ctx);
     if (ret != EOK) {
-        DEBUG(0, ("error rewriting provider types\n"));
+        SYSLOG_ERROR("error rewriting provider types\n");
         return ret;
     }
 
@@ -923,7 +923,7 @@ int be_process_init(TALLOC_CTX *mem_ctx,
                               &ctx->bet_info[BET_ID].bet_ops,
                               &ctx->bet_info[BET_ID].pvt_bet_data);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error initializing data providers\n"));
+        SYSLOG_ERROR("fatal error initializing data providers\n");
         return ret;
     }
 
@@ -932,7 +932,7 @@ int be_process_init(TALLOC_CTX *mem_ctx,
                               &ctx->bet_info[BET_AUTH].pvt_bet_data);
     if (ret != EOK) {
         if (ret != ENOENT) {
-            DEBUG(0, ("fatal error initializing data providers\n"));
+            SYSLOG_ERROR("fatal error initializing data providers\n");
             return ret;
         }
         DEBUG(1, ("No authentication module provided for [%s] !!\n",
@@ -944,7 +944,7 @@ int be_process_init(TALLOC_CTX *mem_ctx,
                               &ctx->bet_info[BET_ACCESS].pvt_bet_data);
     if (ret != EOK) {
         if (ret != ENOENT) {
-            DEBUG(0, ("fatal error initializing data providers\n"));
+            SYSLOG_ERROR("fatal error initializing data providers\n");
             return ret;
         }
         DEBUG(1, ("No access control module provided for [%s] "
@@ -958,7 +958,7 @@ int be_process_init(TALLOC_CTX *mem_ctx,
                               &ctx->bet_info[BET_CHPASS].pvt_bet_data);
     if (ret != EOK) {
         if (ret != ENOENT) {
-            DEBUG(0, ("fatal error initializing data providers\n"));
+            SYSLOG_ERROR("fatal error initializing data providers\n");
             return ret;
         }
         DEBUG(1, ("No change password module provided for [%s] !!\n",
@@ -1012,9 +1012,12 @@ int main(int argc, const char *argv[])
     conf_entry = talloc_asprintf(NULL, BE_CONF_ENTRY, be_domain);
     if (!conf_entry) return 2;
 
+    /* enable syslog logging */
+    openlog(srv_name, LOG_PID, LOG_DAEMON);
+
     ret = server_setup(srv_name, 0, conf_entry, &main_ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Could not set up mainloop [%d]\n", ret));
+        SYSLOG_ERROR("Could not set up mainloop [%d]\n", ret);
         return 2;
     }
 
@@ -1029,7 +1032,7 @@ int main(int argc, const char *argv[])
                           main_ctx->event_ctx,
                           main_ctx->confdb_ctx);
     if (ret != EOK) {
-        DEBUG(0, ("Could not initialize backend [%d]\n", ret));
+        SYSLOG_ERROR("Could not initialize backend [%d]\n", ret);
         return 3;
     }
 
@@ -1038,6 +1041,9 @@ int main(int argc, const char *argv[])
     /* loop on main */
     server_loop(main_ctx);
 
+    /* close syslog */
+    closelog();
+
     return 0;
 }
 
diff --git a/server/providers/dp_auth_util.c b/server/providers/dp_auth_util.c
index 80e9f16..8bfa084 100644
--- a/server/providers/dp_auth_util.c
+++ b/server/providers/dp_auth_util.c
@@ -241,8 +241,8 @@ static void id_callback(DBusPendingCall *pending, void *ptr)
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("Severe error. A reply callback was called but no"
-                  " reply was received and no timeout occurred\n"));
+        SYSLOG_ERROR("Severe error. A reply callback was called but no"
+                     " reply was received and no timeout occurred\n");
 
         /* FIXME: Destroy this connection ? */
         goto done;
@@ -266,8 +266,8 @@ static void id_callback(DBusPendingCall *pending, void *ptr)
         break;
 
     case DBUS_MESSAGE_TYPE_ERROR:
-        DEBUG(0,("The Monitor returned an error [%s]\n",
-                 dbus_message_get_error_name(reply)));
+        SYSLOG_ERROR("The Monitor returned an error [%s]\n",
+                     dbus_message_get_error_name(reply));
         /* Falling through to default intentionally*/
     default:
         /*
@@ -304,7 +304,7 @@ int dp_common_send_id(struct sbus_connection *conn,
                                        DP_SRV_INTERFACE,
                                        DP_SRV_METHOD_REGISTER);
     if (msg == NULL) {
-        DEBUG(0, ("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         return ENOMEM;
     }
 
@@ -330,7 +330,7 @@ int dp_common_send_id(struct sbus_connection *conn,
          * We can't communicate on this connection
          * We'll drop it using the default destructor.
          */
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         return EIO;
     }
diff --git a/server/providers/krb5/krb5_auth.c b/server/providers/krb5/krb5_auth.c
index 03e7903..0eac91f 100644
--- a/server/providers/krb5/krb5_auth.c
+++ b/server/providers/krb5/krb5_auth.c
@@ -793,11 +793,11 @@ static void krb5_pam_handler_done(struct tevent_req *req)
                 }
                 break;
             default:
-                DEBUG(0, ("unsupported PAM command [%d].\n", pd->cmd));
+                SYSLOG_ERROR("unsupported PAM command [%d].\n", pd->cmd);
         }
 
         if (password == NULL) {
-            DEBUG(0, ("password not available, offline auth may not work.\n"));
+            SYSLOG_ERROR("password not available, offline auth may not work.\n");
             goto done;
         }
 
diff --git a/server/providers/ldap/ldap_id.c b/server/providers/ldap/ldap_id.c
index 72caf96..bd376f7 100644
--- a/server/providers/ldap/ldap_id.c
+++ b/server/providers/ldap/ldap_id.c
@@ -873,7 +873,7 @@ static void ldap_id_enumerate_set_timer(struct sdap_id_ctx *ctx,
     tv = tevent_timeval_add(&tv, ert, 0);
     enum_task = tevent_add_timer(ctx->be->ev, ctx, tv, ldap_id_enumerate, ctx);
     if (!enum_task) {
-        DEBUG(0, ("FATAL: failed to setup enumeration task!\n"));
+        SYSLOG_ERROR("FATAL: failed to setup enumeration task!\n");
         /* shutdown! */
         exit(1);
     }
@@ -1354,7 +1354,7 @@ int sssm_ldap_init(struct be_ctx *bectx,
         enum_task = tevent_add_timer(ctx->be->ev, ctx, ctx->last_run,
                                  ldap_id_enumerate, ctx);
         if (!enum_task) {
-            DEBUG(0, ("FATAL: failed to setup enumeration task!\n"));
+            SYSLOG_ERROR("FATAL: failed to setup enumeration task!\n");
             ret = EFAULT;
             goto done;
         }
diff --git a/server/providers/ldap/sdap.c b/server/providers/ldap/sdap.c
index 22d238e..7edcc3d 100644
--- a/server/providers/ldap/sdap.c
+++ b/server/providers/ldap/sdap.c
@@ -148,8 +148,8 @@ int sdap_get_options(TALLOC_CTX *memctx,
             if (ret != EOK ||
                 ((opts->basic[i].def_val.string != NULL) &&
                  (opts->basic[i].val.string == NULL))) {
-                DEBUG(0, ("Failed to retrieve value for option (%s)\n",
-                          opts->basic[i].opt_name));
+                SYSLOG_ERROR("Failed to retrieve value for option (%s)\n",
+                             opts->basic[i].opt_name);
                 if (ret == EOK) ret = EINVAL;
                 goto done;
             }
@@ -162,8 +162,8 @@ int sdap_get_options(TALLOC_CTX *memctx,
                                     opts->basic[i].opt_name,
                                     NULL, &tmp);
             if (ret != EOK) {
-                DEBUG(0, ("Failed to retrieve value for option (%s)\n",
-                          opts->basic[i].opt_name));
+                SYSLOG_ERROR("Failed to retrieve value for option (%s)\n",
+                             opts->basic[i].opt_name);
                 goto done;
             }
 
@@ -186,8 +186,8 @@ int sdap_get_options(TALLOC_CTX *memctx,
                                  opts->basic[i].def_val.number,
                                  &opts->basic[i].val.number);
             if (ret != EOK) {
-                DEBUG(0, ("Failed to retrieve value for option (%s)\n",
-                          opts->basic[i].opt_name));
+                SYSLOG_ERROR("Failed to retrieve value for option (%s)\n",
+                             opts->basic[i].opt_name);
                 goto done;
             }
             DEBUG(6, ("Option %s has value %d\n",
@@ -200,8 +200,8 @@ int sdap_get_options(TALLOC_CTX *memctx,
                                   opts->basic[i].def_val.boolean,
                                   &opts->basic[i].val.boolean);
             if (ret != EOK) {
-                DEBUG(0, ("Failed to retrieve value for option (%s)\n",
-                          opts->basic[i].opt_name));
+                SYSLOG_ERROR("Failed to retrieve value for option (%s)\n",
+                             opts->basic[i].opt_name);
                 goto done;
             }
             DEBUG(6, ("Option %s is %s\n",
@@ -223,7 +223,7 @@ int sdap_get_options(TALLOC_CTX *memctx,
         default_user_map = rfc2307bis_user_map;
         default_group_map = rfc2307bis_group_map;
     } else {
-        DEBUG(0, ("Unrecognized schema type: %s\n", schema));
+        SYSLOG_ERROR("Unrecognized schema type: %s\n", schema);
         ret = EINVAL;
         goto done;
     }
@@ -240,8 +240,8 @@ int sdap_get_options(TALLOC_CTX *memctx,
                                 &opts->user_map[i].name);
         if (ret != EOK ||
             (opts->user_map[i].def_name && !opts->user_map[i].name)) {
-            DEBUG(0, ("Failed to retrieve a value (%s)\n",
-                      opts->user_map[i].opt_name));
+            SYSLOG_ERROR("Failed to retrieve a value (%s)\n",
+                         opts->user_map[i].opt_name);
             if (ret != EOK) ret = EINVAL;
             goto done;
         }
@@ -262,8 +262,8 @@ int sdap_get_options(TALLOC_CTX *memctx,
                                 &opts->group_map[i].name);
         if (ret != EOK ||
             (opts->group_map[i].def_name && !opts->group_map[i].name)) {
-            DEBUG(0, ("Failed to retrieve a value (%s)\n",
-                      opts->group_map[i].opt_name));
+            SYSLOG_ERROR("Failed to retrieve a value (%s)\n",
+                         opts->group_map[i].opt_name);
             if (ret != EOK) ret = EINVAL;
             goto done;
         }
@@ -301,10 +301,10 @@ const char *_sdap_go_get_cstring(struct sdap_gen_opts *opts,
                                  int id, const char *location)
 {
     if (opts[id].type != SDAP_STRING) {
-        DEBUG(0, ("[%s] Requested type 'String' for option '%s'"
-                  " but value is of type '%s'!\n",
-                  location, opts[id].opt_name,
-                  sdap_type_to_string(opts[id].type)));
+        SYSLOG_ERROR("[%s] Requested type 'String' for option '%s'"
+                     " but value is of type '%s'!\n",
+                     location, opts[id].opt_name,
+                     sdap_type_to_string(opts[id].type));
         return NULL;
     }
     return opts[id].val.cstring;
@@ -314,10 +314,10 @@ char *_sdap_go_get_string(struct sdap_gen_opts *opts,
                           int id, const char *location)
 {
     if (opts[id].type != SDAP_STRING) {
-        DEBUG(0, ("[%s] Requested type 'String' for option '%s'"
-                  " but value is of type '%s'!\n",
-                  location, opts[id].opt_name,
-                  sdap_type_to_string(opts[id].type)));
+        SYSLOG_ERROR("[%s] Requested type 'String' for option '%s'"
+                     " but value is of type '%s'!\n",
+                     location, opts[id].opt_name,
+                     sdap_type_to_string(opts[id].type));
         return NULL;
     }
     return opts[id].val.string;
@@ -328,10 +328,10 @@ struct sdap_blob _sdap_go_get_blob(struct sdap_gen_opts *opts,
 {
     struct sdap_blob null_blob = { NULL, 0 };
     if (opts[id].type != SDAP_BLOB) {
-        DEBUG(0, ("[%s] Requested type 'Blob' for option '%s'"
-                  " but value is of type '%s'!\n",
-                  location, opts[id].opt_name,
-                  sdap_type_to_string(opts[id].type)));
+        SYSLOG_ERROR("[%s] Requested type 'Blob' for option '%s'"
+                     " but value is of type '%s'!\n",
+                     location, opts[id].opt_name,
+                     sdap_type_to_string(opts[id].type));
         return null_blob;
     }
     return opts[id].val.blob;
@@ -341,10 +341,10 @@ int _sdap_go_get_int(struct sdap_gen_opts *opts,
                      int id, const char *location)
 {
     if (opts[id].type != SDAP_NUMBER) {
-        DEBUG(0, ("[%s] Requested type 'Number' for option '%s'"
-                  " but value is of type '%s'!\n",
-                  location, opts[id].opt_name,
-                  sdap_type_to_string(opts[id].type)));
+        SYSLOG_ERROR("[%s] Requested type 'Number' for option '%s'"
+                     " but value is of type '%s'!\n",
+                     location, opts[id].opt_name,
+                     sdap_type_to_string(opts[id].type));
         return 0;
     }
     return opts[id].val.number;
@@ -354,10 +354,10 @@ bool _sdap_go_get_bool(struct sdap_gen_opts *opts,
                        int id, const char *location)
 {
     if (opts[id].type != SDAP_BOOL) {
-        DEBUG(0, ("[%s] Requested type 'Boolean' for option '%s'"
-                  " but value is of type '%s'!\n",
-                  location, opts[id].opt_name,
-                  sdap_type_to_string(opts[id].type)));
+        SYSLOG_ERROR("[%s] Requested type 'Boolean' for option '%s'"
+                     " but value is of type '%s'!\n",
+                     location, opts[id].opt_name,
+                     sdap_type_to_string(opts[id].type));
         return false;
     }
     return opts[id].val.boolean;
diff --git a/server/providers/ldap/sdap_async.c b/server/providers/ldap/sdap_async.c
index 6ab8867..f50750a 100644
--- a/server/providers/ldap/sdap_async.c
+++ b/server/providers/ldap/sdap_async.c
@@ -1350,7 +1350,7 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
                 continue;
             }
             if (mu > mg) { /* shouldn't be possible */
-                DEBUG(0, ("Fatal Internal error: aborting\n"));
+                SYSLOG_ERROR("Fatal Internal error: aborting\n");
                 ret = EFAULT;
                 goto fail;
             }
@@ -1369,8 +1369,8 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
         break;
 
     default:
-        DEBUG(0, ("FATAL ERROR: Unhandled schema type! (%d)\n",
-                  opts->schema_type));
+        SYSLOG_ERROR("FATAL ERROR: Unhandled schema type! (%d)\n",
+                     opts->schema_type);
         ret = EFAULT;
         goto fail;
     }
diff --git a/server/providers/proxy.c b/server/providers/proxy.c
index 80a2a55..22717e8 100644
--- a/server/providers/proxy.c
+++ b/server/providers/proxy.c
@@ -2227,78 +2227,78 @@ int sssm_proxy_init(struct be_ctx *bectx,
 
     handle = dlopen(libpath, RTLD_NOW);
     if (!handle) {
-        DEBUG(0, ("Unable to load %s module with path, error: %s\n",
-                  libpath, dlerror()));
+        SYSLOG_ERROR("Unable to load %s module with path, error: %s\n",
+                     libpath, dlerror());
         ret = ELIBACC;
         goto done;
     }
 
     ctx->ops.getpwnam_r = proxy_dlsym(handle, "_nss_%s_getpwnam_r", libname);
     if (!ctx->ops.getpwnam_r) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.getpwuid_r = proxy_dlsym(handle, "_nss_%s_getpwuid_r", libname);
     if (!ctx->ops.getpwuid_r) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.setpwent = proxy_dlsym(handle, "_nss_%s_setpwent", libname);
     if (!ctx->ops.setpwent) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.getpwent_r = proxy_dlsym(handle, "_nss_%s_getpwent_r", libname);
     if (!ctx->ops.getpwent_r) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.endpwent = proxy_dlsym(handle, "_nss_%s_endpwent", libname);
     if (!ctx->ops.endpwent) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.getgrnam_r = proxy_dlsym(handle, "_nss_%s_getgrnam_r", libname);
     if (!ctx->ops.getgrnam_r) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.getgrgid_r = proxy_dlsym(handle, "_nss_%s_getgrgid_r", libname);
     if (!ctx->ops.getgrgid_r) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.setgrent = proxy_dlsym(handle, "_nss_%s_setgrent", libname);
     if (!ctx->ops.setgrent) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.getgrent_r = proxy_dlsym(handle, "_nss_%s_getgrent_r", libname);
     if (!ctx->ops.getgrent_r) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
 
     ctx->ops.endgrent = proxy_dlsym(handle, "_nss_%s_endgrent", libname);
     if (!ctx->ops.endgrent) {
-        DEBUG(0, ("Failed to load NSS fns, error: %s\n", dlerror()));
+        SYSLOG_ERROR("Failed to load NSS fns, error: %s\n", dlerror());
         ret = ELIBBAD;
         goto done;
     }
diff --git a/server/responder/common/responder_common.c b/server/responder/common/responder_common.c
index 57c8678..119a1dd 100644
--- a/server/responder/common/responder_common.c
+++ b/server/responder/common/responder_common.c
@@ -72,7 +72,7 @@ static void client_send(struct tevent_context *ev, struct cli_ctx *cctx)
         return;
     }
     if (ret != EOK) {
-        DEBUG(0, ("Failed to read request, aborting client!\n"));
+        SYSLOG_ERROR("Failed to read request, aborting client!\n");
         talloc_free(cctx);
         return;
     }
@@ -92,7 +92,7 @@ static void client_recv(struct tevent_context *ev, struct cli_ctx *cctx)
     if (!cctx->creq) {
         cctx->creq = talloc_zero(cctx, struct cli_request);
         if (!cctx->creq) {
-            DEBUG(0, ("Failed to alloc request, aborting client!\n"));
+            SYSLOG_ERROR("Failed to alloc request, aborting client!\n");
             talloc_free(cctx);
             return;
         }
@@ -102,7 +102,7 @@ static void client_recv(struct tevent_context *ev, struct cli_ctx *cctx)
         ret = sss_packet_new(cctx->creq, SSS_PACKET_MAX_RECV_SIZE,
                              0, &cctx->creq->in);
         if (ret != EOK) {
-            DEBUG(0, ("Failed to alloc request, aborting client!\n"));
+            SYSLOG_ERROR("Failed to alloc request, aborting client!\n");
             talloc_free(cctx);
             return;
         }
@@ -116,7 +116,7 @@ static void client_recv(struct tevent_context *ev, struct cli_ctx *cctx)
         /* execute command */
         ret = sss_cmd_execute(cctx, cctx->rctx->sss_cmds);
         if (ret != EOK) {
-            DEBUG(0, ("Failed to execute request, aborting client!\n"));
+            SYSLOG_ERROR("Failed to execute request, aborting client!\n");
             talloc_free(cctx);
         }
         /* past this point cctx can be freed at any time by callbacks
@@ -193,7 +193,7 @@ static void accept_priv_fd_handler(struct tevent_context *ev,
     if (!cctx) {
         struct sockaddr_un addr;
         int fd;
-        DEBUG(0, ("Out of memory trying to setup client context on privileged pipe!\n"));
+        SYSLOG_ERROR("Out of memory trying to setup client context on privileged pipe!\n");
         /* accept and close to signal the client we have a problem */
         memset(&addr, 0, sizeof(addr));
         len = sizeof(addr);
@@ -246,7 +246,7 @@ static void accept_fd_handler(struct tevent_context *ev,
     if (!cctx) {
         struct sockaddr_un addr;
         int fd;
-        DEBUG(0, ("Out of memory trying to setup client context!\n"));
+        SYSLOG_ERROR("Out of memory trying to setup client context!\n");
         /* accept and close to signal the client we have a problem */
         memset(&addr, 0, sizeof(addr));
         len = sizeof(addr);
@@ -295,7 +295,7 @@ static int sss_monitor_init(struct resp_ctx *rctx,
     /* Set up SBUS connection to the monitor */
     ret = monitor_get_sbus_address(rctx, rctx->cdb, &sbus_address);
     if (ret != EOK) {
-        DEBUG(0, ("Could not locate monitor address.\n"));
+        SYSLOG_ERROR("Could not locate monitor address.\n");
         return ret;
     }
 
@@ -303,14 +303,14 @@ static int sss_monitor_init(struct resp_ctx *rctx,
                            intf, &rctx->mon_conn,
                            NULL, NULL);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to connect to monitor services.\n"));
+        SYSLOG_ERROR("Failed to connect to monitor services.\n");
         return ret;
     }
 
     /* Identify ourselves to the monitor */
     ret = monitor_common_send_id(rctx->mon_conn, svc_name, svc_version);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to identify to the monitor!\n"));
+        SYSLOG_ERROR("Failed to identify to the monitor!\n");
         return ret;
     }
 
@@ -328,7 +328,7 @@ static int sss_dp_init(struct resp_ctx *rctx,
     /* Set up SBUS connection to the monitor */
     ret = dp_get_sbus_address(rctx, rctx->cdb, &sbus_address);
     if (ret != EOK) {
-        DEBUG(0, ("Could not locate DP address.\n"));
+        SYSLOG_ERROR("Could not locate DP address.\n");
         return ret;
     }
 
@@ -336,7 +336,7 @@ static int sss_dp_init(struct resp_ctx *rctx,
                            intf, &rctx->dp_conn,
                            NULL, NULL);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to connect to monitor services.\n"));
+        SYSLOG_ERROR("Failed to connect to monitor services.\n");
         return ret;
     }
 
@@ -345,7 +345,7 @@ static int sss_dp_init(struct resp_ctx *rctx,
                             cli_type, cli_version,
                             cli_name, cli_domain);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to identify to the DP!\n"));
+        SYSLOG_ERROR("Failed to identify to the DP!\n");
         return ret;
     }
 
@@ -414,18 +414,18 @@ static int set_unix_socket(struct resp_ctx *rctx)
         unlink(rctx->sock_name);
 
         if (bind(rctx->lfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-            DEBUG(0,("Unable to bind on socket '%s'\n", rctx->sock_name));
+            SYSLOG_ERROR("Unable to bind on socket '%s'\n", rctx->sock_name);
             goto failed;
         }
         if (listen(rctx->lfd, 10) != 0) {
-            DEBUG(0,("Unable to listen on socket '%s'\n", rctx->sock_name));
+            SYSLOG_ERROR("Unable to listen on socket '%s'\n", rctx->sock_name);
             goto failed;
         }
 
         rctx->lfde = tevent_add_fd(rctx->ev, rctx, rctx->lfd,
                                    TEVENT_FD_READ, accept_fd_handler, rctx);
         if (!rctx->lfde) {
-            DEBUG(0, ("Failed to queue handler on pipe\n"));
+            SYSLOG_ERROR("Failed to queue handler on pipe\n");
             goto failed;
         }
     }
@@ -450,18 +450,18 @@ static int set_unix_socket(struct resp_ctx *rctx)
         unlink(rctx->priv_sock_name);
 
         if (bind(rctx->priv_lfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-            DEBUG(0,("Unable to bind on socket '%s'\n", rctx->priv_sock_name));
+            SYSLOG_ERROR("Unable to bind on socket '%s'\n", rctx->priv_sock_name);
             goto failed;
         }
         if (listen(rctx->priv_lfd, 10) != 0) {
-            DEBUG(0,("Unable to listen on socket '%s'\n", rctx->priv_sock_name));
+            SYSLOG_ERROR("Unable to listen on socket '%s'\n", rctx->priv_sock_name);
             goto failed;
         }
 
         rctx->priv_lfde = tevent_add_fd(rctx->ev, rctx, rctx->priv_lfd,
                                    TEVENT_FD_READ, accept_priv_fd_handler, rctx);
         if (!rctx->priv_lfde) {
-            DEBUG(0, ("Failed to queue handler on privileged pipe\n"));
+            SYSLOG_ERROR("Failed to queue handler on privileged pipe\n");
             goto failed;
         }
     }
@@ -500,7 +500,7 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
 
     rctx = talloc_zero(mem_ctx, struct resp_ctx);
     if (!rctx) {
-        DEBUG(0, ("fatal error initializing resp_ctx\n"));
+        SYSLOG_ERROR("fatal error initializing resp_ctx\n");
         return ENOMEM;
     }
     rctx->ev = ev;
@@ -512,13 +512,13 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
 
     ret = confdb_get_domains(rctx->cdb, &rctx->domains);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error setting up domain map\n"));
+        SYSLOG_ERROR("fatal error setting up domain map\n");
         return ret;
     }
 
     ret = sss_monitor_init(rctx, monitor_intf, svc_name, svc_version);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error setting up message bus\n"));
+        SYSLOG_ERROR("fatal error setting up message bus\n");
         return ret;
     }
 
@@ -526,30 +526,30 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
                       cli_type, cli_version,
                       cli_name, cli_domain);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error setting up backend connector\n"));
+        SYSLOG_ERROR("fatal error setting up backend connector\n");
         return ret;
     }
     else if (!rctx->dp_conn) {
-        DEBUG(0, ("Data Provider is not yet available. Retrying.\n"));
+        SYSLOG_ERROR("Data Provider is not yet available. Retrying.\n");
         return EIO;
     }
 
     ret = sysdb_init(rctx, ev, cdb, NULL, false, &rctx->db_list);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error initializing resp_ctx\n"));
+        SYSLOG_ERROR("fatal error initializing resp_ctx\n");
         return ret;
     }
 
     ret = sss_names_init(rctx, rctx->cdb, &rctx->names);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error initializing regex data\n"));
+        SYSLOG_ERROR("fatal error initializing regex data\n");
         return ret;
     }
 
     /* after all initializations we are ready to listen on our socket */
     ret = set_unix_socket(rctx);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error initializing socket\n"));
+        SYSLOG_ERROR("fatal error initializing socket\n");
         return ret;
     }
 
diff --git a/server/responder/common/responder_dp.c b/server/responder/common/responder_dp.c
index a636518..a51fc5e 100644
--- a/server/responder/common/responder_dp.c
+++ b/server/responder/common/responder_dp.c
@@ -70,7 +70,7 @@ static int sss_dp_req_destructor(void *ptr)
     key.str = sdp_req->key;
     int hret = hash_delete(dp_requests, &key);
     if (hret != HASH_SUCCESS) {
-        DEBUG(0, ("Could not clear entry from request queue\n"));
+        SYSLOG_ERROR("Could not clear entry from request queue\n");
         /* This should never happen */
         return EIO;
     }
@@ -269,7 +269,7 @@ int sss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *memctx,
             /* We have a new request asking for a callback */
             sdp_req = talloc_get_type(value.ptr, struct sss_dp_req);
             if (!sdp_req) {
-                DEBUG(0, ("Could not retrieve DP request context\n"));
+                SYSLOG_ERROR("Could not retrieve DP request context\n");
                 ret = EIO;
                 goto done;
             }
@@ -303,8 +303,8 @@ int sss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *memctx,
             value.ptr = sdp_req;
             hret = hash_enter(dp_requests, &key, &value);
             if (hret != HASH_SUCCESS) {
-                DEBUG(0, ("Could not store request query (%s)",
-                          hash_error_string(hret)));
+                SYSLOG_ERROR("Could not store request query (%s)",
+                             hash_error_string(hret));
                 ret = EIO;
                 goto done;
             }
@@ -315,8 +315,8 @@ int sss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *memctx,
         break;
 
     default:
-        DEBUG(0,("Could not query request list (%s)\n",
-                  hash_error_string(hret)));
+        SYSLOG_ERROR("Could not query request list (%s)\n",
+                     hash_error_string(hret));
         ret = EIO;
         goto done;
     }
@@ -364,7 +364,7 @@ static int sss_dp_send_acct_req_create(struct resp_ctx *rctx,
                                        DP_CLI_INTERFACE,
                                        DP_SRV_METHOD_GETACCTINFO);
     if (msg == NULL) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         return ENOMEM;
     }
 
@@ -390,7 +390,7 @@ static int sss_dp_send_acct_req_create(struct resp_ctx *rctx,
          * We can't communicate on this connection
          * We'll drop it using the default destructor.
          */
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         return EIO;
     }
@@ -423,7 +423,7 @@ static int sss_dp_send_acct_req_create(struct resp_ctx *rctx,
                                          sss_dp_send_acct_callback,
                                          sdp_req, NULL);
     if (!dbret) {
-        DEBUG(0, ("Could not queue up pending request!"));
+        SYSLOG_ERROR("Could not queue up pending request!");
         talloc_zfree(sdp_req);
         dbus_pending_call_cancel(pending_reply);
         dbus_message_unref(msg);
@@ -456,7 +456,7 @@ static int sss_dp_get_reply(DBusPendingCall *pending,
          * until reply is valid or timeout has occurred. If reply is NULL
          * here, something is seriously wrong and we should bail out.
          */
-        DEBUG(0, ("Severe error. A reply callback was called but no reply was received and no timeout occurred\n"));
+        SYSLOG_ERROR("Severe error. A reply callback was called but no reply was received and no timeout occurred\n");
 
         /* FIXME: Destroy this connection ? */
         err = EIO;
@@ -490,8 +490,8 @@ static int sss_dp_get_reply(DBusPendingCall *pending,
             err = ETIME;
             goto done;
         }
-        DEBUG(0,("The Data Provider returned an error [%s]\n",
-                 dbus_message_get_error_name(reply)));
+        SYSLOG_ERROR("The Data Provider returned an error [%s]\n",
+                     dbus_message_get_error_name(reply));
         /* Falling through to default intentionally*/
     default:
         /*
diff --git a/server/responder/nss/nsssrv.c b/server/responder/nss/nsssrv.c
index 3920189..e0bdcdd 100644
--- a/server/responder/nss/nsssrv.c
+++ b/server/responder/nss/nsssrv.c
@@ -46,6 +46,8 @@
 
 #define SSS_NSS_PIPE_NAME "nss"
 
+#define PRG_NAME "sssd[nss]"
+
 static int service_reload(DBusMessage *message, struct sbus_connection *conn);
 
 struct sbus_method monitor_nss_methods[] = {
@@ -113,13 +115,13 @@ static int nss_get_config(struct nss_ctx *nctx,
                          &nctx->cache_refresh_timeout);
     if (ret != EOK) goto done;
     if (nctx->cache_refresh_timeout >= nctx->cache_timeout) {
-        DEBUG(0,("Configuration error: EntryCacheNoWaitRefreshTimeout exceeds"
-                 "EntryCacheTimeout. Disabling feature.\n"));
+        SYSLOG_ERROR("Configuration error: EntryCacheNoWaitRefreshTimeout exceeds"
+                     "EntryCacheTimeout. Disabling feature.\n");
         nctx->cache_refresh_timeout = 0;
     }
     if (nctx->cache_refresh_timeout < 0) {
-        DEBUG(0,("Configuration error: EntryCacheNoWaitRefreshTimeout is"
-                 "invalid. Disabling feature.\n"));
+        SYSLOG_ERROR("Configuration error: EntryCacheNoWaitRefreshTimeout is"
+                     "invalid. Disabling feature.\n");
         nctx->cache_refresh_timeout = 0;
     }
 
@@ -239,7 +241,7 @@ static void nss_dp_reconnect_init(struct sbus_connection *conn,
     }
 
     /* Failed to reconnect */
-    DEBUG(0, ("Could not reconnect to data provider.\n"));
+    SYSLOG_ERROR("Could not reconnect to data provider.\n");
     /* Kill the backend and let the monitor restart it */
     nss_shutdown(rctx);
 }
@@ -254,13 +256,13 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
 
     nctx = talloc_zero(mem_ctx, struct nss_ctx);
     if (!nctx) {
-        DEBUG(0, ("fatal error initializing nss_ctx\n"));
+        SYSLOG_ERROR("fatal error initializing nss_ctx\n");
         return ENOMEM;
     }
 
     ret = nss_ncache_init(nctx, &nctx->ncache);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error initializing negative cache\n"));
+        SYSLOG_ERROR("fatal error initializing negative cache\n");
         return ret;
     }
 
@@ -285,7 +287,7 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
 
     ret = nss_get_config(nctx, nctx->rctx, cdb);
     if (ret != EOK) {
-        DEBUG(0, ("fatal error getting nss config\n"));
+        SYSLOG_ERROR("fatal error getting nss config\n");
         return ret;
     }
 
@@ -294,7 +296,7 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
                          SERVICE_CONF_ENTRY,
                          "reconnection_retries", 3, &max_retries);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to set up automatic reconnection\n"));
+        SYSLOG_ERROR("Failed to set up automatic reconnection\n");
         return ret;
     }
 
@@ -333,8 +335,11 @@ int main(int argc, const char *argv[])
 
     poptFreeContext(pc);
 
+    /* enable syslog logging */
+    openlog(PRG_NAME, LOG_PID, LOG_DAEMON);
+
     /* set up things like debug , signals, daemonization, etc... */
-    ret = server_setup("sssd[nss]", 0, NSS_SRV_CONFIG, &main_ctx);
+    ret = server_setup(PRG_NAME, 0, NSS_SRV_CONFIG, &main_ctx);
     if (ret != EOK) return 2;
 
     ret = die_if_parent_died();
@@ -351,6 +356,9 @@ int main(int argc, const char *argv[])
     /* loop on main */
     server_loop(main_ctx);
 
+    /* close syslog */
+    closelog();
+
     return 0;
 }
 
diff --git a/server/responder/nss/nsssrv_cmd.c b/server/responder/nss/nsssrv_cmd.c
index 8ca0be6..87886a3 100644
--- a/server/responder/nss/nsssrv_cmd.c
+++ b/server/responder/nss/nsssrv_cmd.c
@@ -464,7 +464,7 @@ static void nss_cmd_getpwnam_callback(void *ptr, int status,
                 ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                               dctx->domain, &sysdb);
                 if (ret != EOK) {
-                    DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                    SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                     NSS_CMD_FATAL_ERROR(cctx);
                 }
                 ret = sysdb_getpwnam(cmdctx, sysdb,
@@ -562,7 +562,7 @@ static void nss_cmd_getpwnam_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_getpwnam(cmdctx, sysdb,
@@ -692,7 +692,7 @@ static int nss_cmd_getpwnam(struct cli_ctx *cctx)
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         ret = EFAULT;
         goto done;
     }
@@ -782,8 +782,8 @@ static void nss_cmd_getpwuid_callback(void *ptr, int status,
                 ret = ENOENT;
             }
             if (dom == NULL) {
-                DEBUG(0, ("No matching domain found for [%lu], fail!\n",
-                          (unsigned long)cmdctx->id));
+                SYSLOG_ERROR("No matching domain found for [%lu], fail!\n",
+                          (unsigned long)cmdctx->id);
                 ret = ENOENT;
             }
 
@@ -799,7 +799,7 @@ static void nss_cmd_getpwuid_callback(void *ptr, int status,
                 ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                               dctx->domain, &sysdb);
                 if (ret != EOK) {
-                    DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                    SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                     NSS_CMD_FATAL_ERROR(cctx);
                 }
                 ret = sysdb_getpwuid(cmdctx, sysdb,
@@ -897,7 +897,7 @@ static void nss_cmd_getpwuid_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_getpwuid(cmdctx, sysdb,
@@ -985,7 +985,7 @@ static int nss_cmd_getpwuid(struct cli_ctx *cctx)
         ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                       dctx->domain, &sysdb);
         if (ret != EOK) {
-            DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+            SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
             ret = EFAULT;
             goto done;
         }
@@ -1113,7 +1113,7 @@ static void nss_cmd_setpwent_callback(void *ptr, int status,
             ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                           dctx->domain, &sysdb);
             if (ret != EOK) {
-                DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                 NSS_CMD_FATAL_ERROR(cctx);
             }
             ret = sysdb_enumpwent(dctx, sysdb,
@@ -1174,7 +1174,7 @@ static void nss_cmd_setpw_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_enumpwent(cmdctx, sysdb,
@@ -1260,7 +1260,7 @@ static int nss_cmd_setpwent_ext(struct cli_ctx *cctx, bool immediate)
         ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                       dctx->domain, &sysdb);
         if (ret != EOK) {
-            DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+            SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
             ret = EFAULT;
             goto done;
         }
@@ -1798,7 +1798,7 @@ static void nss_cmd_getgrnam_callback(void *ptr, int status,
                 ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                               dctx->domain, &sysdb);
                 if (ret != EOK) {
-                    DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                    SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                     NSS_CMD_FATAL_ERROR(cctx);
                 }
                 ret = sysdb_getgrnam(cmdctx, sysdb,
@@ -1892,7 +1892,7 @@ static void nss_cmd_getgrnam_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_getgrnam(cmdctx, sysdb,
@@ -2022,7 +2022,7 @@ static int nss_cmd_getgrnam(struct cli_ctx *cctx)
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         ret = EFAULT;
         goto done;
     }
@@ -2113,8 +2113,8 @@ static void nss_cmd_getgrgid_callback(void *ptr, int status,
                 ret = ENOENT;
             }
             if (dom == NULL) {
-                DEBUG(0, ("No matching domain found for [%lu], fail!\n",
-                          (unsigned long)cmdctx->id));
+                SYSLOG_ERROR("No matching domain found for [%lu], fail!\n",
+                          (unsigned long)cmdctx->id);
                 ret = ENOENT;
             }
 
@@ -2130,7 +2130,7 @@ static void nss_cmd_getgrgid_callback(void *ptr, int status,
                 ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                               dctx->domain, &sysdb);
                 if (ret != EOK) {
-                    DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                    SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                     NSS_CMD_FATAL_ERROR(cctx);
                 }
                 ret = sysdb_getgrgid(cmdctx, sysdb,
@@ -2222,7 +2222,7 @@ static void nss_cmd_getgrgid_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_getgrgid(cmdctx, sysdb,
@@ -2310,7 +2310,7 @@ static int nss_cmd_getgrgid(struct cli_ctx *cctx)
         ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                       dctx->domain, &sysdb);
         if (ret != EOK) {
-            DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+            SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
             ret = EFAULT;
             goto done;
         }
@@ -2434,7 +2434,7 @@ static void nss_cmd_setgrent_callback(void *ptr, int status,
             ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                           dctx->domain, &sysdb);
             if (ret != EOK) {
-                DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                 NSS_CMD_FATAL_ERROR(cctx);
             }
             ret = sysdb_enumgrent(dctx, sysdb,
@@ -2495,7 +2495,7 @@ static void nss_cmd_setgr_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_enumgrent(dctx, sysdb,
@@ -2581,7 +2581,7 @@ static int nss_cmd_setgrent_ext(struct cli_ctx *cctx, bool immediate)
         ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                       dctx->domain, &sysdb);
         if (ret != EOK) {
-            DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+            SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
             ret = EFAULT;
             goto done;
         }
@@ -2824,7 +2824,7 @@ static void nss_cmd_getinitgr_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_initgroups(cmdctx, sysdb,
@@ -2875,7 +2875,7 @@ static void nss_cmd_getinitnam_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         NSS_CMD_FATAL_ERROR(cctx);
     }
     ret = sysdb_getpwnam(cmdctx, sysdb,
@@ -3021,7 +3021,7 @@ static void nss_cmd_getinit_callback(void *ptr, int status,
                 ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                               dctx->domain, &sysdb);
                 if (ret != EOK) {
-                    DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                    SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                     NSS_CMD_FATAL_ERROR(cctx);
                 }
                 ret = sysdb_getpwnam(cmdctx, sysdb,
@@ -3200,7 +3200,7 @@ static int nss_cmd_initgroups(struct cli_ctx *cctx)
     ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                   dctx->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         ret = EFAULT;
         goto done;
     }
diff --git a/server/responder/pam/pam_LOCAL_domain.c b/server/responder/pam/pam_LOCAL_domain.c
index 41d64b3..25a5aed 100644
--- a/server/responder/pam/pam_LOCAL_domain.c
+++ b/server/responder/pam/pam_LOCAL_domain.c
@@ -462,7 +462,7 @@ int LOCAL_pam_handler(struct pam_auth_req *preq)
     ret = sysdb_get_ctx_from_list(preq->cctx->rctx->db_list,
                                   preq->domain, &lreq->dbctx);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         talloc_free(lreq);
         return ret;
     }
diff --git a/server/responder/pam/pamsrv.c b/server/responder/pam/pamsrv.c
index c751528..4e0bf83 100644
--- a/server/responder/pam/pamsrv.c
+++ b/server/responder/pam/pamsrv.c
@@ -48,6 +48,8 @@
 #define PAM_SBUS_SERVICE_NAME "pam"
 #define PAM_SRV_CONFIG "config/services/pam"
 
+#define PRG_NAME "sssd[pam]"
+
 static int service_reload(DBusMessage *message, struct sbus_connection *conn);
 
 struct sbus_method monitor_pam_methods[] = {
@@ -117,7 +119,7 @@ static void pam_dp_reconnect_init(struct sbus_connection *conn, int status, void
     }
 
     /* Handle failure */
-    DEBUG(0, ("Could not reconnect to data provider.\n"));
+    SYSLOG_ERROR("Could not reconnect to data provider.\n");
     /* Kill the backend and let the monitor restart it */
     pam_shutdown(rctx);
 }
@@ -155,7 +157,7 @@ static int pam_process_init(TALLOC_CTX *mem_ctx,
     ret = confdb_get_int(rctx->cdb, rctx, SERVICE_CONF_ENTRY,
                          "reconnection_retries", 3, &max_retries);
     if (ret != EOK) {
-        DEBUG(0, ("Failed to set up automatic reconnection\n"));
+        SYSLOG_ERROR("Failed to set up automatic reconnection\n");
         return ret;
     }
 
@@ -191,8 +193,11 @@ int main(int argc, const char *argv[])
 
 	poptFreeContext(pc);
 
+    /* enable syslog logging */
+    openlog(PRG_NAME, LOG_PID, LOG_DAEMON);
+
     /* set up things like debug , signals, daemonization, etc... */
-    ret = server_setup("sssd[pam]", 0, PAM_SRV_CONFIG, &main_ctx);
+    ret = server_setup(PRG_NAME, 0, PAM_SRV_CONFIG, &main_ctx);
     if (ret != EOK) return 2;
 
     ret = die_if_parent_died();
@@ -209,6 +214,9 @@ int main(int argc, const char *argv[])
     /* loop on main */
     server_loop(main_ctx);
 
+    /* close syslog */
+    closelog();
+
     return 0;
 }
 
diff --git a/server/responder/pam/pamsrv_cache.c b/server/responder/pam/pamsrv_cache.c
index 9c5c209..51e8354 100644
--- a/server/responder/pam/pamsrv_cache.c
+++ b/server/responder/pam/pamsrv_cache.c
@@ -148,7 +148,7 @@ int pam_cache_auth(struct pam_auth_req *preq)
     ret = sysdb_get_ctx_from_list(preq->cctx->rctx->db_list,
                                   preq->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         return ret;
     }
     ret = sysdb_get_user_attr(preq, sysdb,
diff --git a/server/responder/pam/pamsrv_cmd.c b/server/responder/pam/pamsrv_cmd.c
index 671dc08..874ff20 100644
--- a/server/responder/pam/pamsrv_cmd.c
+++ b/server/responder/pam/pamsrv_cmd.c
@@ -532,7 +532,7 @@ static int pam_forwarder(struct cli_ctx *cctx, int pam_cmd)
         ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
                                       preq->domain, &sysdb);
         if (ret != EOK) {
-            DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+            SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
             goto done;
         }
         ret = sysdb_getpwnam(preq, sysdb,
@@ -584,7 +584,7 @@ static void pam_check_user_dp_callback(uint16_t err_maj, uint32_t err_min,
     ret = sysdb_get_ctx_from_list(preq->cctx->rctx->db_list,
                                   preq->domain, &sysdb);
     if (ret != EOK) {
-        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
         goto done;
     }
     ret = sysdb_getpwnam(preq, sysdb,
@@ -733,7 +733,7 @@ static void pam_check_user_callback(void *ptr, int status,
                     ret = sysdb_get_ctx_from_list(preq->cctx->rctx->db_list,
                                                   preq->domain, &sysdb);
                     if (ret != EOK) {
-                        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
+                        SYSLOG_ERROR("Fatal: Sysdb CTX not found for this domain!\n");
                         preq->pd->pam_status = PAM_SYSTEM_ERR;
                         pam_reply(preq);
                         return;
diff --git a/server/responder/pam/pamsrv_dp.c b/server/responder/pam/pamsrv_dp.c
index 7ea2b7e..3f2a9bc 100644
--- a/server/responder/pam/pamsrv_dp.c
+++ b/server/responder/pam/pamsrv_dp.c
@@ -46,7 +46,7 @@ static void pam_dp_process_reply(DBusPendingCall *pending, void *ptr)
     dbus_pending_call_block(pending);
     msg = dbus_pending_call_steal_reply(pending);
     if (msg == NULL) {
-        DEBUG(0, ("Severe error. A reply callback was called but no reply was received and no timeout occurred\n"));
+        SYSLOG_ERROR("Severe error. A reply callback was called but no reply was received and no timeout occurred\n");
         preq->pd->pam_status = PAM_SYSTEM_ERR;
         goto done;
     }
@@ -57,18 +57,18 @@ static void pam_dp_process_reply(DBusPendingCall *pending, void *ptr)
         case DBUS_MESSAGE_TYPE_METHOD_RETURN:
             ret = dp_unpack_pam_response(msg, preq->pd, &dbus_error);
             if (!ret) {
-                DEBUG(0, ("Failed to parse reply.\n"));
+                SYSLOG_ERROR("Failed to parse reply.\n");
                 preq->pd->pam_status = PAM_SYSTEM_ERR;
                 goto done;
             }
             DEBUG(4, ("received: [%d][%s]\n", preq->pd->pam_status, preq->pd->domain));
             break;
         case DBUS_MESSAGE_TYPE_ERROR:
-            DEBUG(0, ("Reply error.\n"));
+            SYSLOG_ERROR("Reply error.\n");
             preq->pd->pam_status = PAM_SYSTEM_ERR;
             break;
         default:
-            DEBUG(0, ("Default... what now?.\n"));
+            SYSLOG_ERROR("Default... what now?.\n");
             preq->pd->pam_status = PAM_SYSTEM_ERR;
     }
 
@@ -103,7 +103,7 @@ int pam_dp_send_req(struct pam_auth_req *preq, int timeout)
                                        DP_CLI_INTERFACE,
                                        DP_SRV_METHOD_PAMHANDLER);
     if (msg == NULL) {
-        DEBUG(0,("Out of memory?!\n"));
+        SYSLOG_ERROR("Out of memory?!\n");
         return ENOMEM;
     }
 
@@ -124,7 +124,7 @@ int pam_dp_send_req(struct pam_auth_req *preq, int timeout)
          * We can't communicate on this connection
          * We'll drop it using the default destructor.
          */
-        DEBUG(0, ("D-BUS send failed.\n"));
+        SYSLOG_ERROR("D-BUS send failed.\n");
         dbus_message_unref(msg);
         return EIO;
     }
diff --git a/server/sbus/sssd_dbus_common.c b/server/sbus/sssd_dbus_common.c
index e5970a3..8ec1521 100644
--- a/server/sbus/sssd_dbus_common.c
+++ b/server/sbus/sssd_dbus_common.c
@@ -130,7 +130,7 @@ dbus_bool_t sbus_add_watch(DBusWatch *dbus_watch, void *data)
         /* does not exist, allocate new one */
         watch = talloc_zero(conn, struct sbus_watch_ctx);
         if (!watch) {
-            DEBUG(0, ("Out of Memory!\n"));
+            SYSLOG_ERROR("Out of Memory!\n");
             return FALSE;
         }
         watch->conn = conn;
@@ -170,7 +170,7 @@ dbus_bool_t sbus_add_watch(DBusWatch *dbus_watch, void *data)
                                watch, fd, event_flags,
                                sbus_watch_handler, watch);
     if (!watch->fde) {
-        DEBUG(0, ("Failed to set up fd event!\n"));
+        SYSLOG_ERROR("Failed to set up fd event!\n");
         talloc_zfree(watch);
         return FALSE;
     }
@@ -323,7 +323,7 @@ dbus_bool_t sbus_add_timeout(DBusTimeout *dbus_timeout, void *data)
 
     timeout = talloc_zero(conn, struct sbus_timeout_ctx);
     if (!timeout) {
-        DEBUG(0, ("Out of Memory!\n"));
+        SYSLOG_ERROR("Out of Memory!\n");
         return FALSE;
     }
     timeout->dbus_timeout = dbus_timeout;
@@ -332,7 +332,7 @@ dbus_bool_t sbus_add_timeout(DBusTimeout *dbus_timeout, void *data)
     timeout->te = tevent_add_timer(conn->ev, timeout, tv,
                                    sbus_timeout_handler, timeout);
     if (!timeout->te) {
-        DEBUG(0, ("Failed to set up timeout event!\n"));
+        SYSLOG_ERROR("Failed to set up timeout event!\n");
         return FALSE;
     }
 
diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c
index 1953ee5..907194f 100644
--- a/server/sbus/sssd_dbus_connection.c
+++ b/server/sbus/sssd_dbus_connection.c
@@ -61,7 +61,7 @@ static void sbus_dispatch(struct tevent_context *ev,
         /* Currently trying to reconnect, defer dispatch */
         new_event = tevent_add_timer(ev, conn, tv, sbus_dispatch, conn);
         if (new_event == NULL) {
-            DEBUG(0,("Could not defer dispatch!\n"));
+            SYSLOG_ERROR("Could not defer dispatch!\n");
         }
         return;
     }
@@ -75,7 +75,7 @@ static void sbus_dispatch(struct tevent_context *ev,
             return;
         }
 
-        DEBUG(0, ("Cannot start auto-reconnection.\n"));
+        SYSLOG_ERROR("Cannot start auto-reconnection.\n");
         conn->reconnect_callback(conn,
                                  SBUS_RECONNECT_ERROR,
                                  conn->reconnect_pvt);
@@ -483,7 +483,7 @@ int sbus_conn_add_interface(struct sbus_connection *conn,
     path = intf->path;
 
     if (path_in_interface_list(conn->intf_list, path)) {
-        DEBUG(0, ("Cannot add method context with identical path.\n"));
+        SYSLOG_ERROR("Cannot add method context with identical path.\n");
         return EINVAL;
     }
 
@@ -499,7 +499,7 @@ int sbus_conn_add_interface(struct sbus_connection *conn,
     dbret = dbus_connection_register_object_path(conn->dbus.conn,
                                                  path, &intf->vtable, intf_p);
     if (!dbret) {
-        DEBUG(0, ("Could not register object path to the connection.\n"));
+        SYSLOG_ERROR("Could not register object path to the connection.\n");
         return ENOMEM;
     }
 
@@ -580,7 +580,7 @@ static void sbus_reconnect(struct tevent_context *ev,
                                                          &iter->intf->vtable,
                                                          iter);
             if (!dbret) {
-                DEBUG(0, ("Could not register object path.\n"));
+                SYSLOG_ERROR("Could not register object path.\n");
                 dbus_connection_unref(conn->dbus.conn);
                 goto failed;
             }
diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c
index eeec13c..34b2881 100644
--- a/server/tools/tools_util.c
+++ b/server/tools/tools_util.c
@@ -226,6 +226,9 @@ int init_sss_tools(struct tools_ctx **_tctx)
     octx->domain = tctx->local;
     tctx->octx = octx;
 
+    /* No syslog in tools */
+    send_syslog = 0;
+
     *_tctx = tctx;
     ret = EOK;
 fini:
diff --git a/server/util/debug.c b/server/util/debug.c
index a7b3a09..f0b5865 100644
--- a/server/util/debug.c
+++ b/server/util/debug.c
@@ -29,6 +29,7 @@
 const char *debug_prg_name = "sssd";
 int debug_level = 0;
 int debug_timestamps = 0;
+int send_syslog = 1;
 
 void debug_fn(const char *format, ...)
 {
diff --git a/server/util/server.c b/server/util/server.c
index 0760e60..c195864 100644
--- a/server/util/server.c
+++ b/server/util/server.c
@@ -62,11 +62,11 @@ static void close_low_fds(bool stderr_too)
 		if (fd < 0)
 			fd = open("/dev/null",O_WRONLY,0);
 		if (fd < 0) {
-			DEBUG(0,("Can't open /dev/null\n"));
+                        SYSLOG_ERROR("Can't open /dev/null\n");
 			return;
 		}
 		if (fd != i) {
-			DEBUG(0,("Didn't get file descriptor %d\n",i));
+                        SYSLOG_ERROR("Didn't get file descriptor %d\n",i);
 			return;
 		}
 	}
@@ -94,8 +94,8 @@ void become_daemon(bool Fork)
         errno = 0;
         if(chdir("/") == -1) {
             ret = errno;
-            DEBUG(0, ("Cannot change directory (%d [%s])\n",
-                    ret, strerror(ret)));
+            SYSLOG_ERROR("Cannot change directory (%d [%s])\n",
+                      ret, strerror(ret));
             return;
         }
 
@@ -187,7 +187,7 @@ static void sig_term(int sig)
 #if HAVE_GETPGRP
 	static int done_sigterm;
 	if (done_sigterm == 0 && getpgrp() == getpid()) {
-		DEBUG(0,("SIGTERM: killing children\n"));
+                SYSLOG_NOTICE("SIGTERM: killing children\n");
 		done_sigterm = 1;
 		kill(-getpgrp(), SIGTERM);
 	}
@@ -201,7 +201,7 @@ static void sig_segv_abrt(int sig)
 #if HAVE_GETPGRP
 	static int done;
 	if (done == 0 && getpgrp() == getpid()) {
-		DEBUG(0,("%s: killing children\n", strsignal(sig)));
+                SYSLOG_NOTICE("%s: killing children\n", strsignal(sig));
 		done = 1;
 		kill(-getpgrp(), SIGTERM);
 	}
@@ -258,7 +258,7 @@ static void server_stdin_handler(struct tevent_context *event_ctx,
 	const char *binary_name = (const char *)private;
 	uint8_t c;
 	if (read(0, &c, 1) == 0) {
-		DEBUG(0,("%s: EOF on stdin - terminating\n", binary_name));
+                SYSLOG_NOTICE("%s: EOF on stdin - terminating\n", binary_name);
 #if HAVE_GETPGRP
 		if (getpgrp() == getpid()) {
 			kill(-getpgrp(), SIGTERM);
@@ -320,8 +320,8 @@ int server_setup(const char *name, int flags,
     if (flags & FLAGS_PID_FILE) {
         ret = pidfile(PID_PATH, name);
         if (ret != EOK) {
-            DEBUG(0, ("Error creating pidfile! (%d [%s])\n",
-                      ret, strerror(ret)));
+            SYSLOG_ERROR("Error creating pidfile! (%d [%s])\n",
+                         ret, strerror(ret));
             return ret;
         }
     }
@@ -335,13 +335,13 @@ int server_setup(const char *name, int flags,
      * Everything else should hang off that */
     event_ctx = tevent_context_init(talloc_autofree_context());
     if (event_ctx == NULL) {
-        DEBUG(0,("The event context initialiaziton failed\n"));
+        SYSLOG_ERROR("The event context initialiaziton failed\n");
         return 1;
     }
 
     ctx = talloc(event_ctx, struct main_context);
     if (ctx == NULL) {
-        DEBUG(0,("Out of memory, aborting!\n"));
+        SYSLOG_ERROR("Out of memory, aborting!\n");
         return ENOMEM;
     }
 
@@ -349,14 +349,14 @@ int server_setup(const char *name, int flags,
 
     conf_db = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
     if (conf_db == NULL) {
-        DEBUG(0,("Out of memory, aborting!\n"));
+        SYSLOG_ERROR("Out of memory, aborting!\n");
         return ENOMEM;
     }
     DEBUG(3, ("CONFDB: %s\n", conf_db));
 
     ret = confdb_init(ctx, &ctx->confdb_ctx, conf_db);
     if (ret != EOK) {
-        DEBUG(0,("The confdb initialization failed\n"));
+        SYSLOG_ERROR("The confdb initialization failed\n");
         return ret;
     }
 
@@ -364,8 +364,8 @@ int server_setup(const char *name, int flags,
     ret = confdb_get_int(ctx->confdb_ctx, ctx, conf_entry,
                          "debug-level", debug_level, &debug_level);
     if (ret != EOK) {
-        DEBUG(0, ("Error reading from confdb (%d) [%s]\n",
-                  ret, strerror(ret)));
+        SYSLOG_ERROR("Error reading from confdb (%d) [%s]\n",
+                     ret, strerror(ret));
         return ret;
     }
 
@@ -374,8 +374,8 @@ int server_setup(const char *name, int flags,
     ret = confdb_get_bool(ctx->confdb_ctx, ctx, conf_entry,
                           "debug-timestamps", dt, &dt);
     if (ret != EOK) {
-        DEBUG(0, ("Error reading from confdb (%d) [%s]\n",
-                  ret, strerror(ret)));
+        SYSLOG_ERROR("Error reading from confdb (%d) [%s]\n",
+                     ret, strerror(ret));
         return ret;
     }
     if (dt) debug_timestamps = 1;
diff --git a/server/util/util.h b/server/util/util.h
index ea7f44e..1b03963 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -30,6 +30,7 @@
 #include <limits.h>
 #include <time.h>
 #include <pcre.h>
+#include <syslog.h>
 #include "config.h"
 #include "talloc.h"
 #include "tevent.h"
@@ -43,6 +44,7 @@ typedef int errno_t;
 extern const char *debug_prg_name;
 extern int debug_level;
 extern int debug_timestamps;
+extern int send_syslog;
 void debug_fn(const char *format, ...);
 
 #define SSSD_DEBUG_OPTS \
@@ -81,6 +83,20 @@ void debug_fn(const char *format, ...);
 #define PRINT(fmt, ...) fprintf(stdout, gettext(fmt), ##__VA_ARGS__)
 #define ERROR(fmt, ...) fprintf(stderr, gettext(fmt), ##__VA_ARGS__)
 
+#define SYSLOG_ERROR(...) do { \
+    DEBUG(0, (__VA_ARGS__)); \
+    if (send_syslog) { \
+        syslog(LOG_ERR, __VA_ARGS__); \
+    } \
+} while(0);
+
+#define SYSLOG_NOTICE(...) do { \
+    DEBUG(0, (__VA_ARGS__)); \
+    if (send_syslog) { \
+        syslog(LOG_NOTICE, __VA_ARGS__); \
+    } \
+} while(0);
+
 #ifndef discard_const
 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
 #endif
-- 
1.6.2.5

