diff --git a/wcfs/client/wcfs.cpp b/wcfs/client/wcfs.cpp index 707560bf867ac14c0f7e841d4adfd69d5471885d..561cd44006d418c568b9c7799e20fefefa269f02 100644 --- a/wcfs/client/wcfs.cpp +++ b/wcfs/client/wcfs.cpp @@ -163,7 +163,23 @@ error _Conn::_pinner(context::Context ctx) { _Conn& wconn = *this; xerr::Contextf E("pinner"); // NOTE pinner error goes to Conn::close who has its own context + for (int i=0; i <10; i++) + xlog::Fatalf("Hello from pinner! %d %s", i, "qqq zzz"); + error err = wconn.__pinner(ctx); + err = E(err); + + // if pinner fails, wcfs will kill us. + // log pinner error so the error is not hidden. + // print to stderr as well as by default log does not print to there. + // XXX also catch panic/exc ? + if (!(err == nil || errors::Is(err, context::canceled))) { // canceled = .close asks pinner to stop + xlog::Fatalf("CRITICAL: %s", v(err)); + xlog::Fatalf("CRITICAL: wcfs server will likely kill us soon."); + + fprintf(stderr, "CRITICAL: %s\n", v(err)); + fprintf(stderr, "CRITICAL: wcfs server will likely kill us soon.\n"); + } // mark the connection non-operational if the pinner fails wconn._downMu.lock(); @@ -173,28 +189,12 @@ error _Conn::_pinner(context::Context ctx) { } wconn._downMu.unlock(); - return E(err); + return err; } error _Conn::__pinner(context::Context ctx) { _Conn& wconn = *this; - // XXX panic/exc -> log.CRITICAL -#if 0 - // if pinner fails, wcfs will kill us. - // log pinner exception so the error is not hidden. - // print to stderr as well as by default log does not print to there. - def _(): - exc = sys.exc_info()[1] - if exc in (None, context.canceled): # canceled = .close asks pinner to stop - return - log.critical('pinner failed:', exc_info=1) - print('CRITICAL: pinner failed:', file=sys.stderr) - traceback.print_exc(file=sys.stderr) - print('\nCRITICAL: wcfs server will likely kill us soon.', file=sys.stderr) - defer(_) -#endif - PinReq req; error err; diff --git a/wcfs/client/wcfs_misc.cpp b/wcfs/client/wcfs_misc.cpp index 1702e0870f21c7aabf24b151cd1d3fdfea7b86dd..717fbdc7c67af877c6759f9ee36c481815e7f82c 100644 --- a/wcfs/client/wcfs_misc.cpp +++ b/wcfs/client/wcfs_misc.cpp @@ -241,6 +241,43 @@ error Contextf::operator() (error err) const { } // xerr:: +#include <golang/time.h> +#include <time.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/syscall.h> + +// xlog:: +namespace xlog { + +void __Logf(const char *file, int line, char level, const char *format, ...) { + double t = time::now(); + time_t t_int = time_t(t); + struct tm tm_loc; + localtime_r(&t_int, &tm_loc); + + char t_buf[32]; + strftime(t_buf, sizeof(t_buf), "%m%d %H:%M:%S", &tm_loc); + + int t_us = int((t-t_int)*1E6); + + pid_t tid = syscall(SYS_gettid); + + string prefix = fmt::sprintf("%c%s.%06d %d %s:%d] ", level, t_buf, t_us, tid, file, line); + // XXX better to emit prefix and msg in one go. + fprintf(stderr, "%s", v(prefix)); + + va_list argp; + va_start(argp, format); + vfprintf(stderr, format, argp); + va_end(argp); + + fprintf(stderr, "\n"); +} + +} // xlog + + // wcfs:: namespace wcfs { @@ -252,7 +289,7 @@ static string h016(uint64_t v) { return fmt::sprintf("%016lx", v); } template<> string v_(zodb::Tid tid) { return h016(tid); } //template<> string v_(zodb::Oid oid) { return h016(oid); } // XXX Tid and Oid are typedefs for uint64_t and C++ reduces template -// specializations to theunderlying type. This providing specialization for +// specializations to the underlying type. This providing specialization for // both Tid and Oid results in "multiple definition" error. } // wcfs:: diff --git a/wcfs/client/wcfs_misc.h b/wcfs/client/wcfs_misc.h index 3f95f5428717cae33505d0c66cbc0b85748f074c..b18af86dce1374d4ce367340fe6d0a0072a54876 100644 --- a/wcfs/client/wcfs_misc.h +++ b/wcfs/client/wcfs_misc.h @@ -168,6 +168,15 @@ public: } // xerr:: +// xlog:: +namespace xlog { + +#define Fatalf(format, ...) __Logf(__FILE__, __LINE__, 'F', format, ##__VA_ARGS__) +void __Logf(const char *file, int line, char level, const char *format, ...); + +} // xlog:: + + // wcfs:: namespace wcfs {