How to get syntax and logical ORA in a trace file?
You can trace specific errors like below:
SQL&gt; alter session set events '1722 trace name errorstack level 1';

Session altered.

SQL&gt; SELECT TO_NUMBER('asdf') from dual;
SELECT TO_NUMBER('asdf') from dual
                 *
ERROR at line 1:
ORA-01722: invalid number

In the trace file:
*** 2020-10-15T18:56:23.811818+02:00
*** SESSION ID:(18.12475) 2020-10-15T18:56:23.811837+02:00
*** CLIENT ID:() 2020-10-15T18:56:23.811841+02:00
*** SERVICE NAME:(SYS$USERS) 2020-10-15T18:56:23.811845+02:00
*** MODULE NAME:(SQL*Plus) 2020-10-15T18:56:23.811849+02:00
*** ACTION NAME:() 2020-10-15T18:56:23.811853+02:00
*** CLIENT DRIVER:(SQL*PLUS) 2020-10-15T18:56:23.811856+02:00

dbkedDefDump(): Starting a non-incident diagnostic dump (flags=0x0, level=1, mask=0x0)
----- Error Stack Dump -----
&lt;error barrier&gt; at 0x7ffdfe31ce40 placed dbkda.c@296
ORA-01722: invalid number
----- Current SQL Statement for this session (sql_id=bkusfcu38gbjr) -----
SELECT TO_NUMBER('asdf') from dual

To log them, you can use a servererror trigger as shown here:
Is it possible in Oracle to trace SQL statements that result in errors?