libsim Versione 8.0.0

◆ l4f_category_delete_f()

subroutine l4f_category_delete_f ( type(l4f_handle), intent(inout) a_category)
private

Delete a logging category.

No-op version with a typed handle.

Parametri
[in,out]a_categorycategory as C native pointer

Definizione alla linea 795 del file log4fortran.F90.

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