Print field or global variable value in alert or console.log

How can we print the global/local variable value in UI?
I’m trying to gather add one validation but it’s not working so I thought to print the value first.

I’ve tried following in form view but didn’t worked.

<form name="my-form" title="MyForm"
      model="com.gpl.apps.db.MyDomain"
      width="large">
    <panel title="MyPanel">
        <field name="UserName" title="#{ __user__ }" />
    </panel>
</form>

Thanks…