mirror of
https://github.com/haiwen/seafile.git
synced 2025-01-09 04:17:30 +08:00
44ffce92b9
This algorithm is simplified and doesn't assume worktree and index. It just merge fs objects and write out merged fs objects. Now for repo operations on seahub, if there are concurrent updates, the two commits will be merged.
140 lines
3.3 KiB
C
140 lines
3.3 KiB
C
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
#include "common.h"
|
|
|
|
#include <stdio.h>
|
|
#include <glib/gstdio.h>
|
|
|
|
#include "log.h"
|
|
#include "utils.h"
|
|
|
|
/* message with greater log levels will be ignored */
|
|
static int ccnet_log_level;
|
|
static int seafile_log_level;
|
|
static FILE *logfp;
|
|
|
|
static void
|
|
seafile_log (const gchar *log_domain, GLogLevelFlags log_level,
|
|
const gchar *message, gpointer user_data)
|
|
{
|
|
time_t t;
|
|
struct tm *tm;
|
|
char buf[1024];
|
|
int len;
|
|
|
|
if (log_level > seafile_log_level)
|
|
return;
|
|
|
|
t = time(NULL);
|
|
tm = localtime(&t);
|
|
len = strftime (buf, 1024, "[%x %X] ", tm);
|
|
g_assert(len < 1024);
|
|
fputs (buf, logfp);
|
|
fputs (message, logfp);
|
|
fflush (logfp);
|
|
}
|
|
|
|
static void
|
|
ccnet_log (const gchar *log_domain, GLogLevelFlags log_level,
|
|
const gchar *message, gpointer user_data)
|
|
{
|
|
time_t t;
|
|
struct tm *tm;
|
|
char buf[1024];
|
|
int len;
|
|
|
|
if (log_level > ccnet_log_level)
|
|
return;
|
|
|
|
t = time(NULL);
|
|
tm = localtime(&t);
|
|
len = strftime (buf, 1024, "[%x %X] ", tm);
|
|
g_assert(len < 1024);
|
|
fputs (buf, logfp);
|
|
fputs (message, logfp);
|
|
fflush (logfp);
|
|
}
|
|
|
|
static int
|
|
get_debug_level(const char *str, int default_level)
|
|
{
|
|
if (strcmp(str, "debug") == 0)
|
|
return G_LOG_LEVEL_DEBUG;
|
|
if (strcmp(str, "info") == 0)
|
|
return G_LOG_LEVEL_INFO;
|
|
if (strcmp(str, "warning") == 0)
|
|
return G_LOG_LEVEL_WARNING;
|
|
return default_level;
|
|
}
|
|
|
|
int
|
|
seafile_log_init (const char *logfile, const char *ccnet_debug_level_str,
|
|
const char *seafile_debug_level_str)
|
|
{
|
|
g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
|
|
| G_LOG_FLAG_RECURSION, seafile_log, NULL);
|
|
g_log_set_handler ("Ccnet", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
|
|
| G_LOG_FLAG_RECURSION, ccnet_log, NULL);
|
|
|
|
/* record all log message */
|
|
ccnet_log_level = get_debug_level(ccnet_debug_level_str, G_LOG_LEVEL_INFO);
|
|
seafile_log_level = get_debug_level(seafile_debug_level_str, G_LOG_LEVEL_DEBUG);
|
|
|
|
if (strcmp(logfile, "-") == 0)
|
|
logfp = stdout;
|
|
else {
|
|
logfile = ccnet_expand_path(logfile);
|
|
if ((logfp = g_fopen (logfile, "a+")) == NULL) {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static SeafileDebugFlags debug_flags = 0;
|
|
|
|
static GDebugKey debug_keys[] = {
|
|
{ "Transfer", SEAFILE_DEBUG_TRANSFER },
|
|
{ "Sync", SEAFILE_DEBUG_SYNC },
|
|
{ "Watch", SEAFILE_DEBUG_WATCH },
|
|
{ "Http", SEAFILE_DEBUG_HTTP },
|
|
{ "Merge", SEAFILE_DEBUG_MERGE },
|
|
{ "Other", SEAFILE_DEBUG_OTHER },
|
|
};
|
|
|
|
gboolean
|
|
seafile_debug_flag_is_set (SeafileDebugFlags flag)
|
|
{
|
|
return (debug_flags & flag) != 0;
|
|
}
|
|
|
|
void
|
|
seafile_debug_set_flags (SeafileDebugFlags flags)
|
|
{
|
|
g_message ("Set debug flags %#x\n", flags);
|
|
debug_flags |= flags;
|
|
}
|
|
|
|
void
|
|
seafile_debug_set_flags_string (const gchar *flags_string)
|
|
{
|
|
guint nkeys = G_N_ELEMENTS (debug_keys);
|
|
|
|
if (flags_string)
|
|
seafile_debug_set_flags (
|
|
g_parse_debug_string (flags_string, debug_keys, nkeys));
|
|
}
|
|
|
|
void
|
|
seafile_debug_impl (SeafileDebugFlags flag, const gchar *format, ...)
|
|
{
|
|
if (flag & debug_flags) {
|
|
va_list args;
|
|
va_start (args, format);
|
|
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
|
|
va_end (args);
|
|
}
|
|
}
|