#include #include "nsd.h" void NsModLogRegSubRealm (char *name, Ns_ModLogHandle *handle) { /* Let's hope all the names are static... */ *handle = name; } void Ns_ModLog (Ns_LogSeverity level, Ns_ModLogHandle where, const char *fmt, ...) { va_list args; char *msg; va_start (args, fmt); msg = ap_pvsprintf (TCL_POOL(), fmt, args); if (where == NULL) where = "unknown"; if (Tcl_request_rec != NULL) ap_log_rerror (where, 0, level, Tcl_request_rec, "[uri: %s]\n %s", Tcl_request_rec->uri, msg); else ap_log_error (where, 0, level, Tcl_server, "%s", msg); va_end (args); } void Ns_Log (Ns_LogSeverity level, const char *fmt, ...) { va_list args; char *msg; va_start (args, fmt); msg = ap_pvsprintf (TCL_POOL(), fmt, args); if (Tcl_request_rec != NULL) ap_log_rerror ("unknown", 0, level, Tcl_request_rec, "[uri: %s]\n %s", Tcl_request_rec->uri, msg); else ap_log_error ("unknown", 0, level, Tcl_server, "%s", msg); va_end (args); } void LogError (char *s) { if (Tcl_request_rec != NULL) ap_log_rerror ("Huh?", 0, APLOG_ERR, Tcl_request_rec, "%s got an error. On what arguments? Who knows?", s); else ap_log_error ("Huh?", 0, APLOG_ERR, Tcl_server, "%s got an error. On what arguments? Who knows?", s); } /* *---------------------------------------------------------------------- * * GetSeverity -- * * Convert a string severity name into an Ns_LogSeverity. * * Results: * Tcl result. * * Side effects: * Errors will be appended to interp->result. * *---------------------------------------------------------------------- */ static int GetSeverity(Tcl_Interp *interp, char *severityStr, Ns_LogSeverity *severityPtr) { if (STRIEQ(severityStr, "fatal")) { *severityPtr = Fatal; } else if (STRIEQ(severityStr, "error")) { *severityPtr = Error; } else if (STRIEQ(severityStr, "warning")) { *severityPtr = Warning; } else if (STRIEQ(severityStr, "bug")) { *severityPtr = Bug; } else if (STRIEQ(severityStr, "notice")) { *severityPtr = Notice; } else if (STRIEQ(severityStr, "debug")) { *severityPtr = Debug; } else if (STRIEQ(severityStr, "dev")) { *severityPtr = Dev; } else { Tcl_AppendResult(interp, "unknown severity \"", severityStr, "\": should be one of: ", "fatal, error, warning, bug, notice, or debug.", NULL); return TCL_ERROR; } return TCL_OK; } /* *---------------------------------------------------------------------- * * NsTclLogCmd, NsTclModLogCmd -- * * Implements ns_log and ns_modlog commands. * * Results: * Tcl result. * * Side effects: * See docs. * *---------------------------------------------------------------------- */ static int TclLog(Tcl_Interp *interp, Ns_ModLogHandle *handle, char *sevstr, int msgc, char **msgv) { Ns_LogSeverity severity; char *msg; if (GetSeverity(interp, sevstr, &severity) != TCL_OK) { return TCL_ERROR; } if (msgc == 1) { msg = msgv[0]; } else { msg = Tcl_Concat(msgc, msgv); } Ns_ModLog(severity, *handle, "%s", msg); if (msg != msgv[0]) { ckfree(msg); } return TCL_OK; } int NsTclLogCmd(ClientData dummy, Tcl_Interp *interp, int argc, char **argv) { char *bogushandle = NULL; if (argc < 3) { Tcl_AppendResult(interp, "wrong # of args: should be \"", argv[0], " severity string ?string ...?\"", NULL); return TCL_ERROR; } return TclLog(interp, &bogushandle, argv[1], argc-2, argv+2); } int NsTclModLogCmd(ClientData dummy, Tcl_Interp *interp, int argc, char **argv) { if (argc < 4) { Tcl_AppendResult(interp, "wrong # of args: should be \"", argv[0], " severity realm string ?string ...?\"", NULL); return TCL_ERROR; } return TclLog(interp, &argv[2], argv[1], argc-3, argv+3); }