libsim Versione 7.2.6
|
◆ l4f_category_delete_legacy()
Delete a logging category. Legacy version with an integer argument.
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 <log4c> and it can be used to control the configuration file
872!!version interface with the attribute "version". The following 4
873!!elements are supported: <config>, <category>, <appender> and
874!!<layout>.
875!!
876!! The <config> element controls the global log4c
877!! configuration. It has 3 sub elements. The <nocleanup> flag
878!! inhibits the log4c destructors routines. The <bufsize> 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 <debug>
881!! element is currently unused).
882!!
883!! The <category> 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 <appender> element has 3 possible attributes: the appender
889!! "name", the appender "type", and the appender "layout".
890!!
891!! The <layout> 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
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!> l4f handle. This type defines an opaque handle
930!! to a l4f category (mapped to a log4c category),
931!! it has to be initialised with the l4f_category_get method.
932TYPE,BIND(C) :: l4f_handle
933 PRIVATE
934 TYPE(c_ptr) :: ptr = c_null_ptr
936
937#ifdef HAVE_LIBLOG4C
938
939TYPE(l4f_handle),SAVE :: l4f_global_default
940
941! emulation of old cnf behavior returning integer instead of pointer
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.
952INTERFACE
954 IMPORT
955 INTEGER(kind=c_int) :: l4f_init
957END INTERFACE
958
959!> Initialize a logging category. This is the C version, please use the
960!! Fortran version l4f_category_get that receives a Fortran character.
961INTERFACE
963 IMPORT
964 CHARACTER(kind=c_char),INTENT(in) :: a_name(*) !< category name
965 TYPE(l4f_handle) :: l4f_category_get_c
967END INTERFACE
968
969!! Delete a logging category. It can receive a C pointer or a
970!! legacy integer value.
971INTERFACE l4f_category_delete
972! SUBROUTINE l4f_category_delete_c(a_category) BIND(C,name='log4c_category_delete')
973! IMPORT
974! TYPE(l4f_handle),VALUE :: a_category !< category as C native pointer
975! END SUBROUTINE l4f_category_delete_c
976 MODULE PROCEDURE l4f_category_delete_legacy, l4f_category_delete_f
977END INTERFACE
978! this function has been disabled because aftere deleting a category
979! the following log4c_fini fails with a double free, we must
980! understand the log4c docs
981
982INTERFACE
983 SUBROUTINE l4f_category_log_c(a_category, a_priority, a_format) bind(C,name='log4c_category_log_c')
984 IMPORT
985 TYPE(l4f_handle),VALUE :: a_category !< category
986 INTEGER(kind=c_int),VALUE :: a_priority !< priority level
987! TYPE(c_ptr),VALUE :: locinfo !< not used
988 CHARACTER(kind=c_char),INTENT(in) :: a_format(*) !< message to emit
989 ! TYPE(c_ptr),VALUE :: a_args
990 END SUBROUTINE l4f_category_log_c
991END INTERFACE
992
993!> Emit log message for a category with specific priority.
994!! It can receive a C pointer or a legacy integer value.
996 MODULE PROCEDURE l4f_category_log_f, l4f_category_log_legacy
998
999!> Return true if the corresponding category handle exists.
1001 MODULE PROCEDURE l4f_category_exist_f, l4f_category_exist_legacy
1003
1004!> log4fortran destructor
1005INTERFACE
1007 IMPORT
1008 INTEGER(kind=c_int) :: l4f_fini
1010END INTERFACE
1011
1012!>Ritorna un messaggio caratteristico delle priorità standard
1013!interface
1014!CHARACTER(len=12) FUNCTION l4f_msg(a_priority)
1015!integer,intent(in):: a_priority !< category name
1016!end function l4f_msg
1017!end interface
1018
1019#else
1020
1021CHARACTER(len=510),PRIVATE:: dummy_a_name
1022
1023#endif
1024
1025PRIVATE
1026PUBLIC l4f_fatal, l4f_alert, l4f_crit, l4f_error, l4f_warn, l4f_notice, &
1027 l4f_info, l4f_debug, l4f_trace, l4f_notset, l4f_unknown
1030PUBLIC l4f_launcher
1031
1032CONTAINS
1033
1034!> Routine specifica per il SIM. Cattura le variabili di ambiente
1035!! LOG4_APPLICATION_NAME,LOG4_APPLICATION_ID e compone il nome univoco
1036!! per il logging. Se le variabili di ambiente non sono impostate
1037!! ritorna un nome definito dal nome del processo e da un timestamp.
1038SUBROUTINE l4f_launcher(a_name, a_name_force, a_name_append)
1039CHARACTER(len=*),INTENT(out) :: a_name !< nome univoco per logging
1040CHARACTER(len=*),INTENT(in),OPTIONAL :: a_name_force !< forza il valore di a_name
1041CHARACTER(len=*),INTENT(in),OPTIONAL :: a_name_append !< valore da appendere a a_name
1042
1043INTEGER :: tarray(8)
1044CHARACTER(len=255) :: LOG4_APPLICATION_NAME,LOG4_APPLICATION_ID,arg
1045CHARACTER(len=255),SAVE :: a_name_save=""
1046
1047IF (PRESENT(a_name_force))THEN
1048 a_name=a_name_force
1049ELSE IF (a_name_save /= "")THEN
1050 a_name=a_name_save
1051ELSE
1052
1053 CALL date_and_time(values=tarray)
1054 CALL getarg(0, arg)
1055 CALL getenv("LOG4_APPLICATION_NAME", log4_application_name)
1056 CALL getenv("LOG4_APPLICATION_ID", log4_application_id)
1057
1058 IF (log4_application_name == "" .AND. log4_application_id == "") THEN
1059 WRITE(a_name,"(a,a,8i5,a)")trim(arg),"[",tarray,"]"
1060 ELSE
1061 a_name = trim(log4_application_name)//"["//trim(log4_application_id)//"]"
1062 END IF
1063
1064END IF
1065
1066a_name_save=a_name
1067
1068IF (PRESENT(a_name_append)) THEN
1069 a_name=trim(a_name)//"."//trim(a_name_append)
1070END IF
1071
1072END SUBROUTINE l4f_launcher
1073
1074#ifndef HAVE_LIBLOG4C
1075! definisce delle dummy routine
1076
1077!> log4fortran constructor
1079
1080character(len=10)::priority
1081integer :: iostat
1082
1083call getenv("LOG4C_PRIORITY",priority)
1084if (priority=="") then
1085 l4f_priority = l4f_notice
1086else
1087 read(priority,*,iostat=iostat)l4f_priority
1088end if
1089
1090if (iostat /= 0) then
1091 l4f_priority = l4f_notice
1092end if
1093
1094l4f_init = 0
1095
1097
1098
1099!>Initialize a logging category.
1100integer function l4f_category_get (a_name)
1101character (len=*),intent(in) :: a_name !< category name
1102
1103dummy_a_name = a_name
1104l4f_category_get = 1
1105
1106end function l4f_category_get
1107
1108
1109!>Delete a logging category.
1110subroutine l4f_category_delete(a_category)
1111integer,intent(in):: a_category !< category name
1112
1113if (a_category == 1) dummy_a_name = ""
1114
1115end subroutine l4f_category_delete
1116
1117
1118!>Emit log message for a category with specific priority
1120integer,intent(in):: a_category !< category name
1121integer,intent(in):: a_priority !< priority level
1122character(len=*),intent(in):: a_format !< message to emit
1123
1124if (a_category == 1 .and. a_priority <= l4f_priority) then
1125 write(*,*)"[dummy] ",l4f_msg(a_priority),trim(dummy_a_name)," - ",trim(a_format)
1126end if
1127
1129
1130
1131!>Emit log message without category with specific priority
1132subroutine l4f_log (a_priority,a_format)
1133integer,intent(in):: a_priority !< priority level
1134character(len=*),intent(in):: a_format !< message to emit
1135
1136if ( a_priority <= l4f_priority) then
1137 write(*,*)"[_default] ",l4f_msg(a_priority),trim(dummy_a_name)," - ",trim(a_format)
1138end if
1139
1140end subroutine l4f_log
1141
1142
1143!>Return True if category exist
1145integer,intent(in):: a_category !< category name
1146
1147if (a_category == 1) then
1148 l4f_category_exist= .true.
1149else
1150 l4f_category_exist= .false.
1151end if
1152
1154
1155
1156!>log4fortran destructors
1158
1159l4f_fini= 0
1160
1162
1163!>Ritorna un messaggio caratteristico delle priorità standard
1164character(len=12) function l4f_msg(a_priority)
1165
1166integer,intent(in):: a_priority !< category name
1167
1168write(l4f_msg,*)a_priority
1169
1170if (a_priority == l4f_fatal) l4f_msg="FATAL"
1171if (a_priority == l4f_alert) l4f_msg="ALERT"
1172if (a_priority == l4f_crit) l4f_msg="CRIT"
1173if (a_priority == l4f_error) l4f_msg="ERROR"
1174if (a_priority == l4f_warn) l4f_msg="WARN"
1175if (a_priority == l4f_notice) l4f_msg="NOTICE"
1176if (a_priority == l4f_info) l4f_msg="INFO"
1177if (a_priority == l4f_debug) l4f_msg="DEBUG"
1178if (a_priority == l4f_trace) l4f_msg="TRACE"
1179if (a_priority == l4f_notset) l4f_msg="NOTSET"
1180if (a_priority == l4f_unknown) l4f_msg="UNKNOWN"
1181
1182end function l4f_msg
1183
1184#else
1185
1186#include "arrayof_post_nodoc.F90"
1187
1188!> Initialize a logging category. This is the
1189!! Fortran legacy version that receives a Fortran character argument
1190!! and returns an integer.
1191FUNCTION l4f_category_get(a_name) RESULT(handle)
1192CHARACTER(kind=c_char,len=*),INTENT(in) :: a_name !< category name
1193INTEGER :: handle
1194
1195INTEGER :: i
1196
1197DO i = 1, l4f_global_ptr%arraysize ! look first for a hole
1199 l4f_global_ptr%array(i) = l4f_category_get_c(trim(a_name)//char(0))
1200 handle = i
1201 RETURN
1202 ENDIF
1203ENDDO
1204
1205handle = append(l4f_global_ptr, l4f_category_get_c(trim(a_name)//char(0)))
1206
1207END FUNCTION l4f_category_get
1208
1209
1210!> Initialize a logging category. This is the
1211!! Fortran version that receives a Fortran character argument
1212!! and returns a typed handle.
1213FUNCTION l4f_category_get_handle(a_name) RESULT(handle)
1214CHARACTER(kind=c_char,len=*),INTENT(in) :: a_name !< category name
1215TYPE(l4f_handle) :: handle
1216
1217handle = l4f_category_get_c(trim(a_name)//char(0))
1218
1219END FUNCTION l4f_category_get_handle
1220
1221
1222!> Delete a logging category. Legacy version with an integer argument.
1223SUBROUTINE l4f_category_delete_legacy(a_category)
1224INTEGER,INTENT(in) :: a_category !< category as an integer
1225
1226IF (a_category <= 0 .OR. a_category > l4f_global_ptr%arraysize) RETURN
1227IF (a_category == l4f_global_ptr%arraysize) THEN
1228 CALL remove(l4f_global_ptr, pos=a_category)
1229ELSE
1230 l4f_global_ptr%array(a_category)%ptr = c_null_ptr
1231ENDIF
1232
1233END SUBROUTINE l4f_category_delete_legacy
1234
1235
1236!> Delete a logging category. No-op version with a typed handle.
1237SUBROUTINE l4f_category_delete_f(a_category)
1238TYPE(l4f_handle),INTENT(inout) :: a_category !< category as C native pointer
1239
1240a_category%ptr = c_null_ptr ! is it necessary?
1241
1242END SUBROUTINE l4f_category_delete_f
1243
1244
1245!> Emit log message for a category with specific priority.
1246!! Fortran version that receives a Fortran character argument.
1247SUBROUTINE l4f_category_log_f(a_category, a_priority, a_format)
1248TYPE(l4f_handle),INTENT(in) :: a_category !< category
1249INTEGER(kind=c_int),INTENT(in) :: a_priority !< priority level
1250CHARACTER(len=*),INTENT(in) :: a_format !< message to emit
1251
1252CALL l4f_category_log_c(a_category, a_priority, trim(a_format)//char(0))
1253
1254END SUBROUTINE l4f_category_log_f
1255
1256
1257!> Emit log message for a category with specific priority.
1258!! Legacy Fortran version that receives an integer instead of a C
1259!! pointer and a Fortran character argument.
1260SUBROUTINE l4f_category_log_legacy(a_category, a_priority, a_format)
1261INTEGER(kind=c_int),INTENT(in) :: a_category !< category
1262INTEGER(kind=c_int),INTENT(in) :: a_priority !< priority level
1263CHARACTER(len=*),INTENT(in) :: a_format !< message to emit
1264
1265CALL l4f_category_log_c(l4f_global_ptr%array(a_category), a_priority, trim(a_format)//char(0))
1266
1267END SUBROUTINE l4f_category_log_legacy
1268
1269
1270!> Emit log message without category with specific priority.
1271!! Fortran version that receives a Fortran character argument.
1272SUBROUTINE l4f_log(a_priority, a_format)
1273INTEGER(kind=c_int),INTENT(in) :: a_priority !< priority level
1274CHARACTER(len=*),INTENT(in) :: a_format !< message to emit
1275
1276INTEGER :: i
1277
1279 i = l4f_init()
1280 l4f_global_default = l4f_category_get_handle('_default')
1281ENDIF
1283
1284END SUBROUTINE l4f_log
1285
1286
1287!> Return true if the corresponding category handle exists
1288!! (is associated with a category).
1289FUNCTION l4f_category_exist_f(a_category) RESULT(exist)
1290TYPE(l4f_handle),INTENT(in) :: a_category !< category
1291LOGICAL :: exist
1292
1293exist = c_associated(a_category%ptr)
1294
1295END FUNCTION l4f_category_exist_f
1296
1297!> Return true if the corresponding category handle exists
1298!! (is associated with a category).
1299!! Legacy Fortran version that receives an integer instead of a C
1300!! pointer.
1301FUNCTION l4f_category_exist_legacy(a_category) RESULT(exist)
1302INTEGER,INTENT(in):: a_category !< category
1303LOGICAL :: exist
1304
1305IF (a_category <= 0 .OR. a_category > l4f_global_ptr%arraysize) THEN
1306 exist = .false.
1307ELSE
1308 exist = l4f_category_exist(l4f_global_ptr%array(a_category))
1309ENDIF
1310
1311END FUNCTION l4f_category_exist_legacy
1312
1313
1314#endif
1315
Return true if the corresponding category handle exists. Definition log4fortran.F90:462 Emit log message for a category with specific priority. Definition log4fortran.F90:457 |