Changeset 375
- Timestamp:
- 03/09/06 19:10:55 (3 years ago)
- Files:
-
- nepenthes/trunk/nepenthes-core/include/LogManager.hpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/src/ConsoleLogger.cpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/src/LogManager.cpp (modified) (2 diffs)
- nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/trunk/nepenthes-core/include/LogManager.hpp
r321 r375 59 59 virtual void logf(uint32_t mask, const char *format, ...); 60 60 const char *getTagName(uint32_t bit); 61 uint32_t getTagId(const char *tag); 62 uint32_t parseTagString(const char *tagString); 61 uint32_t getTagId(const char *tag); 62 uint32_t parseTagString(const char *tagString); 63 void setColor(bool setting); 64 bool getColorSetting(); 63 65 64 66 private: 67 bool m_useColor; 65 68 list<LogHandlerEntry *> m_Loggers; 66 69 const char *m_Tags[MAX_TAGS]; // use vector instead? nepenthes/trunk/nepenthes-core/src/ConsoleLogger.cpp
r321 r375 122 122 123 123 #else 124 printf("[ \033[%d;1m%-5s\033[0m] %s", 124 if( m_LogManager->getColorSetting() ) 125 { 126 printf("[ \033[%d;1m%-5s\033[0m] %s", 125 127 g_ColorMap[level], tag.c_str(), message); 128 } 129 else 130 { 131 printf("%s", message); 132 } 126 133 #endif 127 134 } nepenthes/trunk/nepenthes-core/src/LogManager.cpp
r332 r375 44 44 for( int32_t i = 0; i < MAX_TAGS; i++ ) 45 45 m_Tags[i] = 0; 46 47 m_useColor = false; 46 48 } 47 49 … … 217 219 return mask; 218 220 } 221 222 void LogManager::setColor(bool setting) 223 { 224 m_useColor = setting; 225 } 226 227 bool LogManager::getColorSetting() 228 { 229 return m_useColor; 230 } nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp
r366 r375 78 78 using namespace nepenthes; 79 79 80 enum ColorSetting { colorAuto, colorAlways, colorNever }; 81 80 82 Nepenthes *g_Nepenthes; 81 83 /** … … 185 187 string rlpath; // ringlogger path, gets read from config 186 188 bool ringlog = false; 189 ColorSetting col = colorAuto; 187 190 188 191 #ifdef WIN32 … … 205 208 { "log", 1, 0, 'l' }, // FIXME 206 209 { "logging-help", 0, 0, 'L' }, // FIXME 207 { " no-color", 0, 0, 'o' }, // FIXME210 { "color", 1, 0, 'o' }, 208 211 { "chroot", 1, 0, 'r' }, 209 212 { "ringlog", 0, 0, 'R' }, … … 282 285 283 286 case 'o': // FIXME set nocolor on console 284 printf("This feature '%c' is todo\nquitting\n",c); 285 run=false; 287 if( !strcmp(optarg, "never") ) 288 col = colorNever; 289 else if( !strcmp(optarg, "always") ) 290 col = colorAlways; 291 else if( !strcmp(optarg, "auto") ) 292 col = colorAuto; 293 else 294 { 295 fprintf(stdout, "Invalid argument for --color; must be one of\n" 296 "`never', `always' or `auto'.\n"); 297 run = false; 298 } 299 286 300 break; 287 301 … … 416 430 if ( run == true || confcheck == true || filecheck == true) 417 431 { 432 switch( col ) 433 { 434 case colorAuto: 435 if( isatty(STDOUT_FILENO) ) 436 m_LogManager->setColor(true); 437 else 438 m_LogManager->setColor(false); 439 break; 440 case colorNever: 441 m_LogManager->setColor(false); 442 break; 443 case colorAlways: 444 m_LogManager->setColor(true); 445 break; 446 } 447 418 448 m_Config = new Config; 419 449 logInfo("Trying to load Nepenthes Configuration from %s \n",confpath); … … 1605 1635 helpstruct myopts[]= 1606 1636 { 1607 {"c", "config", "give path to Config File", SYSCONFDIR "/nepenthes.conf" }, 1608 {"C", "capabilities", "force kernel 'security' capabilities", "" }, 1609 {"d", "disk-log", "disk logging tags, see -L", "(no filter)" }, 1610 {"f", "file-check", "check file for known shellcode rmknown,rmnonop", "" }, 1611 {"h", "help", "show help", "" }, 1612 {"H", "large-help", "show help with default values", "" }, 1613 {"i", "info", "how to contact us", "" }, 1614 {"k", "check-config", "check config for syntax errors", "" }, 1615 {"l", "log", "console logging tags, see -L", "(no filter)" }, 1616 {"L", "logging-help", "display help for -d and -l", "" }, 1617 {"o", "no-color", "log without colors", "FIXME" }, 1618 {"r", "chroot", "chroot to", "default is not to set chroot"}, 1619 {"R", "ringlog", "use ringlogger instead of filelogger", "default is filelogger"}, 1620 {"u", "user", "set user to switch to", "default is not to switch"}, 1621 {"g", "group", "set group to switch to (use with -u)", "default is not to switch"}, 1637 {"c", "config=FILE", "use FILE as configuration file", SYSCONFDIR "/nepenthes.conf" }, 1638 {"C", "capabilities", "force kernel 'security' capabilities", 0 }, 1639 {"d", "disk-log", "disk logging tags, see -L", 0 }, 1640 {"f", "file-check=OPTS", "check file for known shellcode, OPTS can\n" 1641 " be any combination of `rmknown' and\n" 1642 " `rmnonop'; seperate by comma when needed", 0 }, 1643 {"h", "help", "display help", 0 }, 1644 {"H", "large-help", "display help with default values", 0 }, 1645 {"i", "info", "how to contact us", 0 }, 1646 {"k", "check-config", "check configuration file for syntax errors", 0 }, 1647 {"l", "log", "console logging tags, see -L", 0 }, 1648 {"L", "logging-help", "display help for -d and -l", 0 }, 1649 {"o", "color=WHEN", "control color usage. WHEN may be `never',\n" 1650 " `always' or `auto'", "`auto'" }, 1651 {"r", "chroot=DIR", "chroot to DIR after startup", "don't chroot" }, 1652 {"R", "ringlog", "use ringlogger instead of filelogger", "filelogger" }, 1653 {"u", "user=USER", "switch to USER after startup", "keep current user"}, 1654 {"g", "group=GROUP", "switch to GROUP after startup (use with -u)", "keep current group"}, 1622 1655 {"v", "version", "show version", "" }, 1623 {"w", "workingdir ", "where shall the process live", PREFIX},1656 {"w", "workingdir=DIR", "set the process' working dir to DIR", PREFIX }, 1624 1657 }; 1625 1658 show_version(); 1626 1659 1627 if ( defaults == true ) 1628 { 1629 for ( uint32_t i=0;i<sizeof(myopts)/sizeof(helpstruct);i++ ) 1630 { 1631 printf(" -%s,\t--%-12s %-30s %s\n", myopts[i].m_shortOpt, 1632 myopts[i].m_longOpt, 1633 myopts[i].m_Description, 1634 myopts[i].m_Default); 1635 } 1636 }else 1637 { 1638 for ( uint32_t i=0;i<sizeof(myopts)/sizeof(helpstruct);i++ ) 1639 { 1640 printf(" -%s,\t--%-12s %-30s\n", myopts[i].m_shortOpt, 1641 myopts[i].m_longOpt, 1642 myopts[i].m_Description 1643 ); 1644 } 1645 1660 for ( uint32_t i=0;i<sizeof(myopts)/sizeof(helpstruct);i++ ) 1661 { 1662 printf(" -%s, --%-19s %s\n", myopts[i].m_shortOpt, 1663 myopts[i].m_longOpt, 1664 myopts[i].m_Description); 1665 1666 if( defaults == true && myopts[i].m_Default ) 1667 { 1668 printf(" Default value/behaviour: %s\n", myopts[i].m_Default); 1669 } 1646 1670 } 1647 1671 }
