Florian,
If you want an example, import one of the supplied monitoring applications. For example, License Monitor. They include code to check for the existence of the Logging Database. You could use this as a sample.
Set errormode = 0; // suppress reload failure in case of no database
LIB CONNECT TO 'QLogs';
// If there is an error connecting to logging database...
LET tempErrorDetails = ScriptErrorDetails;
IF Len(tempErrorDetails) > 0 THEN
trace ERROR: $(tempErrorDetails);
CALL monitor_app_reload_stats('WARN','$(textFile)', tempErrorDetails, 'Status Message')
tempErrorDetails =; // Reset this variable
TRACE Could not validate active database logging. Sourcing from file logs instead.;
SET db_v_file = 1;
LET baseTableName = '$(baseTableName)_file'; // Store log history QVD with suffix _file so it only gets used with file logging
LET lastReloadCompare = If(LastReloadSource=1,lastReloadCompare,cutoffDate); // If last reload loaded from db and now from file
// we want to start over and pull data from cutoffdate
TRACE Last Reload Compare time = $(lastReloadCompare). CutoffDate = $(cutoffDate).;
SET errormode=1;
EXIT SUB;