rewrote logging facilities

svn path=/trunk/boinc/; revision=1376
This commit is contained in:
Karl Chen 2003-06-11 22:42:49 +00:00
parent 6d32b0abd9
commit 76bf2119cd
4 changed files with 321 additions and 32 deletions

View File

@ -174,37 +174,39 @@ bin_PROGRAMS = boinc_client
EXTRA_PROGRAMS = speed_stats
boinc_client_SOURCES = \
main.C \
account.C \
app.C \
client_state.C \
client_types.C \
cs_apps.C \
cs_files.C \
cs_scheduler.C \
file_names.C \
file_xfer.C \
hostinfo.C \
hostinfo_unix.C \
http.C \
log_flags.C \
net_stats.C \
net_xfer.C \
pers_file_xfer.C \
prefs.C \
scheduler_op.C \
speed_stats.C \
ss_logic.C \
time_stats.C \
../lib/app_ipc.C \
../lib/filesys.C \
../lib/language.C \
../lib/parse.C \
../lib/shmem.C \
../lib/md5_file.C \
../lib/md5.c \
../lib/crypt.C \
../lib/util.C
main.C \
account.C \
app.C \
client_state.C \
client_types.C \
cs_apps.C \
cs_files.C \
cs_scheduler.C \
file_names.C \
file_xfer.C \
hostinfo.C \
hostinfo_unix.C \
http.C \
log_flags.C \
net_stats.C \
net_xfer.C \
pers_file_xfer.C \
prefs.C \
scheduler_op.C \
speed_stats.C \
ss_logic.C \
time_stats.C \
client_messages.C \
../lib/app_ipc.C \
../lib/filesys.C \
../lib/language.C \
../lib/parse.C \
../lib/shmem.C \
../lib/md5_file.C \
../lib/md5.c \
../lib/crypt.C \
../lib/util.C \
../lib/messages.C
boinc_client_DEPENDENCIES = $(LIBRSA)
@ -250,11 +252,12 @@ am_boinc_client_OBJECTS = boinc_client-main.$(OBJEXT) \
boinc_client-speed_stats.$(OBJEXT) \
boinc_client-ss_logic.$(OBJEXT) \
boinc_client-time_stats.$(OBJEXT) \
boinc_client-client_messages.$(OBJEXT) \
boinc_client-app_ipc.$(OBJEXT) boinc_client-filesys.$(OBJEXT) \
boinc_client-language.$(OBJEXT) boinc_client-parse.$(OBJEXT) \
boinc_client-shmem.$(OBJEXT) boinc_client-md5_file.$(OBJEXT) \
boinc_client-md5.$(OBJEXT) boinc_client-crypt.$(OBJEXT) \
boinc_client-util.$(OBJEXT)
boinc_client-util.$(OBJEXT) boinc_client-messages.$(OBJEXT)
boinc_client_OBJECTS = $(am_boinc_client_OBJECTS)
am_speed_stats_OBJECTS = speed_stats.$(OBJEXT)
speed_stats_OBJECTS = $(am_speed_stats_OBJECTS)
@ -268,6 +271,7 @@ am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/boinc_client-account.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-app.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-app_ipc.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-client_messages.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-client_state.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-client_types.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-crypt.Po \
@ -285,6 +289,7 @@ am__depfiles_maybe = depfiles
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-main.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-md5.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-md5_file.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-messages.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-net_stats.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-net_xfer.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/boinc_client-parse.Po \
@ -360,6 +365,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-account.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-app.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-app_ipc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-client_messages.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-client_state.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-client_types.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-crypt.Po@am__quote@
@ -377,6 +383,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-md5.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-md5_file.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-messages.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-net_stats.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-net_xfer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/boinc_client-parse.Po@am__quote@
@ -899,6 +906,28 @@ boinc_client-time_stats.obj: time_stats.C
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o boinc_client-time_stats.obj `if test -f 'time_stats.C'; then $(CYGPATH_W) 'time_stats.C'; else $(CYGPATH_W) '$(srcdir)/time_stats.C'; fi`
boinc_client-client_messages.o: client_messages.C
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT boinc_client-client_messages.o -MD -MP -MF "$(DEPDIR)/boinc_client-client_messages.Tpo" \
@am__fastdepCXX_TRUE@ -c -o boinc_client-client_messages.o `test -f 'client_messages.C' || echo '$(srcdir)/'`client_messages.C; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/boinc_client-client_messages.Tpo" "$(DEPDIR)/boinc_client-client_messages.Po"; \
@am__fastdepCXX_TRUE@ else rm -f "$(DEPDIR)/boinc_client-client_messages.Tpo"; exit 1; \
@am__fastdepCXX_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='client_messages.C' object='boinc_client-client_messages.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/boinc_client-client_messages.Po' tmpdepfile='$(DEPDIR)/boinc_client-client_messages.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o boinc_client-client_messages.o `test -f 'client_messages.C' || echo '$(srcdir)/'`client_messages.C
boinc_client-client_messages.obj: client_messages.C
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT boinc_client-client_messages.obj -MD -MP -MF "$(DEPDIR)/boinc_client-client_messages.Tpo" \
@am__fastdepCXX_TRUE@ -c -o boinc_client-client_messages.obj `if test -f 'client_messages.C'; then $(CYGPATH_W) 'client_messages.C'; else $(CYGPATH_W) '$(srcdir)/client_messages.C'; fi`; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/boinc_client-client_messages.Tpo" "$(DEPDIR)/boinc_client-client_messages.Po"; \
@am__fastdepCXX_TRUE@ else rm -f "$(DEPDIR)/boinc_client-client_messages.Tpo"; exit 1; \
@am__fastdepCXX_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='client_messages.C' object='boinc_client-client_messages.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/boinc_client-client_messages.Po' tmpdepfile='$(DEPDIR)/boinc_client-client_messages.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o boinc_client-client_messages.obj `if test -f 'client_messages.C'; then $(CYGPATH_W) 'client_messages.C'; else $(CYGPATH_W) '$(srcdir)/client_messages.C'; fi`
boinc_client-app_ipc.o: ../lib/app_ipc.C
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT boinc_client-app_ipc.o -MD -MP -MF "$(DEPDIR)/boinc_client-app_ipc.Tpo" \
@am__fastdepCXX_TRUE@ -c -o boinc_client-app_ipc.o `test -f '../lib/app_ipc.C' || echo '$(srcdir)/'`../lib/app_ipc.C; \
@ -1075,6 +1104,28 @@ boinc_client-util.obj: ../lib/util.C
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o boinc_client-util.obj `if test -f '../lib/util.C'; then $(CYGPATH_W) '../lib/util.C'; else $(CYGPATH_W) '$(srcdir)/../lib/util.C'; fi`
boinc_client-messages.o: ../lib/messages.C
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT boinc_client-messages.o -MD -MP -MF "$(DEPDIR)/boinc_client-messages.Tpo" \
@am__fastdepCXX_TRUE@ -c -o boinc_client-messages.o `test -f '../lib/messages.C' || echo '$(srcdir)/'`../lib/messages.C; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/boinc_client-messages.Tpo" "$(DEPDIR)/boinc_client-messages.Po"; \
@am__fastdepCXX_TRUE@ else rm -f "$(DEPDIR)/boinc_client-messages.Tpo"; exit 1; \
@am__fastdepCXX_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../lib/messages.C' object='boinc_client-messages.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/boinc_client-messages.Po' tmpdepfile='$(DEPDIR)/boinc_client-messages.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o boinc_client-messages.o `test -f '../lib/messages.C' || echo '$(srcdir)/'`../lib/messages.C
boinc_client-messages.obj: ../lib/messages.C
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT boinc_client-messages.obj -MD -MP -MF "$(DEPDIR)/boinc_client-messages.Tpo" \
@am__fastdepCXX_TRUE@ -c -o boinc_client-messages.obj `if test -f '../lib/messages.C'; then $(CYGPATH_W) '../lib/messages.C'; else $(CYGPATH_W) '$(srcdir)/../lib/messages.C'; fi`; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/boinc_client-messages.Tpo" "$(DEPDIR)/boinc_client-messages.Po"; \
@am__fastdepCXX_TRUE@ else rm -f "$(DEPDIR)/boinc_client-messages.Tpo"; exit 1; \
@am__fastdepCXX_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='../lib/messages.C' object='boinc_client-messages.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/boinc_client-messages.Po' tmpdepfile='$(DEPDIR)/boinc_client-messages.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(boinc_client_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o boinc_client-messages.obj `if test -f '../lib/messages.C'; then $(CYGPATH_W) '../lib/messages.C'; else $(CYGPATH_W) '$(srcdir)/../lib/messages.C'; fi`
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \

55
client/client_messages.C Normal file
View File

@ -0,0 +1,55 @@
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
//
// The Initial Developer of the Original Code is the SETI@home project.
// Portions created by the SETI@home project are Copyright (C) 2002, 2003
// University of California at Berkeley. All Rights Reserved.
//
// Contributor(s):
//
#include "message.h"
#include "log_flags.h"
ClientMessages log_messages;
const char* ClientMessages::v_format_kind(int kind) const
{
switch(kind) {
case DEBUG_STATE: return "DEBUG_STATE ";
case DEBUG_TASK: return "DEBUG_TASK ";
case DEBUG_FILE_XFER: return "DEBUG_FILE_XFER ";
case DEBUG_SCHED_OP: return "DEBUG_SCHED_OP ";
case DEBUG_HTTP: return "DEBUG_HTTP ";
case DEBUG_TIME: return "DEBUG_TIME ";
case DEBUG_NET_XFER: return "DEBUG_NET_XFER ";
case DEBUG_MEASUREMENT: return "DEBUG_MEASUREMENT";
case DEBUG_POLL: return "DEBUG_POLL ";
default: return "*** internal error: invalid MessageKind ***";
}
}
bool ClientMessages::v_message_wanted(int kind) const
{
switch (kind) {
case DEBUG_STATE: return log_flags.state_debug;
case DEBUG_TASK: return log_flags.task_debug;
case DEBUG_FILE_XFER: return log_flags.file_xfer_debug;
case DEBUG_SCHED_OP: return log_flags.sched_op_debug;
case DEBUG_HTTP: return log_flags.http_debug;
case DEBUG_TIME: return log_flags.time_debug;
case DEBUG_NET_XFER: return log_flags.net_xfer_debug;
case DEBUG_MEASUREMENT: return log_flags.measurement_debug;
case DEBUG_POLL: return log_flags.poll_debug;
default: return false;
}
}

145
lib/messages.C Normal file
View File

@ -0,0 +1,145 @@
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
//
// The Initial Developer of the Original Code is the SETI@home project.
// Portions created by the SETI@home project are Copyright (C) 2002, 2003
// University of California at Berkeley. All Rights Reserved.
//
// Contributor(s):
//
#include "util.h"
#include <cassert>
#include <cstring>
#include <string>
#include <fstream>
using namespace std;
Messages::Messages(FILE* output_)
{
output = output_;
indent_level = 0;
spaces[0] = 0;
strcpy(spaces+1, " ");
}
void Messages::enter_level(int diff)
{
assert (indent_level >= 0);
spaces[indent_level] = ' ';
indent_level += diff*2;
spaces[indent_level] = 0;
assert (indent_level >= 0);
}
void Messages::vprintf(int kind, const char* format, va_list va)
{
if (!v_message_wanted(kind)) return;
fprintf(output, "%s [%s]%s ", timestamp(), v_format_kind(kind), spaces);
vfprintf(output, format, va);
}
// break a multi-line string into lines (so that we show prefix on each line)
void Messages::vprintf_multiline(int kind, const char* str, const char* prefix_format, va_list va)
{
if (!v_message_wanted(kind)) return;
if (str == NULL) return;
char sprefix[256] = "";
if (prefix_format) {
vsprintf(sprefix, prefix_format, va);
}
const char* now_timestamp = timestamp();
const char* skind = v_format_kind(kind);
string line;
while (*str) {
if (*str == '\n') {
fprintf(output, "%s [%s]%s %s%s\n", now_timestamp, skind, spaces, sprefix, line.c_str());
line.erase();
} else {
line += *str;
}
++str;
}
if (!line.empty()) {
fprintf(output, "%s %s[%s] %s%s\n", now_timestamp, spaces, skind, sprefix, line.c_str());
}
}
void Messages::vprintf_file(int kind, const char* filename, const char* prefix_format, va_list va)
{
if (!v_message_wanted(kind)) return;
char sprefix[256] = "";
if (prefix_format) {
vsprintf(sprefix, prefix_format, va);
}
const char* now_timestamp = timestamp();
const char* skind = v_format_kind(kind);
ifstream f(filename);
if (!f) return;
string line;
while (getline(f, line)) {
fprintf(output, "%s [%s]%s %s%s\n", now_timestamp, skind, spaces, sprefix, line.c_str());
}
}
void Messages::printf(int kind, const char* format, ...)
{
va_list va;
va_start(va, format);
vprintf(kind, format, va);
va_end(va);
}
void Messages::printf_multiline(int kind, const char* str, const char* prefix_format, ...)
{
va_list va;
va_start(va, prefix_format);
vprintf_multiline(kind, str, prefix_format, va);
va_end(va);
}
void Messages::printf_file(int kind, const char* filename, const char* prefix_format, ...)
{
va_list va;
va_start(va, prefix_format);
vprintf_file(kind, filename, prefix_format, va);
va_end(va);
}
void ScopeMessages::printf(const char* format, ...)
{
va_list va;
va_start(va, format);
messages.vprintf(kind, format, va);
va_end(va);
}
void ScopeMessages::printf_multiline(const char* str, const char* prefix_format, ...)
{
va_list va;
va_start(va, prefix_format);
messages.vprintf_multiline(kind, str, prefix_format, va);
va_end(va);
}
void ScopeMessages::printf_file(const char* filename, const char* prefix_format, ...)
{
va_list va;
va_start(va, prefix_format);
messages.vprintf_file(kind, filename, prefix_format, va);
va_end(va);
}

38
sched/sched_messages.C Normal file
View File

@ -0,0 +1,38 @@
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
//
// The Initial Developer of the Original Code is the SETI@home project.
// Portions created by the SETI@home project are Copyright (C) 2002, 2003
// University of California at Berkeley. All Rights Reserved.
//
// Contributor(s):
//
#include "sched_util.h"
#include <cstdarg>
SchedMessages log_messages;
const char* SchedMessages::v_format_kind(int kind) const
{
switch(kind) {
case CRITICAL: return "CRITICAL";
case NORMAL: return "normal ";
case DEBUG: return "debug ";
default: return "*** internal error: invalid MessageKind ***";
}
}
bool SchedMessages::v_message_wanted(int kind) const
{
return ( kind <= debug_level );
}