LogCommand.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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     // log prefix <string>
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     // log rotate
00050     if (argc == 2 && !strcmp(argv[1], "rotate")) {
00051         Log::instance()->rotate();
00052         return TCL_OK;
00053     }
00054     
00055     // dump rules
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     // log reparse_debug_file
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     // log path level string
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 } // namespace oasys

Generated on Sat Sep 8 08:43:30 2007 for DTN Reference Implementation by  doxygen 1.5.3