Revisited application layout, shared logger and relation with cms to avoid mixing various layout.

This commit is contained in:
2015-02-05 10:28:46 +01:00
parent e40f8ee4d2
commit a810b1176c
4 changed files with 98 additions and 65 deletions

View File

@@ -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

View File

@@ -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)"