common: add some colors on startup (errors, warnings)

This commit is contained in:
Yehuda Sadeh 2009-04-28 11:02:55 -07:00
parent d99ed0a142
commit fd6e6d0cb5
4 changed files with 23 additions and 4 deletions

View File

@ -353,6 +353,7 @@ noinst_HEADERS = \
include/buffer.h\
include/byteorder.h\
include/ceph_fs.h\
include/color.h\
include/crc32c.h\
include/cstring.h\
include/encoding.h\

View File

@ -2,6 +2,8 @@
#include "config.h"
#include "tls.h"
#include "include/color.h"
void common_init(std::vector<const char*>& args, const char *module_type, bool daemon)
{
tls_init();
@ -9,8 +11,8 @@ void common_init(std::vector<const char*>& args, const char *module_type, bool d
g_daemon = daemon;
if (daemon) {
cout << " ** WARNING: Ceph is still under heavy development, and is only suitable for **\n";
cout << " ** testing and review. Do not trust it with important data. **" << std::endl;
cout << TEXT_YELLOW << " ** WARNING: Ceph is still under heavy development, and is only suitable for **" << TEXT_NORMAL << std::endl;
cout << TEXT_YELLOW << " ** testing and review. Do not trust it with important data. **" << TEXT_NORMAL << std::endl;
g_conf.daemonize = true;
g_conf.log_to_stdout = false;

View File

@ -34,6 +34,8 @@ using namespace std;
#include "common/Timer.h"
#include "common/common_init.h"
#include "include/color.h"
void usage()
{
cerr << "usage: cosd -i osdid [--osd-data=path] [--osd-journal=path] [--mkfs]" << std::endl;
@ -99,9 +101,10 @@ int main(int argc, const char **argv)
int w;
int r = OSD::peek_super(g_conf.osd_data, magic, fsid, w);
if (r < 0) {
cerr << " ** ERROR: unable to open OSD superblock on " << g_conf.osd_data << ": " << strerror(-r) << std::endl;
cerr << TEXT_RED << " ** " << TEXT_HAZARD << "ERROR: " << TEXT_RED
<< "unable to open OSD superblock on " << g_conf.osd_data << ": " << strerror(-r) << TEXT_NORMAL << std::endl;
if (r == -ENOTSUP)
cerr << " ** please verify that underlying storage supports xattrs" << std::endl;
cerr << TEXT_RED << " ** please verify that underlying storage supports xattrs" << TEXT_NORMAL << std::endl;
derr(0) << "unable to open OSD superblock on " << g_conf.osd_data << ": " << strerror(-r) << dendl;
exit(1);
}

13
src/include/color.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef __COLOR_H
#define __COLOR_H
#define TEXT_NORMAL "\033[0m"
#define TEXT_HAZARD "\033[5;31m"
#define TEXT_RED "\033[0;31m"
#define TEXT_GREEN "\033[0;32m"
#define TEXT_YELLOW "\033[0;33m"
#define TEXT_BLUE "\033[0;34m"
#define TEXT_MAGENTA "\033[0;35m"
#define TEXT_CYAN "\033[0;36m"
#endif