Skip to content

Commit

Permalink
Config to force stderr in the console (not in a dedicated file)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarre committed Feb 14, 2024
1 parent 653753f commit 9457c91
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 26 deletions.
15 changes: 15 additions & 0 deletions docs/install/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,21 @@ ZOO-Service translation files.
The location of the final ``.mo`` file may vary depending on your
system setup.

Logs on console (Optional)
************************

If needed (typically in case of Docker deployment), it is possible to force the logs
to be written on the console (stderr) :

::

$ ./configure --with-log-console=yes

.. warning::
Logging all services executions on the console can be tricky to troubleshoot in case
of parallel executions. A good solution is to log the job id in the code of the service
depending the language chosen.


Install ZOO-Services
--------------------
Expand Down
4 changes: 2 additions & 2 deletions zoo-project/zoo-kernel/ZOOMakefile.opts.in
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ MONO_LDFLAGS=@MONO_LDFLAGS@
MONO_ENABLED=@MONO_ENABLED@
MONO_FILE=@MONO_FILE@

CFLAGS=@CFLAGS@ @CALLBACK_USE@ @DRU_ENABLED@ @SSH2_CPPFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} ${RABBITMQ_CPPFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
CFLAGS=@CFLAGS@ @CALLBACK_USE@ @DRU_ENABLED@ @SSH2_CPPFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ @LOG_CONSOLE_ENABLED@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} ${RABBITMQ_CPPFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF

CPPFLAGS=@CXXFLAGS@ @CPPFLAGS@ @DRU_ENABLED@ @CALLBACK_USE@ @SSH2_CPPFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} ${RABBITMQ_CPPFLAGS} ${IRODS_CPPFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
CPPFLAGS=@CXXFLAGS@ @CPPFLAGS@ @DRU_ENABLED@ @CALLBACK_USE@ @SSH2_CPPFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ @LOG_CONSOLE_ENABLED@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} ${RABBITMQ_CPPFLAGS} ${IRODS_CPPFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF


LDFLAGS=-rdynamic @LDFLAGS@ @UUID_LDFLAGS@ -lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${RABBITMQ_LDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} ${NODEJSLDFLAGS} ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} ${RLDFLAGS} @JSON_LDFLAGS@ @XSLT_LDFLAGS@
Expand Down
15 changes: 15 additions & 0 deletions zoo-project/zoo-kernel/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,21 @@ AC_SUBST([CXXFLAGS])
AC_SUBST([CPPFLAGS])
AC_SUBST([LDFLAGS])

# ===========================================================================
# Detect if log to the console
# ===========================================================================
AC_ARG_WITH([log-console],
[AS_HELP_STRING([--with-log-console=yes], [Specifies that logs will be produced on console])],
[LOG_CONSOLE="$withval"], [LOG_CONSOLE=""])

if test "x$LOG_CONSOLE" = "xyes"; then
LOG_CONSOLE_ENABLED="-DLOG_CONSOLE_ENABLED"
else
LOG_CONSOLE_ENABLED=""
fi

AC_SUBST([LOG_CONSOLE_ENABLED])

AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([ZOOMakefile.opts])
AC_CONFIG_FILES([main.cfg])
Expand Down
3 changes: 3 additions & 0 deletions zoo-project/zoo-kernel/response_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,9 @@ int errorException(maps **pmsConf, const char *message, const char *errorcode, c
localPrintException(pmsConf,errormap);
setMapInMaps(*pmsConf,"lenv","no-headers","true");
}
#ifdef LOG_CONSOLE_ENABLED
logConsoleMessage(message);
#endif
freeMap(&errormap);
free(errormap);
return -1;
Expand Down
37 changes: 37 additions & 0 deletions zoo-project/zoo-kernel/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,43 @@ void logMessage(const char* pccSource, const char* pccFunction, int iLne, const
if (pcText != NULL) free(pcText);
}

#ifdef LOG_CONSOLE_ENABLED
/**
* Print message on console
*
* @param pccMessage the message to be print
*/
void logConsoleMessage(const char* pccMessage) {

// system time:
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::time_t now_t = std::chrono::system_clock::to_time_t(now);
std::tm* tm = localtime(&now_t);

char* pcStr = (char*)malloc(80 * sizeof(char));
strftime( pcStr, 80, "%Y-%m-%d %H:%M:%S", tm );
if (pccMessage == NULL)
return;

// Remove new line character and ' character in the message
int length = strlen(pccMessage);
char * pointer;
char * consoleMessage = (char *) malloc( sizeof( char) * (length+1) );
strcpy(consoleMessage, pccMessage);
while (pointer = strchr(consoleMessage, '\n')) {
*pointer = ' ';
}
while (pointer = strchr(consoleMessage, '\'')) {
*pointer = '"';
}

fprintf(stderr, "timestamp='%s' pid='%d' event='%s'\n", pcStr, zGetpid(), consoleMessage);
fflush(stderr);
free(pcStr);
free(consoleMessage);
}
#endif

// knut:
// Example:
// zooLog;
Expand Down
4 changes: 4 additions & 0 deletions zoo-project/zoo-kernel/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,7 @@ extern "C" {
#endif

#endif

#ifdef LOG_CONSOLE_ENABLED
void logConsoleMessage(const char*);
#endif
70 changes: 46 additions & 24 deletions zoo-project/zoo-kernel/zoo_service_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,11 @@ int _fetchService(registry* zooRegistry,maps* m,service** spService, map* reques
addToMap(error,"message",tmpMsg);
}
//setMapInMaps(conf,"lenv","status_code","404 Bad Request");
#ifdef LOG_CONSOLE_ENABLED
logConsoleMessage(tmpMsg);
#endif
funcError(&m,error);

//errorException (&m, tmpMsg, "InvalidParameterValue", "identifier");
free (tmpMsg);
free (*spService);
Expand Down Expand Up @@ -1848,7 +1851,9 @@ loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
if (libp != NULL && libp->value != NULL) {
r_inputs = getMap (s1->content, "ServiceProvider");
sprintf (tmps1, "%s/%s", libp->value, r_inputs->value);
#ifdef DEBUG
fprintf (stderr, "libpath1 + service provider : %s/%s", libp->value, r_inputs->value);
#endif
}
else {
r_inputs = getMap (request_inputs, "metapath");
Expand Down Expand Up @@ -2521,6 +2526,9 @@ runRequest (map ** inputs)
* Manage our own error log file (usefull to separate standard apache debug
* messages from the ZOO-Kernel ones but also for IIS users to avoid wrong
* headers messages returned by the CGI due to wrong redirection of stderr)
*
* This default configuration can be changed during the compilation of ZOO-kernel
* by passing --with-log-console=yes to force logs of service executions on stderr
*/
FILE *fstde = NULL;
map *fstdem = getMapFromMaps (m, "main", "logPath");
Expand Down Expand Up @@ -3900,7 +3908,7 @@ runRequest (map ** inputs)
#endif
if(cIdentifier!=NULL)
addToMap(request_inputs,"Identifier",cIdentifier);
if(fetchService(zooRegistry,m,&s1,request_inputs,ntmp,cIdentifier,localPrintExceptionJ)!=0){
if(fetchService(zooRegistry,m,&s1,request_inputs,conf_dir_,cIdentifier,localPrintExceptionJ)!=0){
// TODO: cleanup memory
register_signals(donothing);
freeService(&s1);
Expand Down Expand Up @@ -4068,21 +4076,24 @@ runRequest (map ** inputs)
sprintf (fbkp, "%s/%s.json", r_inputs->value,
usid->value);
setMapInMaps (m, "lenv", "file.responseInit", fbkp);
#ifdef DEBUG
fprintf (stderr, "RUN IN BACKGROUND MODE \n");
fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
zGetpid ());
fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
#endif

#ifndef LOG_CONSOLE_ENABLED
flog =
(char *)
malloc ((strlen (r_inputs->value) + strlen (oid->value) +
strlen (usid->value) + 13) * sizeof (char));
sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
oid->value, usid->value);
setMapInMaps (m, "lenv", "file.log", flog);
#ifdef DEBUG
fprintf (stderr, "RUN IN BACKGROUND MODE \n");
fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
zGetpid ());
fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
#endif
freopen (flog, "w+", stderr);
fflush (stderr);
#endif
f0 = freopen (fbkp, "w+", stdout);
rewind (stdout);
#ifndef WIN32
Expand Down Expand Up @@ -4404,7 +4415,7 @@ runRequest (map ** inputs)
setMapInMaps(m,"lenv","requestType","GetCapabilities");
int t=fetchServicesForDescription(NULL, &m, orig,
printGetCapabilitiesForProcessJ,
NULL, (void*) res3, ntmp,
NULL, (void*) res3, conf_dir_,
request_inputs,
localPrintExceptionJ);
if(t==1){
Expand Down Expand Up @@ -4432,7 +4443,7 @@ runRequest (map ** inputs)
cnt++;
}
fetchService(zooRegistry,m,&s1,
request_inputs,ntmp,cIdentifier,localPrintExceptionJ);
request_inputs,conf_dir_,cIdentifier,localPrintExceptionJ);

}
}
Expand Down Expand Up @@ -4909,7 +4920,7 @@ runRequest (map ** inputs)

r_inputs = getMap (request_inputs, "Identifier");

if(fetchService(zooRegistry,m,&s1,request_inputs,ntmp,r_inputs->value,printExceptionReportResponse)!=0){
if(fetchService(zooRegistry,m,&s1,request_inputs,conf_dir_,r_inputs->value,printExceptionReportResponse)!=0){
// Service not found clear memory
freeMaps(&m);
free(m);
Expand Down Expand Up @@ -5186,21 +5197,24 @@ runRequest (map ** inputs)
sprintf (fbkp, "%s/%s_%s.json", r_inputs->value, r_inputs1->value,
usid->value);
setMapInMaps (m, "lenv", "file.responseInit", fbkp);

#ifdef DEBUG
fprintf (stderr, "RUN IN BACKGROUND MODE \n");
fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
zGetpid ());
fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
#endif
#ifndef LOG_CONSOLE_ENABLED
flog =
(char *)
malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
strlen (usid->value) + 13) * sizeof (char));
sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
r_inputs1->value, usid->value);
setMapInMaps (m, "lenv", "file.log", flog);
#ifdef DEBUG
fprintf (stderr, "RUN IN BACKGROUND MODE \n");
fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
zGetpid ());
fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
#endif
freopen (flog, "w+", stderr);
fflush (stderr);
#endif
f0 = freopen (fbkp, "w+", stdout);
rewind (stdout);
#ifndef WIN32
Expand Down Expand Up @@ -5397,11 +5411,15 @@ runRequest (map ** inputs)
map* tMap=getMapFromMaps(m,"main","executionType");
if(tMap!=NULL && strncasecmp(tMap->value,"xml",3)==0)
InternetCloseHandle (&hInternet);
#ifdef DEBUG
fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
#endif
#ifndef LOG_CONSOLE_ENABLED
fflush(stderr);
fclose (stderr);
zUnlink (flog);
free (flog);
#endif
}
else{
//InternetCloseHandle (&hInternet);
Expand Down Expand Up @@ -5640,7 +5658,7 @@ runAsyncRequest (maps** iconf, map ** lenv, map ** irequest_inputs,json_object *
// Reset metapath
addToMap(request_inputs,"metapath","");
setMapInMaps(lconf,"lenv","metapath","");
if(fetchService(zooRegistry,lconf,&s1,request_inputs,ntmp,r_inputs->value,printExceptionReportResponse)!=0){
if(fetchService(zooRegistry,lconf,&s1,request_inputs,conf_dir,r_inputs->value,printExceptionReportResponse)!=0){
// TODO: cleanup memory
freeMaps(&lconf);
free(lconf);
Expand Down Expand Up @@ -5729,21 +5747,25 @@ runAsyncRequest (maps** iconf, map ** lenv, map ** irequest_inputs,json_object *
sprintf (fbkp, "%s/%s_%s.%s", r_inputs->value, r_inputs1->value,
usid->value, pmExecutionType->value);
setMapInMaps (lconf, "lenv", "file.responseInit", fbkp);

#ifdef DEBUG
fprintf (stderr, "RUN IN BACKGROUND MODE \n");
fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
zGetpid ());
fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
#endif

#ifndef LOG_CONSOLE_ENABLED
flog =
(char *)
malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
strlen (usid->value) + 13) * sizeof (char));
sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
r_inputs1->value, usid->value);
setMapInMaps (lconf, "lenv", "file.log", flog);
#ifdef DEBUG
fprintf (stderr, "RUN IN BACKGROUND MODE \n");
fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
zGetpid ());
fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
#endif
freopen (flog, "w+", stderr);
fflush (stderr);
#endif
f0 = freopen (fbkp, "w+", stdout);
rewind (stdout);

Expand Down

0 comments on commit 9457c91

Please sign in to comment.