Commit d0f807968fccd5d42718971f0b2677e56cc51307

Authored by David RENÉ
1 parent 3fa607d4

first commit of Anubis logger

src/anb_log.aproj 0 → 100644
  1 +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  2 + <PropertyGroup>
  3 + <ProjectGuid>{9AF3C253-38CA-44F2-824F-CFE038997403}</ProjectGuid>
  4 + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  5 + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  6 + <OutputType>Exe</OutputType>
  7 + <RootNamespace>anb_log</RootNamespace>
  8 + <AssemblyName>anb_log</AssemblyName>
  9 + <StartupObject>src\logger_server.anubis</StartupObject>
  10 + <IncludePaths>./%3b./src</IncludePaths>
  11 + </PropertyGroup>
  12 + <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
  13 + <OutputPath>bin\Debug\</OutputPath>
  14 + <DebugSymbols>True</DebugSymbols>
  15 + <DebugType>Full</DebugType>
  16 + <Optimize>False</Optimize>
  17 + </PropertyGroup>
  18 + <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
  19 + <OutputPath>bin\Release\</OutputPath>
  20 + <DebugSymbols>False</DebugSymbols>
  21 + <DebugType>None</DebugType>
  22 + <Optimize>True</Optimize>
  23 + </PropertyGroup>
  24 + <Import Project="$(AnubisBinPath)\Anubis.Build.targets" />
  25 + <ItemGroup>
  26 + <Folder Include="src" />
  27 + <Folder Include="xlib" />
  28 + <Folder Include="xlib\asterisk" />
  29 + <Folder Include="xlib\database" />
  30 + <Folder Include="xlib\database\model" />
  31 + <Folder Include="xlib\database\types" />
  32 + <Folder Include="xlib\ds_files" />
  33 + <Folder Include="xlib\extensions" />
  34 + <Folder Include="xlib\file_processor_io" />
  35 + <Folder Include="xlib\file_processor_io\yaml" />
  36 + <Folder Include="xlib\generic" />
  37 + <Folder Include="xlib\generic\types" />
  38 + <Folder Include="xlib\mail" />
  39 + <Folder Include="xlib\mail\lexers" />
  40 + <Folder Include="xlib\mail\types" />
  41 + <Folder Include="xlib\mail\types\generated" />
  42 + <Folder Include="xlib\network" />
  43 + <Folder Include="xlib\net_services" />
  44 + <Folder Include="xlib\net_services_protocols" />
  45 + <Folder Include="xlib\obj" />
  46 + <Folder Include="xlib\os_tools" />
  47 + <Folder Include="xlib\os_tools\freebsd" />
  48 + <Folder Include="xlib\os_tools\linux" />
  49 + <Folder Include="xlib\os_tools\linux\config" />
  50 + <Folder Include="xlib\string" />
  51 + <Folder Include="xlib\types" />
  52 + <Folder Include="xlib\types\generated" />
  53 + <Folder Include="xlib\unit_test" />
  54 + <Folder Include="xlib\web" />
  55 + <Folder Include="xlib\web\color" />
  56 + <Folder Include="xlib\web\fonts" />
  57 + <Folder Include="xlib\web\jQuery" />
  58 + <Folder Include="xlib\web\jQuery\ui-addon" />
  59 + <Folder Include="xlib\web\js" />
  60 + <Folder Include="xlib\web\piwik" />
  61 + <Folder Include="xlib\web\plugin" />
  62 + <Folder Include="xlib\web\types" />
  63 + <Folder Include="xlib\web\widgets" />
  64 + <Compile Include="src\logger_server.anubis" />
  65 + <Compile Include="src\logger_test.anubis" />
  66 + <Compile Include="xlib\asterisk\ami.anubis" />
  67 + <Compile Include="xlib\asterisk\ami_commands.anubis" />
  68 + <Compile Include="xlib\asterisk\ami_types.anubis" />
  69 + <Compile Include="xlib\CXM_errors.anubis" />
  70 + <Compile Include="xlib\CXM_message_constants.anubis" />
  71 + <Compile Include="xlib\database\alter_table.anubis" />
  72 + <Compile Include="xlib\database\csv_import_status.anubis" />
  73 + <Compile Include="xlib\database\csv_tools.anubis" />
  74 + <Compile Include="xlib\database\db_binds.anubis" />
  75 + <Compile Include="xlib\database\db_get_helpers.anubis" />
  76 + <Compile Include="xlib\database\db_types.anubis" />
  77 + <Compile Include="xlib\database\db_update_fields.anubis" />
  78 + <Compile Include="xlib\database\db_utils.anubis" />
  79 + <Compile Include="xlib\database\db_version.anubis" />
  80 + <Compile Include="xlib\database\migration.anubis" />
  81 + <Compile Include="xlib\database\migration_common.anubis" />
  82 + <Compile Include="xlib\database\migration_common_sqlite3.anubis" />
  83 + <Compile Include="xlib\database\migration_sqlite3.anubis" />
  84 + <Compile Include="xlib\database\model\db_model.anubis" />
  85 + <Compile Include="xlib\database\settings.anubis" />
  86 + <Compile Include="xlib\database\settings_sqlite3.anubis" />
  87 + <Compile Include="xlib\database\sqlite_foreign_key.anubis" />
  88 + <Compile Include="xlib\database\types\db_date.anubis" />
  89 + <Compile Include="xlib\database\types\db_datetime.anubis" />
  90 + <Compile Include="xlib\database\types\db_id.anubis" />
  91 + <Compile Include="xlib\database\types\db_integer.anubis" />
  92 + <Compile Include="xlib\database\types\db_migration.anubis" />
  93 + <Compile Include="xlib\database\types\db_time.anubis" />
  94 + <Compile Include="xlib\densaku_types.anubis" />
  95 + <Compile Include="xlib\ds_files\ds_messages.anubis" />
  96 + <Compile Include="xlib\ds_files\ds_types.anubis" />
  97 + <Compile Include="xlib\extensions\json.anubis" />
  98 + <Compile Include="xlib\file_processor_io\yaml\yaml.anubis" />
  99 + <Compile Include="xlib\file_processor_io\yaml\yaml_parser.anubis" />
  100 + <Compile Include="xlib\file_processor_io\yaml\yaml_type.anubis" />
  101 + <Compile Include="xlib\generic\session.anubis" />
  102 + <Compile Include="xlib\generic\types\session.anubis" />
  103 + <Compile Include="xlib\mail\authentication.anubis" />
  104 + <Compile Include="xlib\mail\compose_email.anubis" />
  105 + <Compile Include="xlib\mail\decode_mail.anubis" />
  106 + <Compile Include="xlib\mail\encode_mail.anubis" />
  107 + <Compile Include="xlib\mail\lexers\enhanced_status.anubis" />
  108 + <Compile Include="xlib\mail\lexers\fqa.anubis" />
  109 + <Compile Include="xlib\mail\send_mail.anubis" />
  110 + <Compile Include="xlib\mail\send_mail_type.anubis" />
  111 + <Compile Include="xlib\mail\smtp_client.anubis" />
  112 + <Compile Include="xlib\mail\smtp_server_extensions.anubis" />
  113 + <Compile Include="xlib\mail\tools.anubis" />
  114 + <Compile Include="xlib\mail\types\generated\email_address.anubis" />
  115 + <Compile Include="xlib\mail\types\generated\email_to_send.anubis" />
  116 + <Compile Include="xlib\network\socket_pool.anubis" />
  117 + <Compile Include="xlib\net_services\CXM_generic_client.anubis" />
  118 + <Compile Include="xlib\net_services\CXM_generic_protocol.anubis" />
  119 + <Compile Include="xlib\net_services\CXM_net_services.anubis" />
  120 + <Compile Include="xlib\net_services\get_file.anubis" />
  121 + <Compile Include="xlib\net_services\send_file.anubis" />
  122 + <Compile Include="xlib\net_services_protocols\ftp_client.anubis" />
  123 + <Compile Include="xlib\net_services_protocols\logger_client.anubis" />
  124 + <Compile Include="xlib\net_services_protocols\logger_server.anubis" />
  125 + <Compile Include="xlib\net_services_protocols\logger_service_deprecated.anubis" />
  126 + <Compile Include="xlib\net_services_protocols\logger_test.anubis" />
  127 + <Compile Include="xlib\net_services_protocols\pkg_updater_protocol.anubis" />
  128 + <Compile Include="xlib\os_tools\freebsd\rc_conf.anubis" />
  129 + <Compile Include="xlib\os_tools\linux\config\network_interface_file.anubis" />
  130 + <Compile Include="xlib\string\crlf.anubis" />
  131 + <Compile Include="xlib\types\generated\file_ref.anubis" />
  132 + <Compile Include="xlib\types\version.anubis" />
  133 + <Compile Include="xlib\unit_test\test.anubis" />
  134 + <Compile Include="xlib\unit_test\xml_rpc.unit_test.anubis" />
  135 + <Compile Include="xlib\web\color\color.anubis" />
  136 + <Compile Include="xlib\web\controllers_web_site.anubis" />
  137 + <Compile Include="xlib\web\counter.anubis" />
  138 + <Compile Include="xlib\web\CXM_common.anubis" />
  139 + <Compile Include="xlib\web\CXM_cookies.anubis" />
  140 + <Compile Include="xlib\web\CXM_dojo.anubis" />
  141 + <Compile Include="xlib\web\CXM_dropzone.anubis" />
  142 + <Compile Include="xlib\web\CXM_form.anubis" />
  143 + <Compile Include="xlib\web\CXM_generic_form.anubis" />
  144 + <Compile Include="xlib\web\CXM_generic_login.anubis" />
  145 + <Compile Include="xlib\web\CXM_generic_table.anubis" />
  146 + <Compile Include="xlib\web\CXM_html_tooltip.anubis" />
  147 + <Compile Include="xlib\web\CXM_https_get.anubis" />
  148 + <Compile Include="xlib\web\CXM_http_get.anubis" />
  149 + <Compile Include="xlib\web\CXM_http_get_common.anubis" />
  150 + <Compile Include="xlib\web\CXM_jquery.anubis" />
  151 + <Compile Include="xlib\web\CXM_json.anubis" />
  152 + <Compile Include="xlib\web\CXM_making_a_web_site.anubis" />
  153 + <Compile Include="xlib\web\CXM_mime.anubis" />
  154 + <Compile Include="xlib\web\CXM_multihost_http_server.anubis" />
  155 + <Compile Include="xlib\web\CXM_page_message.anubis" />
  156 + <Compile Include="xlib\web\CXM_style_tools.anubis" />
  157 + <Compile Include="xlib\web\CXM_urllib.anubis" />
  158 + <Compile Include="xlib\web\CXM_web_action.anubis" />
  159 + <Compile Include="xlib\web\CXM_web_arg_encode.anubis" />
  160 + <Compile Include="xlib\web\CXM_web_arg_utils.anubis" />
  161 + <Compile Include="xlib\web\CXM_web_dump.anubis" />
  162 + <Compile Include="xlib\web\CXM_web_session.anubis" />
  163 + <Compile Include="xlib\web\CXM_widgets.anubis" />
  164 + <Compile Include="xlib\web\CXM_xml_rpc.anubis" />
  165 + <Compile Include="xlib\web\CXM_xml_rpc_parser.anubis" />
  166 + <Compile Include="xlib\web\CXM_xml_rpc_types.anubis" />
  167 + <Compile Include="xlib\web\fonts\awesome.anubis" />
  168 + <Compile Include="xlib\web\jQuery\CXM_jquery_animate.anubis" />
  169 + <Compile Include="xlib\web\jQuery\CXM_jquery_button.anubis" />
  170 + <Compile Include="xlib\web\jQuery\CXM_jquery_datatable.anubis" />
  171 + <Compile Include="xlib\web\jQuery\CXM_jquery_datatable_plugins.anubis" />
  172 + <Compile Include="xlib\web\jQuery\CXM_jquery_datatable_server_side.anubis" />
  173 + <Compile Include="xlib\web\jQuery\CXM_jquery_datatable_translation.anubis" />
  174 + <Compile Include="xlib\web\jQuery\CXM_jquery_datatable_types.anubis" />
  175 + <Compile Include="xlib\web\jQuery\CXM_jquery_dialog.anubis" />
  176 + <Compile Include="xlib\web\jQuery\CXM_jquery_easing.anubis" />
  177 + <Compile Include="xlib\web\jQuery\CXM_jquery_eudock.anubis" />
  178 + <Compile Include="xlib\web\jQuery\CXM_jquery_eudock_types.anubis" />
  179 + <Compile Include="xlib\web\jQuery\CXM_jquery_icons.anubis" />
  180 + <Compile Include="xlib\web\jQuery\CXM_jquery_jqplot.anubis" />
  181 + <Compile Include="xlib\web\jQuery\CXM_jquery_tabs.anubis" />
  182 + <Compile Include="xlib\web\jQuery\CXM_jquery_tiptip.anubis" />
  183 + <Compile Include="xlib\web\jQuery\CXM_jquery_toolbar.anubis" />
  184 + <Compile Include="xlib\web\jQuery\CXM_jq_checkbox.anubis" />
  185 + <Compile Include="xlib\web\jQuery\CXM_jq_form.anubis" />
  186 + <Compile Include="xlib\web\jQuery\CXM_jq_radio.anubis" />
  187 + <Compile Include="xlib\web\jQuery\jqgrid.anubis" />
  188 + <Compile Include="xlib\web\jQuery\jq_flot.anubis" />
  189 + <Compile Include="xlib\web\jQuery\ui-addon\datetimepicker.anubis" />
  190 + <Compile Include="xlib\web\js_tools.anubis" />
  191 + <Compile Include="xlib\web\load_content.anubis" />
  192 + <Compile Include="xlib\web\piwik\CXM_piwik.anubis" />
  193 + <Compile Include="xlib\web\plugin\plugin.anubis" />
  194 + <Compile Include="xlib\web\types\controllers_web_site.anubis" />
  195 + <Compile Include="xlib\web\types\making_a_web_site.anubis" />
  196 + <Compile Include="xlib\web\types\web_action_name.anubis" />
  197 + <Compile Include="xlib\web\types\web_session.anubis" />
  198 + <Compile Include="xlib\web\widgets\button.anubis" />
  199 + <Compile Include="xlib\web\widgets\css_helper.anubis" />
  200 + <Compile Include="xlib\web\widgets\dashboard.anubis" />
  201 + <Compile Include="xlib\web\widgets\fisheye_menu.anubis" />
  202 + <Compile Include="xlib\web\widgets\icon.anubis" />
  203 + <Compile Include="xlib\web\widgets\icons_set.anubis" />
  204 + <Compile Include="xlib\web\widgets\left_menu.anubis" />
  205 + <Compile Include="xlib\web\widgets\left_menu_html.anubis" />
  206 + <Compile Include="xlib\web\widgets\menu.anubis" />
  207 + <Compile Include="xlib\web\widgets\pager.anubis" />
  208 + <Compile Include="xlib\web\widgets\specialized_elements.anubis" />
  209 + <None Include="xlib\.git" />
  210 + <None Include="xlib\.gitignore" />
  211 + <None Include="xlib\examples.ide" />
  212 + <None Include="xlib\minimal_web_site.aproj" />
  213 + <None Include="xlib\obj\unit_test.aproj.FileListAbsolute.txt" />
  214 + <None Include="xlib\unit_test.aproj" />
  215 + <None Include="xlib\unit_test.ide" />
  216 + <None Include="xlib\web\js\cxm_jquery_animate.js" />
  217 + </ItemGroup>
  218 +</Project>
0 219 \ No newline at end of file
... ...
src/anb_log.ide 0 → 100644
  1 +
  2 +Microsoft Visual Studio Solution File, Format Version 9.00
  3 +# Visual Studio 2005
  4 +# SharpDevelop 1.0.12.108
  5 +Project("{B6712916-30DE-4a3e-A54C-2A79AC984AEE}") = "anb_log", "anb_log.aproj", "{9AF3C253-38CA-44F2-824F-CFE038997403}"
  6 +EndProject
  7 +Global
  8 + GlobalSection(SolutionConfigurationPlatforms) = preSolution
  9 + Debug|Any CPU = Debug|Any CPU
  10 + Release|Any CPU = Release|Any CPU
  11 + EndGlobalSection
  12 + GlobalSection(ProjectConfigurationPlatforms) = postSolution
  13 + {9AF3C253-38CA-44F2-824F-CFE038997403}.Debug|Any CPU.Build.0 = Debug|Any CPU
  14 + {9AF3C253-38CA-44F2-824F-CFE038997403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
  15 + {9AF3C253-38CA-44F2-824F-CFE038997403}.Release|Any CPU.Build.0 = Release|Any CPU
  16 + {9AF3C253-38CA-44F2-824F-CFE038997403}.Release|Any CPU.ActiveCfg = Release|Any CPU
  17 + EndGlobalSection
  18 +EndGlobal
... ...
src/src/logger_server.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 01/12/2019
  5 + * Time: 02:08
  6 + * © David RENÉ
  7 + */
  8 +
  9 +read tools/basis.anubis
  10 +read system/logger.anubis
  11 +read system/data_io.anubis
  12 +read system/string.anubis
  13 +read system/files.anubis
  14 +read system/parameter/inifile.anubis
  15 +read system/message_queue.anubis
  16 +read xlib/CXM_message_constants.anubis
  17 +
  18 + read logger_client.anubis
  19 +
  20 +type UID_loggers:
  21 + uid_loggers(
  22 + String uid,
  23 + String base_dir,
  24 + Var(List(Logger)) loggers
  25 + )
  26 +.
  27 +
  28 + /** get_uid_loggers
  29 + */
  30 +define Maybe(UID_loggers)
  31 + get_uid_loggers
  32 + (
  33 + List(UID_loggers) all_loggers, //all known logger
  34 + String _uid //searched UID loggers
  35 + )=
  36 + if all_loggers is
  37 + {
  38 + [] then failure,
  39 + [h . t] then
  40 + if h.uid = _uid then
  41 + success(h)
  42 + else
  43 + get_uid_loggers(t, _uid)
  44 + }
  45 +.
  46 +
  47 +define Maybe(Logger)
  48 + get_logger_from_uid
  49 + (
  50 + List(UID_loggers) all_loggers,
  51 + String _uid,
  52 + String log_name,
  53 + Logger anb_logger
  54 + )=
  55 + if all_loggers is
  56 + {
  57 + [] then failure,
  58 + [h . t] then
  59 + if h.uid = _uid then
  60 + if get_logger(*h.loggers, log_name) is
  61 + {
  62 + failure then logError(anb_logger, "can't find log ["+log_name+"] in uid ["+_uid+"]");failure,
  63 + success(log) then success(log)
  64 + }
  65 + else
  66 + get_logger_from_uid(t, _uid, log_name, anb_logger)
  67 + }
  68 +.
  69 +
  70 +define Maybe(Logger)
  71 + create_logger_from_message
  72 + (
  73 + Logger anb_logger,
  74 + Message msg,
  75 + String base_directory
  76 + )=
  77 + if find_string(msg, "LOG_NAME") is {failure then logError(anb_logger, "create_logger_from_message can't find LOG_NAME");failure, success(loggerName) then
  78 + if find_int32 (msg, "FORMAT_SIZE") is {failure then logError(anb_logger, "create_logger_from_message can't find FORMAT_SIZE");failure, success(formatting_size) then
  79 + if find_string(msg, "FILE_NAME") is {failure then logError(anb_logger, "create_logger_from_message can't find FILE_NAME");failure, success(fileName) then
  80 + if find_int32 (msg, "FILE_LEVEL") is {failure then logError(anb_logger, "create_logger_from_message can't find FILE_LEVEL");failure,success(_fileLevel) then
  81 + if find_int32 (msg, "CONS_LEVEL") is {failure then logError(anb_logger, "create_logger_from_message can't find CONS_LEVEL");failure,success(_consoleLevel) then
  82 +
  83 + with file_level = get_LogLevel_from_value(to_Int(_fileLevel)),
  84 + with console_level = get_LogLevel_from_value(to_Int(_consoleLevel)),
  85 + with final_file_path = base_directory + fileName,
  86 + make_directories(final_file_path);
  87 + logInfo(anb_logger, "create_logger_from_message logger name ["+loggerName+"] format size["+formatting_size+"] file name["+fileName+"] file level ["+get_log_level_char(file_level)+"] console level ["+get_log_level_char(console_level)+"]");
  88 + success(createLogger(loggerName, to_Int(formatting_size), final_file_path, file_level, console_level))
  89 + }}}}}
  90 +.
  91 +
  92 + /** register one logger into UID
  93 + */
  94 +define One
  95 + register_logger
  96 + (
  97 + Var(List(UID_loggers)) logs,
  98 + Message msg,
  99 + String base_directory,
  100 + Logger anb_logger
  101 + )=
  102 +
  103 + if find_string(msg, "UID") is { failure then logError(anb_logger, "register_logger UID not found"), success(uid) then
  104 + if find_string(msg, "LOG_NAME") is { failure then logError(anb_logger, "register_logger can't find LOG_NAME"), success(log_name) then
  105 + if get_uid_loggers(*logs, uid) is
  106 + {
  107 + failure then //the uid logger doesn't exists so we create and
  108 + logError(anb_logger, "register_logger UID logger ["+uid+"] doesn't exist. Please register the UID first"),
  109 + success(_uid_log) then
  110 + if get_logger(*_uid_log.loggers, log_name) is
  111 + {
  112 + failure then
  113 + if create_logger_from_message(anb_logger, msg, _uid_log.base_dir) is
  114 + {
  115 + failure then unique,
  116 + success(new_log) then
  117 + _uid_log.loggers <- [new_log . *_uid_log.loggers];
  118 + logInfo(anb_logger, "register_logger: logger ["+log_name+"] created in ["+uid+"]")
  119 + }
  120 + success(_) then
  121 + logWarning(anb_logger, "register_logger: logger ["+log_name+"] already exists in ["+uid+"]")
  122 + }
  123 + }
  124 + }}
  125 +.
  126 +
  127 +define One
  128 + register_uid
  129 + (
  130 + Var(List(UID_loggers)) logs,
  131 + Message msg,
  132 + String log_server_base_dir,
  133 + Logger anb_logger
  134 + )=
  135 + if find_string(msg, "UID") is { failure then logError(anb_logger, "register_uid can't find UID field"), success(uid) then
  136 + with default_path = find_string(msg, "DEFAULT_PATH", "/"),
  137 + abs_path = find_bool(msg, "ABSOLUTE_PATH", false),
  138 + if get_uid_loggers(*logs, uid) is
  139 + {
  140 + failure then //the uid logger doesn't exists so we create and
  141 + with base_dir = if abs_path then default_path else log_server_base_dir + default_path,
  142 + with new_uid = uid_loggers(uid, base_dir, var([])),
  143 + logs <- [ new_uid . *logs];
  144 + logInfo(anb_logger, "register_uid UID logger ["+uid+"] success with base dir '"+base_dir+"'.")
  145 + success(_) then
  146 + logError(anb_logger, "register_uid UID logger ["+uid+"] already exists.")
  147 + }}
  148 +.
  149 +
  150 +define Bool
  151 + process_log
  152 + (
  153 + Logger log,
  154 + Message msg
  155 + )=
  156 + if find_string(msg, "LOG_STRING") is {failure then logError(log, "process_log can't find LOG_STRING");false, success(log_string) then
  157 + if find_int32 (msg, "LEVEL") is {failure then logError(log, "process_log can't find LEVEL");false, success(int_level) then
  158 + if find_int32 (msg, "THREAD_ID") is {failure then logError(log, "process_log can't find THREAD_ID");false, success(thread_id) then
  159 +
  160 + with level = get_LogLevel_from_value(to_Int(int_level)),
  161 + if level is logTrace then
  162 + if find_string(msg, "LOG_MASK") is
  163 + {
  164 + failure then
  165 + //println("process_log can't find LogMask ["+log_string+"]");
  166 + logError(log, "process_log can't find LOG_MASK");false,
  167 + success(log_mask) then logTrace(log, logMask(log_mask), log_string, thread_id); true
  168 + }
  169 + else doLog(log, log_string, level, thread_id); true
  170 +
  171 + }
  172 + }
  173 + }.
  174 +
  175 +define Bool
  176 + process_log
  177 + (
  178 + List(Logger) logs,
  179 + Message msg
  180 + )=
  181 + if find_string(msg, "LOG_NAME") is
  182 + {
  183 + failure then println("process_log can't find LOG_NAME");false,
  184 + success(log_name) then
  185 + if get_logger(logs, log_name) is
  186 + {
  187 + failure then println("can't find log ["+log_name+"]");false,
  188 + success(log) then process_log(log, msg)
  189 + }
  190 + }
  191 +.
  192 +
  193 +define Bool
  194 + process_log
  195 + (
  196 + List(UID_loggers) logs,
  197 + Message msg,
  198 + Logger anb_logger
  199 + )=
  200 + with uid = if find_string(msg, "UID") is { failure then "", success(_uid) then _uid},
  201 +
  202 + if find_string(msg, "LOG_NAME") is
  203 + {
  204 + failure then logError(anb_logger, "process_log can't find LOG_NAME");false,
  205 + success(log_name) then
  206 + if get_logger_from_uid(logs, uid, log_name, anb_logger) is
  207 + {
  208 + failure then logError(anb_logger, "can't find log ["+log_name+"] in ["+uid+"]");false,
  209 + success(log) then process_log(log, msg)
  210 + }
  211 + }
  212 +.
  213 +
  214 +public define String
  215 + data_preview
  216 + (
  217 + ByteArray data,
  218 + Int max
  219 + ) =
  220 + with l = length(data),
  221 + firsts_bytes = extract(data, 0, max),
  222 + "Length=" + l + "; String='"+to_string(firsts_bytes)+"' Buffer=[" + to_ascii(firsts_bytes) + (if l > max then "...]" else "]").
  223 +
  224 +
  225 +define (UDP_Socket, ByteArray, Truncation, Word32, Word32) -> One
  226 + make_udp_handler
  227 + (
  228 + Var(List(UID_loggers)) logs,
  229 + String base_directory,
  230 + Logger anb_logger
  231 + ) =
  232 + (
  233 + UDP_Socket socket,
  234 + ByteArray data,
  235 + Truncation truncation,
  236 + Word32 ip_address,
  237 + Word32 ip_port
  238 + ) |->
  239 + with ip = ip_addr_to_string(ip_address),
  240 + logTrace(anb_logger, logMask("Logger"), "LoggerServer: data received (" + length(data) + " bytes) from IP " + ip + "... ");
  241 + //println("LoggerServer: data received (" + length(data) + " bytes) from IP " + ip + "... ");
  242 + //println("LoggerServer: data_preview " + data_preview(data, 20));
  243 +
  244 + if receive_message_from_io(make_data_io(data)) is
  245 + {
  246 + failure then
  247 + //println("LoggerServer: Bad data packet received from IP " + ip + ": " + data_preview(data, 20));
  248 + logWarning(anb_logger, "LoggerServer: Bad data packet received from IP " + ip + ": " + data_preview(data, 20)),
  249 + success(msg) then
  250 + if *msg.what = _CXM_LOGGER_LOG then
  251 + forget(process_log(*logs, msg, anb_logger))
  252 + else if *msg.what = _CXM_LOGGER_REGISTER_UID then
  253 + forget(register_uid(logs, msg, base_directory, anb_logger))
  254 + else if *msg.what = _CXM_LOGGER_REGISTER_LOG then
  255 + forget(register_logger(logs, msg, base_directory, anb_logger))
  256 + else
  257 + logError(anb_logger, "LoggerService: wrong message_received. [" + to_hexa(*msg.what) + "] is not _CXM_LOGGER_LOG or _CXM_LOGGER_REGISTER or _CXM_LOGGER_UNREGISTER ")
  258 +}
  259 +.
  260 +define One
  261 + my_notify
  262 + (
  263 + One dummy
  264 + ) =
  265 + unique.
  266 +
  267 +public define Maybe(UDP_Server)
  268 + start_logger_server
  269 + (
  270 + Var(List(UID_loggers)) logs,
  271 + Logger anb_logger,
  272 + Word32 logger_listen_port,
  273 + String base_directory
  274 + ) =
  275 + if start_udp_server(0,
  276 + logger_listen_port,
  277 + make_udp_handler(logs, base_directory, anb_logger),
  278 + 8*1024,
  279 + my_notify) is
  280 + {
  281 + cannot_create_the_socket then logError(anb_logger, "Cannot create the listening socket."); failure,
  282 + cannot_bind_address_port then logError(anb_logger, "Cannot bind to port " + logger_listen_port + "."); failure,
  283 + access_denied then logError(anb_logger, "Cannot listen on port " + logger_listen_port + "."); failure,
  284 + ok(server) then logInfo(anb_logger, "LocalLog Server started on port " + logger_listen_port + "."); success(server)
  285 + }
  286 +.
  287 +
  288 +read locale/L3LanguageInfo.anubis //date and time formating
  289 +
  290 +define Var(List(UID_loggers))
  291 + create_default_loggers
  292 + (
  293 + String log_server_base_dir
  294 + )
  295 + =
  296 + //none uid for extended libraryet etc...
  297 + with base_dir = log_server_base_dir + "/unknown/",
  298 + sql = createLogger("SQL", 8, base_dir+"sql.log", logTrace, logTrace),
  299 + db = createLogger("SDB", 8, base_dir+"db.log", logTrace, logTrace),
  300 + sql_trace = createLogger("SQL_TRACE", 8, base_dir+"sql.log", logTrace, logTrace),
  301 + make_directories(base_dir);
  302 + with uid = uid_loggers("", base_dir, var([sql, db, sql_trace])),
  303 + var([uid])
  304 +.
  305 +
  306 +global define One
  307 + anb_log
  308 + (
  309 + List(String) args
  310 + )=
  311 + with product_time = to_Int(__TIME__),
  312 + with anb_log_path = find_and_replace(my_anubis_directory, "\\", "/") + "/anb_log/",
  313 + with ini = loadIniFile(anb_log_path+"config.ini"),
  314 + server_port = readWord32(ini, "GENERAL", "udp_port", 45514),
  315 + base_directory = readString(ini, "GENERAL", "base_directory", anb_log_path+"log/"),
  316 + make_directories(base_directory);
  317 + //create own logger
  318 + with anb_logger = createLogger("anb_log", 7, base_directory + "anb_log.log", logTrace, logTrace),
  319 + logInfo(anb_logger, "start anb_log "+datef_ymd(product_time) + " " + dhour_format(product_time));
  320 +
  321 + forget(start_logger_server(create_default_loggers(base_directory), anb_logger, server_port, base_directory))
  322 +.
... ...
src/src/logger_test.anubis 0 → 100644
  1 +/*
  2 + * Created by PyramIDE.
  3 + * User: フランスのトトロ aka (David RENÉ)
  4 + * Date: 01/12/2019
  5 + * Time: 19:52
  6 + * © David RENÉ
  7 + */
  8 +
  9 +read tools/basis.anubis
  10 +read logger_client.anubis
  11 +
  12 +global define One
  13 + logger_test
  14 + (
  15 + List(String) args
  16 + )=
  17 + with app0 = "logger test0",
  18 + uid0_dir = "logger test0/",
  19 +log_name0_0 = "log_name0_0",
  20 +log_name0_1 = "log_name0_1",
  21 + uid1 = "logger test1",
  22 +
  23 + register_uid(app0, uid0_dir, false);
  24 + register_logger(app0, log_name0_0, 8, false, log_name0_0+".log", logDebug, logDebug);
  25 + register_logger(app0, log_name0_1, 8, false, log_name0_1+".log", logDebug, logDebug);
  26 + sleep(1000);
  27 + logNone (app0, log_name0_0, "logNone in log_name0_0");
  28 + logNone (app0, log_name0_1, "logNone in log_name0_1");
  29 + logCriticalError (app0, log_name0_0, "logCriticalError in log_name0_0");
  30 + logCriticalError (app0, log_name0_1, "logCriticalError in log_name0_1");
  31 + logError (app0, log_name0_0, "logError in log_name0_0");
  32 + logError (app0, log_name0_1, "logError in log_name0_1");
  33 + logWarning (app0, log_name0_0, "logWarning in log_name0_0");
  34 + logWarning (app0, log_name0_1, "logWarning in log_name0_1");
  35 + logInfo (app0, log_name0_0, "logInfo in log_name0_0");
  36 + logInfo (app0, log_name0_1, "logInfo in log_name0_1");
  37 + logDebug (app0, log_name0_0, "logDebug in log_name0_0");
  38 + logDebug (app0, log_name0_1, "logDebug in log_name0_1")
  39 +.
... ...
xlib @ feda58399a9
1   -Subproject commit 42087dcf0b412fabb5b67106041c711206c2281f
  1 +Subproject commit feda58399a96e2dc798291203edae434a6d2e3ba
... ...