Revisited application layout, shared logger and relation with cms to avoid mixing various layout.
This commit is contained in:
@@ -2,8 +2,8 @@ note
|
|||||||
description: "[
|
description: "[
|
||||||
application service
|
application service
|
||||||
]"
|
]"
|
||||||
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
|
date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $"
|
||||||
revision: "$Revision: 96542 $"
|
revision: "$Revision: 96584 $"
|
||||||
|
|
||||||
class
|
class
|
||||||
EWF_ROC_SERVER
|
EWF_ROC_SERVER
|
||||||
@@ -23,7 +23,7 @@ inherit
|
|||||||
|
|
||||||
REFACTORING_HELPER
|
REFACTORING_HELPER
|
||||||
|
|
||||||
ARGUMENTS
|
SHARED_EXECUTION_ENVIRONMENT
|
||||||
|
|
||||||
SHARED_LOGGER
|
SHARED_LOGGER
|
||||||
|
|
||||||
@@ -102,14 +102,16 @@ feature {NONE} -- Launch operation
|
|||||||
feature -- CMS Initialization
|
feature -- CMS Initialization
|
||||||
|
|
||||||
cms_setup: CMS_DEFAULT_SETUP
|
cms_setup: CMS_DEFAULT_SETUP
|
||||||
|
local
|
||||||
|
utf: UTF_CONVERTER
|
||||||
do
|
do
|
||||||
if attached separate_character_option_value ('d') as l_dir then
|
if attached execution_environment.arguments.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_directory_name (l_dir)
|
||||||
create layout.make_with_path (create {PATH}.make_from_string (l_dir))
|
|
||||||
else
|
else
|
||||||
log.write_debug (generator + ".cms_setup using current directory" )
|
|
||||||
create layout.make_default
|
create layout.make_default
|
||||||
end
|
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)
|
create Result.make (layout)
|
||||||
setup_storage (Result)
|
setup_storage (Result)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,15 +11,19 @@ note
|
|||||||
- templates (html, Collection+JSON, ...)
|
- templates (html, Collection+JSON, ...)
|
||||||
- ...
|
- ...
|
||||||
]"
|
]"
|
||||||
date: "$Date$"
|
date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $"
|
||||||
revision: "$Revision$"
|
revision: "$Revision: 96584 $"
|
||||||
|
|
||||||
class
|
class
|
||||||
APPLICATION_LAYOUT
|
APPLICATION_LAYOUT
|
||||||
|
|
||||||
|
inherit
|
||||||
|
SHARED_EXECUTION_ENVIRONMENT
|
||||||
|
|
||||||
create
|
create
|
||||||
make_default,
|
make_default,
|
||||||
make_with_path
|
make_with_path,
|
||||||
|
make_with_directory_name
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
@@ -37,6 +41,34 @@ feature {NONE} -- Initialization
|
|||||||
-- Create a layour based on a path `p'.
|
-- Create a layour based on a path `p'.
|
||||||
do
|
do
|
||||||
path := p.absolute_path.canonical_path
|
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
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
@@ -44,6 +76,17 @@ feature -- Access
|
|||||||
path: PATH
|
path: PATH
|
||||||
-- Root location.
|
-- 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
|
feature -- Access: internal
|
||||||
|
|
||||||
config_path: PATH
|
config_path: PATH
|
||||||
@@ -163,6 +206,6 @@ feature {NONE} -- Implementation
|
|||||||
-- Directory for templates (HTML, etc).
|
-- Directory for templates (HTML, etc).
|
||||||
|
|
||||||
;note
|
;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)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
note
|
note
|
||||||
description: "Provides logger information"
|
description: "Provides logger information"
|
||||||
date: "$Date: 2015-02-03 19:11:23 +0100 (mar., 03 févr. 2015) $"
|
date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $"
|
||||||
revision: "$Revision: 96575 $"
|
revision: "$Revision: 96584 $"
|
||||||
|
|
||||||
class
|
class
|
||||||
SHARED_LOGGER
|
SHARED_LOGGER
|
||||||
@@ -9,49 +9,47 @@ class
|
|||||||
inherit
|
inherit
|
||||||
LOG_PRIORITY_CONSTANTS
|
LOG_PRIORITY_CONSTANTS
|
||||||
|
|
||||||
ARGUMENTS
|
SHARED_EXECUTION_ENVIRONMENT
|
||||||
|
|
||||||
feature -- Logger
|
feature -- Logger
|
||||||
|
|
||||||
|
|
||||||
log: LOGGING_FACILITY
|
log: LOGGING_FACILITY
|
||||||
-- New `log' (once per process)
|
-- `log' facility (once per process)
|
||||||
-- that could be shared between threads
|
-- that could be shared between threads
|
||||||
-- without reinitializing it.
|
-- 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")
|
once ("PROCESS")
|
||||||
--| Initialize the logging facility
|
|
||||||
create Result.make
|
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
|
end
|
||||||
|
|
||||||
l_log_writer.set_max_file_size ({NATURAL_64} 1024*1204)
|
feature {NONE} -- Implementation
|
||||||
l_log_writer.set_max_backup_count (l_logger_config.backup_count)
|
|
||||||
|
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)
|
set_logger_level (l_log_writer, l_logger_config.level)
|
||||||
log.register_log_writer (l_log_writer)
|
log.register_log_writer (l_log_writer)
|
||||||
|
|
||||||
--| Write an informational message
|
|
||||||
Result.write_information ("The application is starting up...")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- JSON
|
set_logger_level (a_log_writer: LOG_WRITER; a_priority: INTEGER)
|
||||||
|
|
||||||
set_logger_level (a_log_writer: LOG_ROLLING_WRITER_FILE; a_priority: INTEGER)
|
|
||||||
-- Setup the logger level based on `a_priority'
|
-- Setup the logger level based on `a_priority'
|
||||||
do
|
do
|
||||||
if a_priority = log_debug then
|
if a_priority = log_debug then
|
||||||
@@ -80,10 +78,14 @@ feature {NONE} -- JSON
|
|||||||
-- By default, level is set to `DEBUG'.
|
-- By default, level is set to `DEBUG'.
|
||||||
local
|
local
|
||||||
l_parser: JSON_PARSER
|
l_parser: JSON_PARSER
|
||||||
|
ut: FILE_UTILITIES
|
||||||
do
|
do
|
||||||
create Result
|
create Result
|
||||||
if attached json_file_from (a_path) as json_file then
|
if
|
||||||
l_parser := new_json_parser (json_file)
|
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
|
l_parser.parse_content
|
||||||
if
|
if
|
||||||
l_parser.is_valid and then
|
l_parser.is_valid and then
|
||||||
@@ -105,20 +107,6 @@ feature {NONE} -- JSON
|
|||||||
end
|
end
|
||||||
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
|
note
|
||||||
copyright: "2011-2015, 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)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ note
|
|||||||
- documentation
|
- documentation
|
||||||
- themes
|
- themes
|
||||||
]"
|
]"
|
||||||
date: "$Date: 2014-12-18 16:37:11 +0100 (jeu., 18 déc. 2014) $"
|
date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $"
|
||||||
revision: "$Revision: 96383 $"
|
revision: "$Revision: 96584 $"
|
||||||
|
|
||||||
class
|
class
|
||||||
CMS_LAYOUT
|
CMS_LAYOUT
|
||||||
@@ -19,8 +19,8 @@ inherit
|
|||||||
|
|
||||||
create
|
create
|
||||||
make_default,
|
make_default,
|
||||||
make_with_path
|
make_with_path,
|
||||||
|
make_with_directory_name
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user