in src/generic/logutl.c [116:233]
int sendMsgToDestList(Tcl_Interp * interp, LogData * logData,
LogLevel * logLevel, Tcl_Obj * msg)
{
LogDest *logDest = NULL;
Tcl_Obj *fmsg = NULL;
Tcl_Obj *emsg = NULL; /* eval'd message */
Tcl_Obj *subst = NULL;
int res = 0;
int err = 0;
int i = 0;
LogDest **logDests = logData->listOfDests;
if ((interp == NULL) || (logDests == NULL) ||
(logLevel == NULL) || (msg == NULL))
return TCL_ERROR;
for (i = 0; i < logData->destSize; i++) {
logDest = logDests[i];
if (logDest != NULL) {
if ((logDest->plugIn != NULL) &&
(logDest->plugIn->handler != NULL) &&
(logDest->plugInData != NULL) &&
(logDest->filter != NULL) && (logDest->format != NULL)) {
if (doesPass(logLevel, logDest->filter) == TCL_OK) {
/* ------------------------------------------------------------------
* do we need to eval the message ?
* --------------------------------------------------------------- */
if (logData->logSubst) {
/* message already evaluated ? */
if (emsg == NULL) {
/* no, evaluate now */
subst = Tcl_NewStringObj("subst", 5);
Tcl_IncrRefCount(subst);
if (Tcl_ListObjAppendElement(NULL, subst, msg) !=
TCL_OK) {
Tcl_DecrRefCount(subst);
err++;
}
else {
res =
Tcl_EvalObjEx(interp, subst,
TCL_EVAL_DIRECT);
Tcl_DecrRefCount(subst);
if (res != TCL_OK) {
err++;
}
else {
emsg = Tcl_GetObjResult(interp);
Tcl_IncrRefCount(emsg); /* keep */
Tcl_ResetResult(interp);
fmsg =
formatMessage(logLevel,
logDest->format,
logDest->maxCharInMsg,
emsg);
}
}
}
else {
/* already evaluated. format */
fmsg = formatMessage(logLevel, logDest->format,
logDest->maxCharInMsg, emsg);
}
}
else {
/* ----------------------------------------------------------------
* ..no, just format it
* ------------------------------------------------------------- */
fmsg = formatMessage(logLevel, logDest->format,
logDest->maxCharInMsg, msg);
}
/* ------------------------------------------------------------------
* fallback if subst did not work
* --------------------------------------------------------------- */
if (fmsg == NULL) {
fmsg = formatMessage(logLevel, logDest->format,
logDest->maxCharInMsg, msg);
}
/* ------------------------------------------------------------------
* and send it to the handler
* --------------------------------------------------------------- */
if (logDest->plugIn->handler(interp, logDest->plugInData,
Tcl_GetString(fmsg)) != TCL_OK)
err++;
Tcl_DecrRefCount(fmsg);
}
}
}
}
if (emsg != NULL) {
Tcl_DecrRefCount(emsg); /* need it no longer */
}
if (err > 0)
return TCL_ERROR;
return TCL_OK;
}