From a810b1176c2b39792731d0024a9f7754b73493d9 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 5 Feb 2015 10:28:46 +0100 Subject: [PATCH] Revisited application layout, shared logger and relation with cms to avoid mixing various layout. --- examples/demo/src/ewf_roc_server.e | 16 +++-- library/layout/src/application_layout.e | 51 +++++++++++-- library/layout/src/logger/shared_logger.e | 88 ++++++++++------------- src/configuration/cms_layout.e | 8 +-- 4 files changed, 98 insertions(+), 65 deletions(-) diff --git a/examples/demo/src/ewf_roc_server.e b/examples/demo/src/ewf_roc_server.e index a1bd205..9de8b74 100644 --- a/examples/demo/src/ewf_roc_server.e +++ b/examples/demo/src/ewf_roc_server.e @@ -2,8 +2,8 @@ note description: "[ application service ]" - date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $" - revision: "$Revision: 96542 $" + date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $" + revision: "$Revision: 96584 $" class EWF_ROC_SERVER @@ -23,7 +23,7 @@ inherit REFACTORING_HELPER - ARGUMENTS + SHARED_EXECUTION_ENVIRONMENT SHARED_LOGGER @@ -102,14 +102,16 @@ feature {NONE} -- Launch operation feature -- CMS Initialization cms_setup: CMS_DEFAULT_SETUP + local + utf: UTF_CONVERTER do - if attached separate_character_option_value ('d') as l_dir then - log.write_debug (generator + ".cms_setup using a command line argument -d " + l_dir ) - create layout.make_with_path (create {PATH}.make_from_string (l_dir)) + if attached execution_environment.arguments.separate_character_option_value ('d') as l_dir then + create layout.make_with_directory_name (l_dir) else - log.write_debug (generator + ".cms_setup using current directory" ) create layout.make_default end + initialize_logger (layout) + log.write_debug (generator + ".cms_setup based directory %"" + utf.escaped_utf_32_string_to_utf_8_string_8 (layout.path.name) + "%"") create Result.make (layout) setup_storage (Result) end diff --git a/library/layout/src/application_layout.e b/library/layout/src/application_layout.e index aded89d..6846ede 100644 --- a/library/layout/src/application_layout.e +++ b/library/layout/src/application_layout.e @@ -11,15 +11,19 @@ note - templates (html, Collection+JSON, ...) - ... ]" - date: "$Date$" - revision: "$Revision$" + date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $" + revision: "$Revision: 96584 $" class APPLICATION_LAYOUT +inherit + SHARED_EXECUTION_ENVIRONMENT + create make_default, - make_with_path + make_with_path, + make_with_directory_name feature {NONE} -- Initialization @@ -37,6 +41,34 @@ feature {NONE} -- Initialization -- Create a layour based on a path `p'. do path := p.absolute_path.canonical_path + initialize_name + end + + make_with_directory_name (a_dirname: READABLE_STRING_GENERAL) + -- Create a layour based on a path `p'. + do + make_with_path (create {PATH}.make_from_string (a_dirname)) + end + + initialize_name + -- Initialize `name'. + local + p: PATH + s: STRING_32 + do + create p.make_from_string (execution_environment.arguments.command_name) + if attached p.entry as e then + p := e + end + create s.make_from_string (p.name) + if attached p.extension as l_extension then + s.remove_tail (l_extension.count + 1) + end + if s.is_whitespace then + set_name ({STRING_8} "app") + else + set_name (s) + end end feature -- Access @@ -44,6 +76,17 @@ feature -- Access path: PATH -- Root location. + name: IMMUTABLE_STRING_32 + -- Application name, default is "app" + +feature -- Change + + set_name (a_name: READABLE_STRING_GENERAL) + -- Set `name' from `a_name'. + do + create name.make_from_string_general (a_name) + end + feature -- Access: internal config_path: PATH @@ -163,6 +206,6 @@ feature {NONE} -- Implementation -- Directory for templates (HTML, etc). ;note - copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" + copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" end diff --git a/library/layout/src/logger/shared_logger.e b/library/layout/src/logger/shared_logger.e index 5e35cfe..20a24fd 100644 --- a/library/layout/src/logger/shared_logger.e +++ b/library/layout/src/logger/shared_logger.e @@ -1,7 +1,7 @@ note description: "Provides logger information" - date: "$Date: 2015-02-03 19:11:23 +0100 (mar., 03 févr. 2015) $" - revision: "$Revision: 96575 $" + date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $" + revision: "$Revision: 96584 $" class SHARED_LOGGER @@ -9,49 +9,47 @@ class inherit LOG_PRIORITY_CONSTANTS - ARGUMENTS + SHARED_EXECUTION_ENVIRONMENT feature -- Logger - log: LOGGING_FACILITY - -- New `log' (once per process) + -- `log' facility (once per process) -- that could be shared between threads -- without reinitializing it. - local - l_log_writer: LOG_ROLLING_WRITER_FILE - l_environment: EXECUTION_ENVIRONMENT - l_path: PATH - l_logger_config: LOGGER_CONFIGURATION once ("PROCESS") - --| Initialize the logging facility create Result.make - create l_environment - if attached separate_character_option_value ('d') as l_dir then - create l_path.make_from_string (l_dir) - else - create l_path.make_current - l_path := l_path.extended ("site") - end - l_logger_config := new_logger_level_configuration (l_path.extended("config").extended ("application_configuration.json")) - if attached l_logger_config.location as p then - create l_log_writer.make_at_location (p.extended ("api.log")) - else - create l_log_writer.make_at_location (l_path.extended ("logs").extended ("api.log")) - end - - l_log_writer.set_max_file_size ({NATURAL_64} 1024*1204) - l_log_writer.set_max_backup_count (l_logger_config.backup_count) - set_logger_level (l_log_writer, l_logger_config.level) - log.register_log_writer (l_log_writer) - - --| Write an informational message - Result.write_information ("The application is starting up...") end -feature {NONE} -- JSON +feature {NONE} -- Implementation - set_logger_level (a_log_writer: LOG_ROLLING_WRITER_FILE; a_priority: INTEGER) + initialize_logger (app: APPLICATION_LAYOUT) + local + l_log_writer_file: LOG_ROLLING_WRITER_FILE + l_log_writer: LOG_WRITER + l_logs_path: detachable PATH + l_logger_config: LOGGER_CONFIGURATION + ut: FILE_UTILITIES + do + l_logger_config := new_logger_level_configuration (app.application_config_path) + l_logs_path := l_logger_config.location + if l_logs_path = Void then + l_logs_path := app.logs_path + end + if ut.directory_path_exists (l_logs_path) then + create l_log_writer_file.make_at_location (l_logs_path.extended (app.name).appended_with_extension ("log")) + l_log_writer_file.set_max_file_size ({NATURAL_64} 1024 * 1204) + l_log_writer_file.set_max_backup_count (l_logger_config.backup_count) + l_log_writer := l_log_writer_file + else + -- Should we create the directory anyway ? + create {LOG_WRITER_NULL} l_log_writer + end + set_logger_level (l_log_writer, l_logger_config.level) + log.register_log_writer (l_log_writer) + end + + set_logger_level (a_log_writer: LOG_WRITER; a_priority: INTEGER) -- Setup the logger level based on `a_priority' do if a_priority = log_debug then @@ -80,10 +78,14 @@ feature {NONE} -- JSON -- By default, level is set to `DEBUG'. local l_parser: JSON_PARSER + ut: FILE_UTILITIES do create Result - if attached json_file_from (a_path) as json_file then - l_parser := new_json_parser (json_file) + if + ut.file_path_exists (a_path) and then + attached (create {JSON_FILE_READER}).read_json_from (a_path.name) as json_file + then + create l_parser.make_with_string (json_file) l_parser.parse_content if l_parser.is_valid and then @@ -105,20 +107,6 @@ feature {NONE} -- JSON end end - json_file_from (a_fn: PATH): detachable STRING - local - ut: FILE_UTILITIES - do - if ut.file_path_exists (a_fn) then - Result := (create {JSON_FILE_READER}).read_json_from (a_fn.name) - end - end - - new_json_parser (a_string: STRING): JSON_PARSER - do - create Result.make_with_string (a_string) - end - note copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" diff --git a/src/configuration/cms_layout.e b/src/configuration/cms_layout.e index bd3b290..9a126cd 100644 --- a/src/configuration/cms_layout.e +++ b/src/configuration/cms_layout.e @@ -7,8 +7,8 @@ note - documentation - themes ]" - date: "$Date: 2014-12-18 16:37:11 +0100 (jeu., 18 déc. 2014) $" - revision: "$Revision: 96383 $" + date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $" + revision: "$Revision: 96584 $" class CMS_LAYOUT @@ -19,8 +19,8 @@ inherit create make_default, - make_with_path - + make_with_path, + make_with_directory_name feature -- Access