mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
Add option for prefixing timestamps
To make bees more friendly to use with syslog/systemd, we add an option to omit timestamps from the log output. Signed-off-by: Kai Krakow <kai@kaishome.de>
This commit is contained in:
parent
c6bf6bfe1d
commit
c6be07e158
@ -86,6 +86,11 @@ namespace crucible {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ChatterTimestamp {
|
||||||
|
public:
|
||||||
|
ChatterTimestamp(int);
|
||||||
|
};
|
||||||
|
|
||||||
class ChatterBox {
|
class ChatterBox {
|
||||||
string m_file;
|
string m_file;
|
||||||
int m_line;
|
int m_line;
|
||||||
|
@ -17,6 +17,7 @@ namespace crucible {
|
|||||||
|
|
||||||
static shared_ptr<set<string>> chatter_names;
|
static shared_ptr<set<string>> chatter_names;
|
||||||
static const char *SPACETAB = " \t";
|
static const char *SPACETAB = " \t";
|
||||||
|
static int chatter_prefix_timestamp = 1;
|
||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
@ -52,16 +53,21 @@ namespace crucible {
|
|||||||
{
|
{
|
||||||
ostringstream header_stream;
|
ostringstream header_stream;
|
||||||
|
|
||||||
time_t ltime;
|
if (chatter_prefix_timestamp) {
|
||||||
DIE_IF_MINUS_ONE(time(<ime));
|
time_t ltime;
|
||||||
struct tm ltm;
|
DIE_IF_MINUS_ONE(time(<ime));
|
||||||
DIE_IF_ZERO(localtime_r(<ime, <m));
|
struct tm ltm;
|
||||||
|
DIE_IF_ZERO(localtime_r(<ime, <m));
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", <m));
|
DIE_IF_ZERO(strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", <m));
|
||||||
|
|
||||||
|
header_stream << buf;
|
||||||
|
header_stream << " " << getpid() << "." << gettid();
|
||||||
|
} else {
|
||||||
|
header_stream << "tid " << gettid();
|
||||||
|
}
|
||||||
|
|
||||||
header_stream << buf;
|
|
||||||
header_stream << " " << getpid() << "." << gettid();
|
|
||||||
if (!m_name.empty()) {
|
if (!m_name.empty()) {
|
||||||
header_stream << " " << m_name;
|
header_stream << " " << m_name;
|
||||||
}
|
}
|
||||||
@ -91,6 +97,11 @@ namespace crucible {
|
|||||||
c.m_oss.str("");
|
c.m_oss.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChatterTimestamp::ChatterTimestamp(int prefix_timestamp)
|
||||||
|
{
|
||||||
|
chatter_prefix_timestamp = prefix_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
set<ChatterBox*> ChatterBox::s_boxes;
|
set<ChatterBox*> ChatterBox::s_boxes;
|
||||||
|
|
||||||
set<ChatterBox*>& ChatterBox::all_boxes()
|
set<ChatterBox*>& ChatterBox::all_boxes()
|
||||||
|
@ -49,7 +49,6 @@ BEESHOME="${BEESHOME:-$MNT_DIR/.beeshome}"
|
|||||||
BEESSTATUS="${BEESSTATUS:-$WORK_DIR/$UUID.status}"
|
BEESSTATUS="${BEESSTATUS:-$WORK_DIR/$UUID.status}"
|
||||||
DB_SIZE="${DB_SIZE:-$((64*AL16M))}"
|
DB_SIZE="${DB_SIZE:-$((64*AL16M))}"
|
||||||
LOG_SHORT_PATH="${LOG_SHORT_PATH:-N}"
|
LOG_SHORT_PATH="${LOG_SHORT_PATH:-N}"
|
||||||
LOG_FILTER_TIME="${LOG_FILTER_TIME:-N}"
|
|
||||||
|
|
||||||
INFO "Check: Disk exists"
|
INFO "Check: Disk exists"
|
||||||
if [ ! -b "/dev/disk/by-uuid/$UUID" ]; then
|
if [ ! -b "/dev/disk/by-uuid/$UUID" ]; then
|
||||||
@ -101,19 +100,6 @@ fi
|
|||||||
|
|
||||||
MNT_DIR="${MNT_DIR//\/\//\/}"
|
MNT_DIR="${MNT_DIR//\/\//\/}"
|
||||||
|
|
||||||
filter_time(){
|
|
||||||
if YN $LOG_FILTER_TIME; then
|
|
||||||
sed -e 's/^.*crawl:/crawl:/g' \
|
|
||||||
-e 's/^.*status:/status:/g' \
|
|
||||||
-e 's/^.*bees:/bees:/g' \
|
|
||||||
-e 's/^.*crawl_writeback:/crawl_writeback:/g' \
|
|
||||||
-e 's/^.*main:/main:/g' \
|
|
||||||
-e 's/^.*hash_prefetch:/hash_prefetch:/g'
|
|
||||||
else
|
|
||||||
cat
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
filter_path(){
|
filter_path(){
|
||||||
if YN $LOG_SHORT_PATH; then
|
if YN $LOG_SHORT_PATH; then
|
||||||
sed -e "s#$MNT_DIR##g"
|
sed -e "s#$MNT_DIR##g"
|
||||||
@ -122,6 +108,6 @@ filter_path(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@LIBEXEC_PREFIX@/bees "$MNT_DIR" 3>&1 2>&1 | filter_time | filter_path
|
@LIBEXEC_PREFIX@/bees $OPTIONS "$MNT_DIR" 3>&1 2>&1 | filter_path
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
18
src/bees.cc
18
src/bees.cc
@ -35,6 +35,8 @@ do_cmd_help(char *argv[])
|
|||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-h, --help\t\tShow this help\n"
|
"\t-h, --help\t\tShow this help\n"
|
||||||
|
"\t-t, --timestamps\tShow timestamps in log output (default)\n"
|
||||||
|
"\t-T, --notimestamps\tOmit timestamps in log output\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Optional environment variables:\n"
|
"Optional environment variables:\n"
|
||||||
"\tBEESHOME\tPath to hash table and configuration files\n"
|
"\tBEESHOME\tPath to hash table and configuration files\n"
|
||||||
@ -595,21 +597,31 @@ bees_main(int argc, char *argv[])
|
|||||||
|
|
||||||
THROW_CHECK1(invalid_argument, argc, argc >= 0);
|
THROW_CHECK1(invalid_argument, argc, argc >= 0);
|
||||||
|
|
||||||
|
// Defaults
|
||||||
|
int chatter_prefix_timestamp = 1;
|
||||||
|
|
||||||
// Parse options
|
// Parse options
|
||||||
int c;
|
int c;
|
||||||
while (1) {
|
while (1) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{ "help", no_argument, NULL, 'h' }
|
{ "timestamps", no_argument, NULL, 't' },
|
||||||
|
{ "notimestamps", no_argument, NULL, 'T' },
|
||||||
|
{ "help", no_argument, NULL, 'h' }
|
||||||
};
|
};
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "h", long_options, &option_index);
|
c = getopt_long(argc, argv, "Tth", long_options, &option_index);
|
||||||
if (-1 == c) {
|
if (-1 == c) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'T':
|
case 'T':
|
||||||
|
chatter_prefix_timestamp = 0;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
chatter_prefix_timestamp = 1;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
do_cmd_help(argv);
|
do_cmd_help(argv);
|
||||||
default:
|
default:
|
||||||
@ -617,6 +629,8 @@ bees_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChatterTimestamp cts(chatter_prefix_timestamp);
|
||||||
|
|
||||||
// Create a context and start crawlers
|
// Create a context and start crawlers
|
||||||
bool did_subscription = false;
|
bool did_subscription = false;
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user