00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "LogCommand.h"
00019 #include "debug/Log.h"
00020
00021 namespace oasys {
00022
00023 LogCommand::LogCommand()
00024 : TclCommand("log")
00025 {
00026 bind_var(new StringOpt("logfile", &Log::instance()->logfile_,
00027 "file", "The pathname to the logfile."));
00028
00029 add_to_help("<path> <level> <string>",
00030 "Log message string with path, level");
00031 add_to_help("prefix <prefix>", "Set logging prefix");
00032 add_to_help("rotate", "Rotate the log file");
00033 add_to_help("dump_rules", "Show log filter rules");
00034 add_to_help("reparse", "Reparse the rules file");
00035 }
00036
00037 int
00038 LogCommand::exec(int argc, const char** argv, Tcl_Interp* interp)
00039 {
00040 (void)interp;
00041
00042
00043 if (argc == 3 && !strcmp(argv[1], "prefix")) {
00044 Log::instance()->set_prefix(argv[2]);
00045 logf("/log", LOG_DEBUG, "set logging prefix to '%s'", argv[2]);
00046 return TCL_OK;
00047 }
00048
00049
00050 if (argc == 2 && !strcmp(argv[1], "rotate")) {
00051 Log::instance()->rotate();
00052 return TCL_OK;
00053 }
00054
00055
00056 if (argc == 2 && !strcmp(argv[1], "dump_rules")) {
00057 StringBuffer buf;
00058 Log::instance()->dump_rules(&buf);
00059 set_result(buf.c_str());
00060 return TCL_OK;
00061 }
00062
00063
00064 if (argc == 2 &&
00065 (strcmp(argv[1], "reparse_debug_file") == 0 ||
00066 strcmp(argv[1], "reparse") == 0))
00067 {
00068 Log::instance()->parse_debug_file();
00069 return TCL_OK;
00070 }
00071
00072
00073 if (argc != 4) {
00074 wrong_num_args(argc, argv, 1, 4, 4);
00075 return TCL_ERROR;
00076 }
00077
00078 log_level_t level = str2level(argv[2]);
00079 if (level == LOG_INVALID) {
00080 resultf("invalid log level %s", argv[2]);
00081 return TCL_ERROR;
00082 }
00083
00084 logf(argv[1], level, argv[3]);
00085
00086 return TCL_OK;
00087 }
00088
00089 }