[sheepdog] [PATCH 3/7] logger: add format_thread_name()
MORITA Kazutaka
morita.kazutaka at gmail.com
Tue Aug 13 12:09:27 CEST 2013
From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
This prepares for the next patch.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
lib/logger.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/lib/logger.c b/lib/logger.c
index 5fa892d..0c41f67 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -117,6 +117,19 @@ static int64_t max_logsize = 500 * 1024 * 1024; /*500MB*/
static pthread_mutex_t logsize_lock = PTHREAD_MUTEX_INITIALIZER;
+static const char *format_thread_name(char *str, size_t size, const char *name,
+ int idx)
+{
+ if (name && name[0] && idx)
+ snprintf(str, size, "%s %d", name, idx);
+ else if (name && name[0])
+ snprintf(str, size, "%s", name);
+ else
+ snprintf(str, size, "main");
+
+ return str;
+}
+
/*
* We need to set default log formatter because collie doesn't want to call
* select_log_formatter().
@@ -667,13 +680,7 @@ void set_thread_name(const char *name, bool show_idx)
void get_thread_name(char *name)
{
- if (worker_name && worker_idx)
- snprintf(name, MAX_THREAD_NAME_LEN, "%s %d",
- worker_name, worker_idx);
- else if (worker_name)
- snprintf(name, MAX_THREAD_NAME_LEN, "%s", worker_name);
- else
- snprintf(name, MAX_THREAD_NAME_LEN, "%s", "main");
+ format_thread_name(name, MAX_THREAD_NAME_LEN, worker_name, worker_idx);
}
--
1.7.9.5
More information about the sheepdog
mailing list