libsim Versione 8.0.0

◆ l4f_category_log_legacy()

subroutine l4f_category_log_legacy ( integer(kind=c_int), intent(in) a_category,
integer(kind=c_int), intent(in) a_priority,
character(len=*), intent(in) a_format )

Emit log message for a category with specific priority.

Legacy Fortran version that receives an integer instead of a C pointer and a Fortran character argument.

Parametri
[in]a_categorycategory
[in]a_prioritypriority level
[in]a_formatmessage to emit

Definizione alla linea 820 del file log4fortran.F90.

821! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
822! authors:
823! Davide Cesari <dcesari@arpa.emr.it>
824! Paolo Patruno <ppatruno@arpa.emr.it>
825
826! This program is free software; you can redistribute it and/or
827! modify it under the terms of the GNU General Public License as
828! published by the Free Software Foundation; either version 2 of
829! the License, or (at your option) any later version.
830
831! This program is distributed in the hope that it will be useful,
832! but WITHOUT ANY WARRANTY; without even the implied warranty of
833! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
834! GNU General Public License for more details.
835
836! You should have received a copy of the GNU General Public License
837! along with this program. If not, see <http://www.gnu.org/licenses/>.
838#include "config.h"
839
840!> \defgroup log4fortran Libsim package, log4fortran library.
841!! Fortran interface to a basic set of log4c library for performing
842!! logging within a program.
843
844!>\brief classe per la gestione del logging
845!!
846!!Questo modulo permette una semplice, ma potente gestione della messagistica.
847!!E' utile sia in fase di debug che di monitoraggio utente.
848!!
849!!Questo modulo fornisce funzionalità simili, ma non identiche a
850!!seconda che siano disponibili in fase di compilazione le librerie
851!!log4c e cnf.
852!!
853!!There are three fundamental types of object in Log4C: categories,
854!!appenders and layouts. You can think of these objects as
855!!corresponding to the what, where and how of the logging system:
856!!categories describe what sub-system the message relates to,
857!!appenders determine where the message goes and layouts determine how
858!!the message is formatted.
859!!
860!!First, you have to figure out what kind of categories you
861!!want. Maybe you want one logger for GUI code and another one for
862!!memory management and a third one for user access
863!!logging. Okay. That's fine. Me, I like to have a separate logger for
864!!each class or data structure. I've already gone to the trouble of
865!!breaking my code down into such categories. Why not just use those?
866!!Feel free to set it up any way you like. Just don't make the mistake
867!!of using message severity as your categories. That's what the
868!!priority is all about.
869!!
870!! La gestione di appenders e layouts viene demandata in toto al file
871!! di configurazione di log4c (vedere apposita documentazione
872!! http://log4c.cvs.sourceforge.net/\*checkout\*/log4c/log4c/doc/Log4C-DevelopersGuide.odt )
873!!
874!!log4fortran by default can log messages with some standard priority levels:
875!!
876!!Use debug to write debugging messages which should not be printed
877!!when the application is in production.
878!!
879!!Use info for messages similar to the "verbose" mode of many
880!!applications.
881!!
882!!Use warn for warning messages which are logged to some log but the
883!!application is able to carry on without a problem.
884!!
885!!Use error for application error messages which are also logged to
886!!some log but, still, the application can hobble along. Such as when
887!!some administrator-supplied configuration parameter is incorrect and
888!!you fall back to using some hard-coded default value.
889!!
890!!Use fatal for critical messages, after logging of which the
891!!application quits abnormally.
892!!
893!!Configuration syntax:
894!!
895!!The log4crc configuration file uses an XML syntax. The root element
896!!is &lt;log4c&gt; and it can be used to control the configuration file
897!!version interface with the attribute "version". The following 4
898!!elements are supported: &lt;config&gt;, &lt;category&gt;, &lt;appender&gt; and
899!!&lt;layout&gt;.
900!!
901!! The &lt;config&gt; element controls the global log4c
902!! configuration. It has 3 sub elements. The &lt;nocleanup&gt; flag
903!! inhibits the log4c destructors routines. The &lt;bufsize&gt; element
904!! sets the buffer size used to format log4c_logging_event_t
905!! objects. If is set to 0, the allocation is dynamic (the &lt;debug&gt;
906!! element is currently unused).
907!!
908!! The &lt;category&gt; element has 3 possible attributes: the category
909!! "name", the category "priority" and the category
910!! "appender". Future versions will handle multple appenders per
911!! category.
912!!
913!! The &lt;appender&gt; element has 3 possible attributes: the appender
914!! "name", the appender "type", and the appender "layout".
915!!
916!! The &lt;layout&gt; element has 2 possible attributes: the layout
917!! "name" and the layout "type".
918!!
919!!
920!!This initial version of the log4c configuration file syntax is quite
921!!different from log4j. XML seemed the best choice to keep the log4j
922!!configuration power in a C API. Environment variables
923!!
924!! LOG4C_RCPATH holds the path to the main log4crc configuration file
925!! LOG4C_PRIORITY holds the "root" category priority
926!! LOG4C_APPENDER holds the "root" category appender
927!!
928!!
929!!Programma esempio \include log4fortran.f90
930!!Here's one sample log4crc configuration file \include log4crc
931!!
932!!\ingroup log4fortran
933MODULE log4fortran
934USE iso_c_binding
935IMPLICIT NONE
936
937INTEGER(kind=c_int),PARAMETER :: L4F_FATAL = 000 !< standard priority
938INTEGER(kind=c_int),PARAMETER :: L4F_ALERT = 100 !< standard priority
939INTEGER(kind=c_int),PARAMETER :: L4F_CRIT = 200 !< standard priority
940INTEGER(kind=c_int),PARAMETER :: L4F_ERROR = 300 !< standard priority
941INTEGER(kind=c_int),PARAMETER :: L4F_WARN = 400 !< standard priority
942INTEGER(kind=c_int),PARAMETER :: L4F_NOTICE = 500 !< standard priority
943INTEGER(kind=c_int),PARAMETER :: L4F_INFO = 600 !< standard priority
944INTEGER(kind=c_int),PARAMETER :: L4F_DEBUG = 700 !< standard priority
945INTEGER(kind=c_int),PARAMETER :: L4F_TRACE = 800 !< standard priority
946INTEGER(kind=c_int),PARAMETER :: L4F_NOTSET = 900 !< standard priority
947INTEGER(kind=c_int),PARAMETER :: L4F_UNKNOWN = 1000 !< standard priority
948
949!> Default priority value. It is used only when compiled without log4c
950!! since the configuration file is ignored, but it is better to define
951!! it all the time.
952INTEGER(kind=c_int),PUBLIC :: l4f_priority=l4f_notice
953
954#ifdef HAVE_LIBLOG4C
955
956!> l4f handle. This type defines an opaque handle
957!! to a l4f category (mapped to a log4c category),
958!! it has to be initialised with the l4f_category_get_handle method.
959TYPE,BIND(C) :: l4f_handle
960 PRIVATE
961 TYPE(c_ptr) :: ptr = c_null_ptr
962END TYPE l4f_handle
963
964
965TYPE(l4f_handle),SAVE :: l4f_global_default
966
967#undef ARRAYOF_ORIGEQ
968#undef ARRAYOF_ORIGTYPE
969#undef ARRAYOF_TYPE
970#define ARRAYOF_ORIGTYPE TYPE(l4f_handle)
971#define ARRAYOF_TYPE arrayof_l4f_handle
972#include "arrayof_pre_nodoc.F90"
973
974TYPE(arrayof_l4f_handle) :: l4f_global_ptr
975
976!> Global log4fortran constructor. It can be called by Fortran.
977INTERFACE
978 FUNCTION l4f_init() bind(C,name='log4c_init')
979 IMPORT
980 INTEGER(kind=c_int) :: l4f_init
981 END FUNCTION l4f_init
982END INTERFACE
983
984! Internal C interface not to be used by user Fortran code
985INTERFACE
986 FUNCTION l4f_category_get_c(a_name) bind(C,name='log4c_category_get')
987 IMPORT
988 CHARACTER(kind=c_char),INTENT(in) :: a_name(*) !< category name
989 TYPE(l4f_handle) :: l4f_category_get_c
990 END FUNCTION l4f_category_get_c
991END INTERFACE
992
993! Internal C interface not to be used by user Fortran code
994! this function has been disabled because after deleting a category
995! the following log4c_fini fails with a double free, we must
996! understand the log4c docs
997INTERFACE
998 SUBROUTINE l4f_category_delete_c(a_category) bind(C,name='log4c_category_delete')
999 IMPORT
1000 TYPE(l4f_handle),VALUE :: a_category !< category as C native pointer
1001 END SUBROUTINE l4f_category_delete_c
1002END INTERFACE
1003
1004!! Delete a logging category. It can receive a l4f_handle pointer or a
1005!! legacy integer value.
1006INTERFACE l4f_category_delete
1007 MODULE PROCEDURE l4f_category_delete_legacy, l4f_category_delete_f
1008END INTERFACE
1009
1010! Internal C interface not to be used by user Fortran code
1011INTERFACE
1012 SUBROUTINE l4f_category_log_c(a_category, a_priority, a_format) bind(C,name='log4c_category_log_c')
1013 IMPORT
1014 TYPE(l4f_handle),VALUE :: a_category !< category
1015 INTEGER(kind=c_int),VALUE :: a_priority !< priority level
1016! TYPE(c_ptr),VALUE :: locinfo !< not used
1017 CHARACTER(kind=c_char),INTENT(in) :: a_format(*) !< message to emit
1018 ! TYPE(c_ptr),VALUE :: a_args
1019 END SUBROUTINE l4f_category_log_c
1020END INTERFACE
1021
1022!> Emit log message for a category with specific priority.
1023!! It can receive a l4f_handle or a legacy integer value.
1024INTERFACE l4f_category_log
1025 MODULE PROCEDURE l4f_category_log_f, l4f_category_log_legacy
1026END INTERFACE l4f_category_log
1027
1028!> Return true if the corresponding category handle exists.
1029INTERFACE l4f_category_exist
1030 MODULE PROCEDURE l4f_category_exist_f, l4f_category_exist_legacy
1031END INTERFACE l4f_category_exist
1032
1033!> Global log4fortran destructor. It can be called by Fortran.
1034INTERFACE
1035 FUNCTION l4f_fini() bind(C,name='log4c_fini')
1036 IMPORT
1037 INTEGER(kind=c_int) :: l4f_fini
1038 END FUNCTION l4f_fini
1039END INTERFACE
1040
1041!>Ritorna un messaggio caratteristico delle priorità standard
1042!interface
1043!CHARACTER(len=12) FUNCTION l4f_msg(a_priority)
1044!integer,intent(in):: a_priority !< category name
1045!end function l4f_msg
1046!end interface
1047
1048#else
1049
1050CHARACTER(len=510),PRIVATE:: dummy_a_name
1051
1052!> l4f handle. Dummy handle.
1053TYPE :: l4f_handle
1054 PRIVATE
1055 INTEGER :: ptr = 0
1056END TYPE l4f_handle
1057
1058#endif
1059
1060PRIVATE
1061PUBLIC l4f_fatal, l4f_alert, l4f_crit, l4f_error, l4f_warn, l4f_notice, &
1062 l4f_info, l4f_debug, l4f_trace, l4f_notset, l4f_unknown
1063PUBLIC l4f_handle, l4f_init, l4f_category_get_handle, l4f_category_get, l4f_category_delete, l4f_category_log, &
1065PUBLIC l4f_launcher
1066
1067CONTAINS
1068
1069!> Routine specifica per il SIM. Cattura le variabili di ambiente
1070!! LOG4_APPLICATION_NAME,LOG4_APPLICATION_ID e compone il nome univoco
1071!! per il logging. Se le variabili di ambiente non sono impostate
1072!! ritorna un nome definito dal nome del processo e da un timestamp.
1073SUBROUTINE l4f_launcher(a_name, a_name_force, a_name_append)
1074CHARACTER(len=*),INTENT(out) :: a_name !< nome univoco per logging
1075CHARACTER(len=*),INTENT(in),OPTIONAL :: a_name_force !< forza il valore di a_name
1076CHARACTER(len=*),INTENT(in),OPTIONAL :: a_name_append !< valore da appendere a a_name
1077
1078INTEGER :: tarray(8)
1079CHARACTER(len=255) :: LOG4_APPLICATION_NAME,LOG4_APPLICATION_ID,arg
1080CHARACTER(len=255),SAVE :: a_name_save=""
1081
1082IF (PRESENT(a_name_force))THEN
1083 a_name=a_name_force
1084ELSE IF (a_name_save /= "")THEN
1085 a_name=a_name_save
1086ELSE
1087
1088 CALL date_and_time(values=tarray)
1089 CALL getarg(0, arg)
1090 CALL getenv("LOG4_APPLICATION_NAME", log4_application_name)
1091 CALL getenv("LOG4_APPLICATION_ID", log4_application_id)
1092
1093 IF (log4_application_name == "" .AND. log4_application_id == "") THEN
1094 WRITE(a_name,"(a,a,8i5,a)")trim(arg),"[",tarray,"]"
1095 ELSE
1096 a_name = trim(log4_application_name)//"["//trim(log4_application_id)//"]"
1097 END IF
1098
1099END IF
1100
1101a_name_save=a_name
1102
1103IF (PRESENT(a_name_append)) THEN
1104 a_name=trim(a_name)//"."//trim(a_name_append)
1105END IF
1106
1107END SUBROUTINE l4f_launcher
1108
1109#ifndef HAVE_LIBLOG4C
1110! define dummy function to replace log4c interface
1111
1112!> log4fortran global constructor
1113INTEGER FUNCTION l4f_init()
1114CHARACTER(len=10) :: priority
1115INTEGER :: iostat
1116
1117CALL getenv("LOG4C_PRIORITY",priority)
1118IF (priority=="") THEN
1119 l4f_priority = l4f_notice
1120ELSE
1121 READ(priority,*,iostat=iostat)l4f_priority
1122END IF
1123
1124IF (iostat /= 0) THEN
1125 l4f_priority = l4f_notice
1126END IF
1127
1128l4f_init = 0
1129
1130END FUNCTION l4f_init
1131
1132
1133!>Initialize a logging category.
1134FUNCTION l4f_category_get(a_name) RESULT(handle)
1135CHARACTER(len=*),INTENT(in) :: a_name !< category name
1136
1137TYPE(l4f_handle) :: handle
1138
1139handle%ptr = 1
1140dummy_a_name = a_name
1141
1142END FUNCTION l4f_category_get
1143
1144
1145!>Delete a logging category.
1146SUBROUTINE l4f_category_delete(a_category)
1147TYPE(l4f_handle),INTENT(in) :: a_category !< category
1148
1149a_category%ptr = 0
1150dummy_a_name = ""
1151
1152END SUBROUTINE l4f_category_delete
1153
1154
1155!> Emit log message for a category with specific priority
1156SUBROUTINE l4f_category_log(a_category,a_priority,a_format)
1157TYPE(l4f_handle),INTENT(in) :: a_category !< category
1158INTEGER,INTENT(in):: a_priority !< priority level
1159CHARACTER(len=*),INTENT(in):: a_format !< message to emit
1160
1161IF (a_category%ptr == 1 .AND. a_priority <= l4f_priority) THEN
1162 WRITE(*,*)"[dummy] ",l4f_msg(a_priority),trim(dummy_a_name)," - ",trim(a_format)
1163ENDIF
1164
1165END SUBROUTINE l4f_category_log
1166
1167
1168!> Emit log message without category with specific priority
1169SUBROUTINE l4f_log(a_priority,a_format)
1170INTEGER,INTENT(in):: a_priority !< priority level
1171CHARACTER(len=*),INTENT(in):: a_format !< message to emit
1172
1173IF (a_priority <= l4f_priority) THEN
1174 WRITE(*,*)"[_default] ",l4f_msg(a_priority),trim(dummy_a_name)," - ",trim(a_format)
1175ENDIF
1176
1177END SUBROUTINE l4f_log
1178
1179
1180!> Return True if category exist
1181LOGICAL FUNCTION l4f_category_exist(a_category)
1182TYPE(l4f_handle),INTENT(in) :: a_category !< category
1183
1184l4f_category_exist = a_category%ptr == 1
1185
1186END FUNCTION l4f_category_exist
1187
1188
1189!>log4fortran destructors
1190INTEGER FUNCTION l4f_fini()
1191
1192l4f_fini= 0
1193
1194END FUNCTION l4f_fini
1195
1196!>Ritorna un messaggio caratteristico delle priorità standard
1197CHARACTER(len=12) FUNCTION l4f_msg(a_priority)
1198INTEGER,INTENT(in):: a_priority !< priority level
1199
1200write(l4f_msg,*)a_priority
1201
1202if (a_priority == l4f_fatal) l4f_msg="FATAL"
1203if (a_priority == l4f_alert) l4f_msg="ALERT"
1204if (a_priority == l4f_crit) l4f_msg="CRIT"
1205if (a_priority == l4f_error) l4f_msg="ERROR"
1206if (a_priority == l4f_warn) l4f_msg="WARN"
1207if (a_priority == l4f_notice) l4f_msg="NOTICE"
1208if (a_priority == l4f_info) l4f_msg="INFO"
1209if (a_priority == l4f_debug) l4f_msg="DEBUG"
1210if (a_priority == l4f_trace) l4f_msg="TRACE"
1211if (a_priority == l4f_notset) l4f_msg="NOTSET"
1212if (a_priority == l4f_unknown) l4f_msg="UNKNOWN"
1213
1214END FUNCTION l4f_msg
1215
1216#else
1217
1218#include "arrayof_post_nodoc.F90"
1219
1220!> Initialize a logging category. This is the
1221!! Fortran legacy version that receives a Fortran character argument
1222!! and returns an integer.
1223FUNCTION l4f_category_get(a_name) RESULT(handle)
1224CHARACTER(kind=c_char,len=*),INTENT(in) :: a_name !< category name
1225INTEGER :: handle
1226
1227handle = append(l4f_global_ptr, l4f_category_get_c(trim(a_name)//char(0)))
1228
1229END FUNCTION l4f_category_get
1230
1231
1232!> Initialize a logging category. This is the
1233!! Fortran version that receives a Fortran character argument
1234!! and returns a typed handle.
1235FUNCTION l4f_category_get_handle(a_name) RESULT(handle)
1236CHARACTER(kind=c_char,len=*),INTENT(in) :: a_name !< category name
1237TYPE(l4f_handle) :: handle
1238
1239handle = l4f_category_get_c(trim(a_name)//char(0))
1240
1241END FUNCTION l4f_category_get_handle
1242
1243
1244!> Delete a logging category. Legacy version with an integer argument.
1245SUBROUTINE l4f_category_delete_legacy(a_category)
1246INTEGER,INTENT(in) :: a_category !< category as an integer
1247
1248IF (a_category <= 0 .OR. a_category > l4f_global_ptr%arraysize) RETURN
1249CALL remove(l4f_global_ptr, pos=a_category)
1250
1251END SUBROUTINE l4f_category_delete_legacy
1252
1253
1254!> Delete a logging category. No-op version with a typed handle.
1255SUBROUTINE l4f_category_delete_f(a_category)
1256TYPE(l4f_handle),INTENT(inout) :: a_category !< category as C native pointer
1257
1258! hee the C function should be called, see comment above
1259! CALL l4f_category_delete_c(a_category)
1260a_category%ptr = c_null_ptr
1261
1262END SUBROUTINE l4f_category_delete_f
1263
1264
1265!> Emit log message for a category with specific priority.
1266!! Fortran version that receives a Fortran character argument.
1267SUBROUTINE l4f_category_log_f(a_category, a_priority, a_format)
1268TYPE(l4f_handle),INTENT(in) :: a_category !< category
1269INTEGER(kind=c_int),INTENT(in) :: a_priority !< priority level
1270CHARACTER(len=*),INTENT(in) :: a_format !< message to emit
1271
1272CALL l4f_category_log_c(a_category, a_priority, trim(a_format)//char(0))
1273
1274END SUBROUTINE l4f_category_log_f
1275
1276
1277!> Emit log message for a category with specific priority.
1278!! Legacy Fortran version that receives an integer instead of a C
1279!! pointer and a Fortran character argument.
1280SUBROUTINE l4f_category_log_legacy(a_category, a_priority, a_format)
1281INTEGER(kind=c_int),INTENT(in) :: a_category !< category
1282INTEGER(kind=c_int),INTENT(in) :: a_priority !< priority level
1283CHARACTER(len=*),INTENT(in) :: a_format !< message to emit
1284
1285CALL l4f_category_log_c(l4f_global_ptr%array(a_category), l4f_warn, &
1286 'You are using the legacy log4fortran interface!'//char(0))
1287CALL l4f_category_log_c(l4f_global_ptr%array(a_category), l4f_warn, &
1288 'Please, upgrade your code by defining category as `TYPE(l4f_handle)`'//char(0))
1289CALL l4f_category_log_c(l4f_global_ptr%array(a_category), l4f_warn, &
1290 'and replacing `l4f_category_get` with `l4f_category_get_handle`'//char(0))
1291CALL l4f_category_log_c(l4f_global_ptr%array(a_category), a_priority, trim(a_format)//char(0))
1292
1293END SUBROUTINE l4f_category_log_legacy
1294
1295
1296!> Emit log message without category with specific priority.
1297!! Fortran version that receives a Fortran character argument.
1298SUBROUTINE l4f_log(a_priority, a_format)
1299INTEGER(kind=c_int),INTENT(in) :: a_priority !< priority level
1300CHARACTER(len=*),INTENT(in) :: a_format !< message to emit
1301
1302INTEGER :: i
1303
1304IF (.NOT.l4f_category_exist(l4f_global_default)) THEN
1305 i = l4f_init()
1306 l4f_global_default = l4f_category_get_handle('_default')
1307ENDIF
1308CALL l4f_category_log(l4f_global_default, a_priority, a_format)
1309
1310END SUBROUTINE l4f_log
1311
1312
1313!> Return true if the corresponding category handle exists
1314!! (is associated with a category).
1315FUNCTION l4f_category_exist_f(a_category) RESULT(exist)
1316TYPE(l4f_handle),INTENT(in) :: a_category !< category
1317LOGICAL :: exist
1318
1319exist = c_associated(a_category%ptr)
1320
1321END FUNCTION l4f_category_exist_f
1322
1323!> Return true if the corresponding category handle exists
1324!! (is associated with a category).
1325!! Legacy Fortran version that receives an integer instead of a C
1326!! pointer.
1327FUNCTION l4f_category_exist_legacy(a_category) RESULT(exist)
1328INTEGER,INTENT(in):: a_category !< category
1329LOGICAL :: exist
1330
1331IF (a_category <= 0 .OR. a_category > l4f_global_ptr%arraysize) THEN
1332 exist = .false.
1333ELSE
1334 exist = l4f_category_exist(l4f_global_ptr%array(a_category))
1335ENDIF
1336
1337END FUNCTION l4f_category_exist_legacy
1338
1339#endif
1340
1341END MODULE log4fortran
Return true if the corresponding category handle exists.
Emit log message for a category with specific priority.
Global log4fortran destructor.
Global log4fortran constructor.
classe per la gestione del logging

Generated with Doxygen.