1

I know this is simple. I have a callback function callback below:

function callback($id = '121-01927'){
    watchdog('print', '%message : Sample',array('%message' => $id), WATCHDOG_DEBUG, $link = NULL);
}

After executing the callback function, I viewed watchdog table in my database, and it says there.

%message : Sample

It seems my placeholder %message is not substituted by the variable $id. Where am I missing?

1
  • Looks alright to me, have you tried using dpm($id) to make sure the variable is being set correctly?
    – Darvanen
    Apr 21, 2015 at 3:41

1 Answer 1

1

The placeholders are not supposed to be substituted in the database.

This is because the watchdog() function can be called from anywhere, for any user, with any language. Mid you call t() function, which usually does the placeholder substitutions and translation, that function used the current language to translate to. Now, if you call watchdog() to log an error for user A, whose language is de, the message should not be saved to the database as the de-translated string. That is why the english untranslated strong is stored.

When an administrator views the log (From Admin -> Reports -> Recent log items), Drupal does the translation call (t()) at that very moment. All entries will then be translated to the language the current user has configured.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy