Commit 3fc5f658 authored by Rom Walton's avatar Rom Walton

- Introduce boinclog, it basically creates a tab delimited file using

        the message log cache of the client.  Useful for debugging debt
        related issues using Excel or various databases.
        
    client/
        boinc_cmd.cpp
        boinc_log.cpp
    win_build/
        boinclog.vcproj (added)

svn path=/trunk/boinc/; revision=19686
parent 617b456d
......@@ -9459,3 +9459,14 @@ David 23 Nov 2009
html/inc/
prefs.inc
Rom 24 Nov 2009
- Introduce boinclog, it basically creates a tab delimited file using
the message log cache of the client. Useful for debugging debt
related issues using Excel or various databases.
client/
boinc_cmd.cpp
boinc_log.cpp
win_build/
boinclog.vcproj (added)
......@@ -127,9 +127,9 @@ char* next_arg(int argc, char** argv, int& i) {
const char* prio_name(int prio) {
switch (prio) {
case 1: return "low";
case 2: return "medium";
case 3: return "high";
case MSG_INFO: return "low";
case MSG_USER_ERROR: return "medium";
case MSG_INTERNAL_ERROR: return "high";
}
return "unknown";
}
......@@ -184,7 +184,7 @@ int main(int argc, char** argv) {
#if 1
retval = rpc.init(hostname, port);
if (retval) {
fprintf(stderr, "can't connect to %s\n", hostname?hostname:"local host");
fprintf(stderr, "can't connect to %s\n", strlen(hostname)?hostname:"local host");
exit(1);
}
#else
......
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// boinclog: command-line interface to a BOINC core client,
// using GUI RPCs.
//
// usage: boinccmd [--host hostname] [--passwd passwd] command
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
#include "boinc_win.h"
#endif
#if defined(_WIN32) && !defined(__CYGWIN32__)
#define snprintf _snprintf
#define strdate _strdate
#define strtime _strtime
#endif
#ifdef _WIN32
#include "win_util.h"
#else
#include "config.h"
#include <cstdio>
#include <cstring>
#include <unistd.h>
#endif
#include <vector>
#include <string>
using std::vector;
using std::string;
#include "gui_rpc_client.h"
#include "error_numbers.h"
#include "util.h"
#include "str_util.h"
#include "str_replace.h"
#include "url.h"
#include "version.h"
#include "common_defs.h"
#define ARGX2(s1,s2) (!strcmp(argv[i], s1)||!strcmp(argv[i], s2))
#define ARG(S) ARGX2("-"#S, "--"#S)
// Global variables
char g_log_filename[256];
int g_message_sequence;
void version(){
printf("boinclog, built from %s \n", PACKAGE_STRING );
exit(0);
}
void usage() {
fprintf(stderr, "\n\
usage: boinclog [--host hostname] [--passwd passwd]\n\n\
Commands:\n\
--version, -V show version of the logging tool\n\
"
);
exit(1);
}
void show_error(int retval) {
fprintf(stderr, "Error %d: %s\n", retval, boincerror(retval));
}
// Convert local time into a human readable format using RFC1123
//
std::string rfc1123time(time_t timestamp) {
struct tm conv = *gmtime(&timestamp);
char buf[256];
const char *day[] = {
"Sun","Mon","Tue","Wed","Thu","Fri","Sat"
};
const char *month[] = {
"Jan","Feb","Mar","Apr","May","Jun","Jul",
"Aug","Sep","Oct","Nov","Dec"
};
sprintf(buf,
"%s, %02i %s %i %02i:%02i:%02i GMT",
day[conv.tm_wday], conv.tm_mday, month[conv.tm_mon],
conv.tm_year+1900, conv.tm_hour, conv.tm_min, conv.tm_sec
);
return std::string(buf);
}
const char* prio_name(int prio) {
switch (prio) {
case MSG_INFO: return "low";
case MSG_USER_ERROR: return "medium";
case MSG_INTERNAL_ERROR: return "high";
}
return "unknown";
}
void update_display() {
system("cls");
printf("BOINC Log Conversion Client %s\n", PACKAGE_VERSION);
printf("Log file: %s\n", g_log_filename);
printf("%d message(s) processed.\n\n", g_message_sequence);
printf("Press CTRL-C to exit application.\n");
}
int main(int argc, char** argv) {
unsigned int i;
int retval, port=0;
RPC_CLIENT rpc;
MESSAGES msgs;
char hostname_buf[256], passwd_buf[256];
char *hostname = 0, *passwd = passwd_buf, *p;
char buf[256];
struct tm* ptm;
time_t timestamp;
FILE* f = NULL;
std::string msg_datetime;
std::string msg_project;
std::string msg_priority;
std::string msg_type;
std::string msg_body;
std::string msg_tmp;
strcpy(hostname_buf, "");
strcpy(passwd_buf, "");
strcpy(buf, "");
strcpy(g_log_filename, "");
g_message_sequence = 0;
#ifdef _WIN32
chdir_to_data_dir();
#endif
read_gui_rpc_password(passwd_buf);
#if defined(_WIN32) && defined(USE_WINSOCK)
WSADATA wsdata;
retval = WSAStartup( MAKEWORD( 1, 1 ), &wsdata);
if (retval) {
fprintf(stderr, "WinsockInitialize: %d\n", retval);
exit(1);
}
#endif
for (i=1; i<(unsigned int)argc; i++) {
if (0) {
} else if (ARG(h)) {
usage();
} else if (ARG(help)) {
usage();
} else if (ARG(V)) {
version();
} else if (ARG(version)) {
version();
} else if (ARG(host)) {
if ((i+1) == (unsigned int)argc) usage();
hostname = hostname_buf;
safe_strcpy(hostname_buf, argv[i+1]);
p = strchr(hostname, ':');
if (p) {
port = atoi(p+1);
*p=0;
}
} else if (ARG(passwd)) {
if ((i+1) == (unsigned int)argc) usage();
safe_strcpy(passwd_buf, argv[i+1]);
} else {
printf("Unknown option: %s\n", argv[i]);
usage();
}
}
retval = rpc.init(hostname, port);
if (retval) {
fprintf(stderr, "can't connect to %s\n", strlen(hostname)?hostname:"local host");
show_error(retval);
exit(1);
}
if (passwd) {
retval = rpc.authorize(passwd);
if (retval) {
fprintf(stderr, "authorization failure: %d\n", retval);
show_error(retval);
exit(1);
}
}
// Construct a unique filename for the output.
time(&timestamp);
ptm = localtime(&timestamp);
strftime(g_log_filename, sizeof(g_log_filename), "%Y%m%d%H%M.log", ptm);
// Open the new log file for output
f = fopen(g_log_filename, "w");
setbuf(f, NULL);
while(true) {
update_display();
msgs.clear();
rpc.get_messages(g_message_sequence, msgs);
for (i=0; i<msgs.messages.size(); i++) {
MESSAGE* pMsg = msgs.messages[i];
msg_datetime.clear();
msg_project.clear();
msg_priority.clear();
msg_type.clear();
msg_body.clear();
msg_datetime = rfc1123time((time_t)pMsg->timestamp);
msg_project = pMsg->project;
msg_priority = prio_name(pMsg->priority);
msg_body = pMsg->body;
if (pMsg->body[0] == '[') {
msg_type = pMsg->body.substr(1, pMsg->body.find(']') - 1);
}
// If a message type is found in the message body, remove it from
// the message body
if (!msg_type.empty()) {
msg_tmp = std::string("[") + msg_type + std::string("] ");
msg_body.replace(0, msg_tmp.size(), "");
}
// If line feeds are detected in the message body, replace them with
// the pipe symbol.
for (unsigned int j = 0; j < msg_body.size(); j++) {
if (msg_body[j] == '\n') msg_body[j] = '|';
}
// Dump to tab delimited file
fprintf(f,
"%s\t%s\t%s\t%s\t%s",
msg_datetime.c_str(),
msg_priority.c_str(),
msg_project.c_str(),
msg_type.c_str(),
msg_body.c_str()
);
g_message_sequence = pMsg->seqno;
}
boinc_sleep(1.0);
}
#if defined(_WIN32) && defined(USE_WINSOCK)
WSACleanup();
#endif
exit(retval);
}
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by boinc_cmd.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40000
#define _APS_NEXT_CONTROL_VALUE 1007
#define _APS_NEXT_SYMED_VALUE 102
#endif
#endif
// Microsoft Visual C++ generated resource script.
//
#include "boinc_cmd.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winresrc.h"
#include "version.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Neutral resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
#ifdef _WIN32
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
#if defined(_GRIDREPUBLIC)
#elif defined(_PROGRESSTHRUPROCESSORS)
#elif defined(_WCG)
IDI_MAIN_ICON ICON "res\\wcg.ico"
#else
IDI_MAIN_ICON ICON "res\\icon.ico"
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"boinc_log.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winresrc.h""\r\n"
"#include ""version.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Visual Studio 2005 Compatibility
//
#ifndef IDC_STATIC
#define IDC_STATIC (-1) // all static controls
#endif
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#if defined(_GRIDREPUBLIC)
VS_VERSION_INFO VERSIONINFO
FILEVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
PRODUCTVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "GridRepublic"
VALUE "FileDescription", "BOINC Log Conversion Client"
VALUE "FileVersion", BOINC_VERSION_STRING "\0"
VALUE "InternalName", "boinccmd"
VALUE "LegalCopyright", " 2003-2009 University of California"
VALUE "OriginalFilename", "boinclog.exe"
VALUE "ProductName", "BOINC client"
VALUE "ProductVersion", BOINC_VERSION_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#elif defined(_PROGRESSTHRUPROCESSORS)
VS_VERSION_INFO VERSIONINFO
FILEVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
PRODUCTVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Progress Thru Processors"
VALUE "FileDescription", "BOINC Log Conversion Client"
VALUE "FileVersion", BOINC_VERSION_STRING "\0"
VALUE "InternalName", "boinccmd"
VALUE "LegalCopyright", " 2003-2009 University of California"
VALUE "OriginalFilename", "boinclog.exe"
VALUE "ProductName", "BOINC client"
VALUE "ProductVersion", BOINC_VERSION_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#elif defined(_WCG)
VS_VERSION_INFO VERSIONINFO
FILEVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
PRODUCTVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "World Community Grid"
VALUE "FileDescription", "BOINC Log Conversion Client"
VALUE "FileVersion", BOINC_VERSION_STRING "\0"
VALUE "InternalName", "boinccmd"
VALUE "LegalCopyright", " 2003-2009 University of California"
VALUE "OriginalFilename", "boinclog.exe"
VALUE "ProductName", "BOINC client"
VALUE "ProductVersion", BOINC_VERSION_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#else
VS_VERSION_INFO VERSIONINFO
FILEVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
PRODUCTVERSION BOINC_MAJOR_VERSION,BOINC_MINOR_VERSION,BOINC_RELEASE,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Space Sciences Laboratory"
VALUE "FileDescription", "BOINC Log Conversion Client"
VALUE "FileVersion", BOINC_VERSION_STRING "\0"
VALUE "InternalName", "boinccmd"
VALUE "LegalCopyright", " 2003-2009 University of California"
VALUE "OriginalFilename", "boinclog.exe"
VALUE "ProductName", "BOINC client"
VALUE "ProductVersion", BOINC_VERSION_STRING "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment