You can use the following query. Sum it up if you need space used by all databases on the server.
SELECT instance_name, cntr_value
FROM sys.dm_os_performance_counters
WHERE counter_name IN ('Data File(s) Size (KB)')
Log file is similar - counter_name is 'Log File(s) Size (KB)'. If you want to find only the used space in the log file, the counter_name is 'Log File(s) Used Size (KB)'.
EDIT:
Sorry, correction to above. You should look only for object_name = 'SQLServer:Databases'
SELECT instance_name, cntr_value
FROM sys.dm_os_performance_counters
WHERE counter_name IN ('Data File(s) Size (KB)')
AND object_name = 'SQLServer:Databases'