summaryrefslogtreecommitdiff
path: root/common/filelist-vfs-intf.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2024-01-19 18:26:34 +0100
committerTomas Bzatek <tbzatek@redhat.com>2024-01-19 18:26:34 +0100
commita55d09bb2d74944b7ea5a7e81b7d3e86bc04cd42 (patch)
tree7b2229b1fce0b342d1968069eae98a3be4afc3a8 /common/filelist-vfs-intf.c
parente9036281ebb3a5be97e42f56667bb8dfebc5b4fe (diff)
downloadtuxcmd-modules-a55d09bb2d74944b7ea5a7e81b7d3e86bc04cd42.tar.xz
common: Logging rework
Use common logging macros for a consistent output. A logging domain needs to be set in a Makefile first (the _LOG_DOMAIN define). Heavy debugging output is guarded by the __DEBUG_INTERNAL define and omitted by default. Logging severity is controlled by the TUXCMD_DEBUG env. var, typically set by the tuxcmd process itself.
Diffstat (limited to 'common/filelist-vfs-intf.c')
-rw-r--r--common/filelist-vfs-intf.c41
1 files changed, 19 insertions, 22 deletions
diff --git a/common/filelist-vfs-intf.c b/common/filelist-vfs-intf.c
index afb7a85..9517084 100644
--- a/common/filelist-vfs-intf.c
+++ b/common/filelist-vfs-intf.c
@@ -24,6 +24,7 @@
#include "tuxcmd-vfs.h"
#include "strutils.h"
+#include "logutils.h"
#include "vfsutils.h"
#include "filelist.h"
#include "filelist-vfs-intf.h"
@@ -39,8 +40,6 @@ vfs_filelist_new (struct PathTree *files)
struct VfsFilelistData * data;
data = g_malloc0 (sizeof (struct VfsFilelistData));
-
- log ("vfs_filelist_new()\n");
data->files = files;
return data;
@@ -49,10 +48,8 @@ vfs_filelist_new (struct PathTree *files)
void
vfs_filelist_free (struct VfsFilelistData *data)
{
- if (! data) {
- fprintf (stderr, "vfs_filelist_free: data == NULL !\n");
+ if (data == NULL)
return;
- }
g_free (data->list_dir_path);
g_free (data);
}
@@ -75,7 +72,7 @@ internal_get_dir_size (struct VfsFilelistData *data, struct PathTree *tree)
if (data->break_get_dir_size)
break;
if (n->data) {
- log ("internal_get_dir_size: found item '%s', size = %zd \n", n->node, n->data->iSize);
+ log_debug ("internal_get_dir_size: found item '%s', size = %zd", n->node, n->data->iSize);
Size += (n->data->ItemType == vDirectory) ? internal_get_dir_size (data, n) : n->data->iSize;
}
idx++;
@@ -97,7 +94,7 @@ vfs_filelist_get_dir_size (struct VfsFilelistData *data, const char *APath)
if (node) {
return internal_get_dir_size (data, node);
} else {
- printf ("(EE) VFSGetDirSize: path '%s' not found\n", APath);
+ log_error ("VFSGetDirSize: path '%s' not found", APath);
return 0;
}
}
@@ -142,20 +139,20 @@ vfs_filelist_file_info (struct VfsFilelistData *data, const char *AFileName, gbo
node = filelist_tree_find_node_by_path (data->files, AFileName);
if (node) {
if (node->data) {
- printf ("(II) vfs_filelist_file_info: found file: '%s'\n", node->node);
+ log_debug ("vfs_filelist_file_info: found file: '%s'", node->node);
return assign_file_info (node, AFileName, FollowSymlinks, AddFullPath);
} else {
- printf ("(EE) vfs_filelist_file_info: node->data == NULL! \n");
+ log_error ("vfs_filelist_file_info: node->data == NULL!");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED, "node->data == NULL");
return NULL;
}
} else {
- printf ("(EE) vfs_filelist_file_info: file specified not found\n");
+ log_error ("vfs_filelist_file_info: file specified not found");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "File specified not found.");
return NULL;
}
} else {
- printf ("(EE) vfs_filelist_file_info: Invalid pointers to data objects.\n");
+ log_error ("vfs_filelist_file_info: Invalid pointers to data objects.");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid pointers to data objects.");
return NULL;
}
@@ -172,7 +169,7 @@ vfs_filelist_list_first (struct VfsFilelistData *data, const char *sDir, gboolea
data->list_dir_node = NULL;
if (sDir == NULL) {
- printf ("(EE) vfs_filelist_list_first: sDir is NULL!\n");
+ log_error ("vfs_filelist_list_first: sDir is NULL!");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "NewPath is NULL");
return NULL;
}
@@ -192,14 +189,14 @@ vfs_filelist_list_first (struct VfsFilelistData *data, const char *sDir, gboolea
full_path = g_build_filename (sDir, node->data->FName, NULL);
Item = assign_file_info (node, full_path, FollowSymlinks, AddFullPath);
g_free (full_path);
- printf ("(II) vfs_filelist_list_first: found file: %s\n", Item->FName);
+ log_debug ("vfs_filelist_list_first: found file: %s", Item->FName);
return Item;
} else {
- printf ("(II) vfs_filelist_list_first: no more files\n");
+ log_debug ("vfs_filelist_list_first: no more files");
return NULL;
}
} else {
- printf ("(EE) vfs_filelist_list_first: Directory '%s' not found.\n", sDir);
+ log_error ("vfs_filelist_list_first: Directory '%s' not found.", sDir);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Directory '%s' not found.", sDir);
return NULL;
}
@@ -214,7 +211,7 @@ vfs_filelist_list_next (struct VfsFilelistData *data, GError **error)
full_path = NULL;
if (! data->list_dir_node) {
- printf ("(EE) vfs_filelist_list_next: data->list_dir_node is NULL!\n");
+ log_error ("vfs_filelist_list_next: data->list_dir_node is NULL!");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED, "data->list_dir_node is NULL");
return NULL;
}
@@ -226,10 +223,10 @@ vfs_filelist_list_next (struct VfsFilelistData *data, GError **error)
full_path = g_build_filename (data->list_dir_path, node->data->FName, NULL);
Item = assign_file_info (node, full_path, data->follow_symlinks, data->add_full_path);
g_free (full_path);
- printf ("(II) vfs_filelist_list_next: found file: %s\n", Item->FName);
+ log_debug ("vfs_filelist_list_next: found file: %s", Item->FName);
return Item;
} else {
- printf ("(II) vfs_filelist_list_next: no more files\n");
+ log_debug ("vfs_filelist_list_next: no more files");
return NULL;
}
}
@@ -253,23 +250,23 @@ vfs_filelist_change_dir (struct VfsFilelistData *data, const char *NewPath, GErr
char *ANewPath;
if (NewPath == NULL) {
- printf ("(EE) VFSChangeDir: NewPath is NULL!\n");
+ log_error ("VFSChangeDir: NewPath is NULL!");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "NewPath is NULL");
return NULL;
}
/* make up the target path */
- printf ("(--) VFSChangeDir: Going to change dir from '%s'\n", NewPath);
+ log_debug ("VFSChangeDir: Going to change dir from '%s'", NewPath);
ANewPath = exclude_trailing_path_sep (NewPath);
if (! ANewPath || strlen (ANewPath) <= 0)
ANewPath = g_strdup ("/");
- printf ("(--) VFSChangeDir: Going to change dir to '%s'\n", ANewPath);
+ log_debug ("VFSChangeDir: Going to change dir to '%s'", ANewPath);
/* find the directory in the filelist */
if (filelist_tree_find_node_by_path (data->files, ANewPath)) {
return ANewPath;
} else {
- printf ("(EE) VFSChangeDir: Directory '%s' not found.\n", ANewPath);
+ log_error ("VFSChangeDir: Directory '%s' not found.", ANewPath);
g_free (ANewPath);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Directory '%s' not found.", ANewPath);
return NULL;