Index: uspace/srv/devman/devman.c
===================================================================
--- uspace/srv/devman/devman.c	(revision 0418050164f0ae33ce754da92e722d5809138eff)
+++ uspace/srv/devman/devman.c	(revision 9b415c96f2f29f61f5d4f5f7ea3fd3b1ef1ea27a)
@@ -34,4 +34,5 @@
 #include <fcntl.h>
 #include <sys/stat.h>
+#include <io/log.h>
 #include <ipc/driver.h>
 #include <ipc/devman.h>
@@ -146,5 +147,5 @@
 	fibril_mutex_unlock(&drivers_list->drivers_mutex);
 
-	printf(NAME": the '%s' driver was added to the list of available "
+	log_msg(LVL_NOTE, "Driver `%s' was added to the list of available "
 	    "drivers.\n", drv->name);
 }
@@ -237,5 +238,5 @@
 bool read_match_ids(const char *conf_path, match_id_list_t *ids)
 {
-	printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
+	log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")\n", conf_path);
 	
 	bool suc = false;
@@ -247,5 +248,6 @@
 	fd = open(conf_path, O_RDONLY);
 	if (fd < 0) {
-		printf(NAME ": unable to open %s\n", conf_path);
+		log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.\n",
+		    conf_path, str_error(fd));
 		goto cleanup;
 	}
@@ -255,5 +257,6 @@
 	lseek(fd, 0, SEEK_SET);
 	if (len == 0) {
-		printf(NAME ": configuration file '%s' is empty.\n", conf_path);
+		log_msg(LVL_ERROR, "Configuration file '%s' is empty.\n",
+		    conf_path);
 		goto cleanup;
 	}
@@ -261,5 +264,5 @@
 	buf = malloc(len + 1);
 	if (buf == NULL) {
-		printf(NAME ": memory allocation failed when parsing file "
+		log_msg(LVL_ERROR, "Memory allocation failed when parsing file "
 		    "'%s'.\n", conf_path);
 		goto cleanup;
@@ -268,5 +271,5 @@
 	ssize_t read_bytes = safe_read(fd, buf, len);
 	if (read_bytes <= 0) {
-		printf(NAME ": unable to read file '%s'.\n", conf_path);
+		log_msg(LVL_ERROR, "Unable to read file '%s'.\n", conf_path);
 		goto cleanup;
 	}
@@ -306,5 +309,5 @@
 bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
 {
-	printf(NAME ": get_driver_info base_path = %s, name = %s.\n",
+	log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")\n",
 	    base_path, name);
 	
@@ -338,5 +341,6 @@
 	struct stat s;
 	if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
-		printf(NAME ": driver not found at path %s.", drv->binary_path);
+		log_msg(LVL_ERROR, "Driver not found at path `%s'.",
+		    drv->binary_path);
 		goto cleanup;
 	}
@@ -365,5 +369,5 @@
 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
 {
-	printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
+	log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")\n", dir_path);
 	
 	int drv_cnt = 0;
@@ -399,5 +403,5 @@
 	dev_node_t *dev;
 	
-	printf(NAME ": create_root_nodes\n");
+	log_msg(LVL_DEBUG, "create_root_nodes()\n");
 	
 	fibril_rwlock_write_lock(&tree->rwlock);
@@ -484,6 +488,6 @@
 void attach_driver(dev_node_t *dev, driver_t *drv)
 {
-	printf(NAME ": attach_driver %s to device %s\n",
-	    drv->name, dev->pfun->pathname);
+	log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")\n",
+	    dev->pfun->pathname, drv->name);
 	
 	fibril_mutex_lock(&drv->driver_mutex);
@@ -507,10 +511,10 @@
 	assert(fibril_mutex_is_locked(&drv->driver_mutex));
 	
-	printf(NAME ": start_driver '%s'\n", drv->name);
+	log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")\n", drv->name);
 	
 	rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL);
 	if (rc != EOK) {
-		printf(NAME ": error spawning %s (%s)\n",
-		    drv->name, str_error(rc));
+		log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.\n",
+		    drv->name, drv->binary_path, str_error(rc));
 		return false;
 	}
@@ -574,5 +578,6 @@
 	int phone;
 
-	printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
+	log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")\n",
+	    driver->name);
 
 	fibril_mutex_lock(&driver->driver_mutex);
@@ -641,5 +646,5 @@
 	 * immediately and possibly started here as well.
 	 */
-	printf(NAME ": driver %s goes into running state.\n", driver->name);
+	log_msg(LVL_DEBUG, "Driver `%s' enters running state.\n", driver->name);
 	driver->state = DRIVER_RUNNING;
 
@@ -658,5 +663,6 @@
 void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
 {
-	printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
+	log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")\n",
+	    driver->name);
 	
 	/*
@@ -748,6 +754,6 @@
 	 * access any structures that would affect driver_t.
 	 */
-	printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
-	    dev->pfun->name);
+	log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")\n",
+	    drv->name, dev->pfun->name);
 	
 	sysarg_t rc;
@@ -810,5 +816,5 @@
 	driver_t *drv = find_best_match_driver(drivers_list, dev);
 	if (drv == NULL) {
-		printf(NAME ": no driver found for device '%s'.\n",
+		log_msg(LVL_ERROR, "No driver found for device `%s'.\n",
 		    dev->pfun->pathname);
 		return false;
@@ -848,5 +854,5 @@
 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
 {
-	printf(NAME ": init_device_tree.\n");
+	log_msg(LVL_DEBUG, "init_device_tree()\n");
 	
 	tree->current_handle = 0;
@@ -1027,5 +1033,5 @@
 	fun->pathname = (char *) malloc(pathsize);
 	if (fun->pathname == NULL) {
-		printf(NAME ": failed to allocate device path.\n");
+		log_msg(LVL_ERROR, "Failed to allocate device path.\n");
 		return false;
 	}
@@ -1058,4 +1064,7 @@
 	assert(fibril_rwlock_is_write_locked(&tree->rwlock));
 	
+	log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])\n",
+	    dev, pfun, pfun->pathname);
+
 	/* Add the node to the handle-to-node map. */
 	dev->handle = ++tree->current_handle;
@@ -1064,5 +1073,4 @@
 
 	/* Add the node to the list of its parent's children. */
-	printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);
 	dev->pfun = pfun;
 	pfun->child = dev;
Index: uspace/srv/devman/main.c
===================================================================
--- uspace/srv/devman/main.c	(revision 0418050164f0ae33ce754da92e722d5809138eff)
+++ uspace/srv/devman/main.c	(revision 9b415c96f2f29f61f5d4f5f7ea3fd3b1ef1ea27a)
@@ -43,4 +43,5 @@
 #include <stdio.h>
 #include <errno.h>
+#include <str_error.h>
 #include <bool.h>
 #include <fibril_synch.h>
@@ -51,4 +52,5 @@
 #include <sys/stat.h>
 #include <ctype.h>
+#include <io/log.h>
 #include <ipc/devman.h>
 #include <ipc/driver.h>
@@ -71,5 +73,5 @@
 	driver_t *driver = NULL;
 
-	printf(NAME ": devman_driver_register \n");
+	log_msg(LVL_DEBUG, "devman_driver_register\n");
 	
 	iid = async_get_call(&icall);
@@ -88,5 +90,5 @@
 	}
 
-	printf(NAME ": the %s driver is trying to register by the service.\n",
+	log_msg(LVL_DEBUG, "The `%s' driver is trying to register.\n",
 	    drv_name);
 	
@@ -95,5 +97,5 @@
 	
 	if (driver == NULL) {
-		printf(NAME ": no driver named %s was found.\n", drv_name);
+		log_msg(LVL_ERROR, "No driver named `%s' was found.\n", drv_name);
 		free(drv_name);
 		drv_name = NULL;
@@ -106,5 +108,6 @@
 	
 	/* Create connection to the driver. */
-	printf(NAME ":  creating connection to the %s driver.\n", driver->name);
+	log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.\n",
+	    driver->name);
 	ipc_call_t call;
 	ipc_callid_t callid = async_get_call(&call);
@@ -118,5 +121,6 @@
 	set_driver_phone(driver, IPC_GET_ARG5(call));
 	
-	printf(NAME ": the %s driver was successfully registered as running.\n",
+	log_msg(LVL_NOTE, 
+	    "The `%s' driver was successfully registered as running.\n",
 	    driver->name);
 	
@@ -142,6 +146,6 @@
 	callid = async_get_call(&call);
 	if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
-		printf(NAME ": ERROR: devman_receive_match_id - invalid "
-		    "protocol.\n");
+		log_msg(LVL_ERROR, 
+		    "Invalid protocol when trying to receive match id.\n");
 		async_answer_0(callid, EINVAL); 
 		delete_match_id(match_id);
@@ -150,6 +154,5 @@
 	
 	if (match_id == NULL) {
-		printf(NAME ": ERROR: devman_receive_match_id - failed to "
-		    "allocate match id.\n");
+		log_msg(LVL_ERROR, "Failed to allocate match id.\n");
 		async_answer_0(callid, ENOMEM);
 		return ENOMEM;
@@ -165,6 +168,6 @@
 	if (rc != EOK) {
 		delete_match_id(match_id);
-		printf(NAME ": devman_receive_match_id - failed to receive "
-		    "match id string.\n");
+		log_msg(LVL_ERROR, "Failed to receive match id string: %s.\n",
+		    str_error(rc));
 		return rc;
 	}
@@ -172,5 +175,5 @@
 	list_append(&match_id->link, &match_ids->ids);
 	
-	printf(NAME ": received match id '%s', score = %d \n",
+	log_msg(LVL_DEBUG, "Received match id `%s', score %d.\n",
 	    match_id->id, match_id->score);
 	return rc;
@@ -228,5 +231,7 @@
 	if (ftype != fun_inner && ftype != fun_exposed) {
 		/* Unknown function type */
-		printf(NAME ": Error, unknown function type provided by driver!\n");
+		log_msg(LVL_ERROR, 
+		    "Unknown function type %d provided by driver.\n",
+		    (int) ftype);
 
 		fibril_rwlock_write_unlock(&tree->rwlock);
@@ -265,5 +270,5 @@
 	fibril_rwlock_write_unlock(&tree->rwlock);
 	
-	printf(NAME ": devman_add_function %s\n", fun->pathname);
+	log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")\n", fun->pathname);
 	
 	devman_receive_match_ids(match_count, &fun->match_ids);
@@ -347,6 +352,6 @@
 	devmap_register_class_dev(class_info);
 	
-	printf(NAME ": function'%s' added to class '%s', class name '%s' was "
-	    "asigned to it\n", fun->pathname, class_name, class_info->dev_name);
+	log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.\n",
+	    fun->pathname, class_name, class_info->dev_name);
 
 	async_answer_0(callid, EOK);
@@ -363,5 +368,5 @@
 	
 	initialize_running_driver(driver, &device_tree);
-	printf(NAME ": the %s driver was successfully initialized. \n",
+	log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.\n",
 	    driver->name);
 	return 0;
@@ -385,6 +390,6 @@
 	fid_t fid = fibril_create(init_running_drv, driver);
 	if (fid == 0) {
-		printf(NAME ": Error creating fibril for the initialization of "
-		    "the newly registered running driver.\n");
+		log_msg(LVL_ERROR, "Failed to create initialization fibril " \
+		    "for driver `%s' .\n", driver->name);
 		return;
 	}
@@ -484,6 +489,6 @@
 	 */
 	if (dev == NULL) {
-		printf(NAME ": devman_forward error - no device or function with "
-		    "handle %" PRIun " was found.\n", handle);
+		log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
+		    "function with handle %" PRIun " was found.\n", handle);
 		async_answer_0(iid, ENOENT);
 		return;
@@ -491,6 +496,7 @@
 
 	if (fun == NULL && !drv_to_parent) {
-		printf(NAME ": devman_forward error - cannot connect to "
-		    "handle %" PRIun ", refers to a device.\n", handle);
+		log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
+		    "connect to handle %" PRIun ", refers to a device.\n",
+		    handle);
 		async_answer_0(iid, ENOENT);
 		return;
@@ -513,6 +519,6 @@
 	
 	if (driver == NULL) {
-		printf(NAME ": devman_forward error - the device is not in %" PRIun
-		    " usable state.\n", handle);
+		log_msg(LVL_ERROR, "IPC forwarding refused - " \
+		    "the device %" PRIun " is not in usable state.\n", handle);
 		async_answer_0(iid, ENOENT);
 		return;
@@ -526,7 +532,7 @@
 	
 	if (driver->phone <= 0) {
-		printf(NAME ": devman_forward: cound not forward to driver %s ",
-		    driver->name);
-		printf("the driver's phone is %" PRIun ").\n", driver->phone);
+		log_msg(LVL_ERROR, 
+		    "Could not forward to driver `%s' (phone is %d).\n",
+		    driver->name, (int) driver->phone);
 		async_answer_0(iid, EINVAL);
 		return;
@@ -534,9 +540,11 @@
 
 	if (fun != NULL) {
-		printf(NAME ": devman_forward: forward connection to function %s to "
-		    "driver %s.\n", fun->pathname, driver->name);
+		log_msg(LVL_DEBUG, 
+		    "Forwarding request for `%s' function to driver `%s'.\n",
+		    fun->pathname, driver->name);
 	} else {
-		printf(NAME ": devman_forward: forward connection to device %s to "
-		    "driver %s.\n", dev->pfun->pathname, driver->name);
+		log_msg(LVL_DEBUG, 
+		    "Forwarding request for `%s' device to driver `%s'.\n",
+		    dev->pfun->pathname, driver->name);
 	}
 
@@ -570,6 +578,7 @@
 	async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
 	    IPC_FF_NONE);
-	printf(NAME ": devman_connection_devmapper: forwarded connection to "
-	    "device %s to driver %s.\n", fun->pathname, dev->drv->name);
+	log_msg(LVL_DEBUG, 
+	    "Forwarding devmapper request for `%s' function to driver `%s'.\n",
+	    fun->pathname, dev->drv->name);
 }
 
@@ -606,5 +615,5 @@
 static bool devman_init(void)
 {
-	printf(NAME ": devman_init - looking for available drivers.\n");
+	log_msg(LVL_DEBUG, "devman_init - looking for available drivers.\n");
 	
 	/* Initialize list of available drivers. */
@@ -612,13 +621,13 @@
 	if (lookup_available_drivers(&drivers_list,
 	    DRIVER_DEFAULT_STORE) == 0) {
-		printf(NAME " no drivers found.");
+		log_msg(LVL_FATAL, "no drivers found.");
 		return false;
 	}
 
-	printf(NAME ": devman_init  - list of drivers has been initialized.\n");
+	log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.\n");
 
 	/* Create root device node. */
 	if (!init_device_tree(&device_tree, &drivers_list)) {
-		printf(NAME " failed to initialize device tree.");
+		log_msg(LVL_FATAL, "Failed to initialize device tree.");
 		return false;
 	}
@@ -641,6 +650,11 @@
 	printf(NAME ": HelenOS Device Manager\n");
 
+	if (log_init(NAME, LVL_ERROR) != EOK) {
+		printf(NAME ": Error initializing logging subsystem.\n");
+		return -1;
+	}
+
 	if (!devman_init()) {
-		printf(NAME ": Error while initializing service\n");
+		log_msg(LVL_ERROR, "Error while initializing service.\n");
 		return -1;
 	}
@@ -650,8 +664,10 @@
 
 	/* Register device manager at naming service. */
-	if (service_register(SERVICE_DEVMAN) != EOK)
+	if (service_register(SERVICE_DEVMAN) != EOK) {
+		log_msg(LVL_ERROR, "Failed registering as a service.\n");
 		return -1;
-
-	printf(NAME ": Accepting connections\n");
+	}
+
+	printf(NAME ": Accepting connections.\n");
 	async_manager();
 
