Simplify CMS_SERVICE initialization, and CMS server (launcher).

Renamed "layout" lib as "app_env" with APPLICATION_ENVIRONMENT interface.
  applied changed to callers.
Added CMS_THEME.has_region (a_name): BOOLEAN to know if a region is declared in a defined theme.
This commit is contained in:
2015-04-29 23:01:42 +02:00
parent 0eb2b70d0f
commit 6ff7a6493c
34 changed files with 214 additions and 154 deletions

View File

@@ -0,0 +1,211 @@
note
description: "[
Application environment (layout, ...)
Related to file system locations such as
- configuration locations
- application
- log
- documentation
- www
- assets
- templates (html, Collection+JSON, ...)
- ...
]"
date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $"
revision: "$Revision: 96584 $"
class
APPLICATION_ENVIRONMENT
inherit
SHARED_EXECUTION_ENVIRONMENT
create
make_default,
make_with_path,
make_with_directory_name
feature {NONE} -- Initialization
make_default
-- Create a default layout based on current working directory.
local
p: PATH
do
create p.make_current
p := p.extended ("site")
make_with_path (p)
end
make_with_path (p: PATH)
-- 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
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
-- Configuration file path.
local
p: detachable PATH
do
p := internal_config_path
if p = Void then
p := path.extended ("config")
internal_config_path := p
end
Result := p
end
application_config_path: PATH
-- Database Configuration file path.
local
p: detachable PATH
do
p := internal_application_config_path
if p = Void then
p := config_path.extended ("application_configuration.json")
internal_application_config_path := p
end
Result := p
end
logs_path: PATH
-- Directory for logs.
local
p: detachable PATH
do
p := internal_logs_path
if p = Void then
p := path.extended ("logs")
internal_logs_path := p
end
Result := p
end
documentation_path: PATH
-- Directory for API documentation.
local
p: detachable PATH
do
p := internal_documentation_path
if p = Void then
p := path.extended ("doc")
internal_documentation_path := p
end
Result := p
end
www_path: PATH
-- Directory for www.
local
p: detachable PATH
do
p := internal_www_path
if p = Void then
p := path.extended ("www")
internal_www_path := p
end
Result := p
end
assets_path: PATH
-- Directory for public assets.
-- css, images, js.
local
p: detachable PATH
do
p := internal_assets_path
if p = Void then
p := www_path.extended ("assets")
internal_assets_path := p
end
Result := p
end
template_path: PATH
-- Directory for templates (HTML, etc).
local
p: detachable PATH
do
p := internal_template_path
if p = Void then
p := www_path.extended ("template")
internal_template_path := p
end
Result := p
end
feature {NONE} -- Implementation
internal_config_path: detachable like config_path
-- Configuration file path.
internal_application_config_path: detachable like application_config_path
-- Database Configuration file path.
internal_logs_path: detachable like logs_path
-- Directory for logs.
internal_documentation_path: detachable like documentation_path
-- Directory for API documentation.
internal_www_path: detachable like www_path
-- Directory for www.
internal_assets_path: detachable like assets_path
-- Directory for public assets.
-- css, images, js.
internal_template_path: detachable like template_path
-- Directory for templates (HTML, etc).
;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)"
end

View File

@@ -0,0 +1,23 @@
note
description: "See {APPLICATION_ENVIRONMENT}."
date: "$Date$"
revision: "$Revision$"
class
APPLICATION_LAYOUT
obsolete
"Use APPLICATION_ENVIRONMENT [April/2015]"
inherit
APPLICATION_ENVIRONMENT
create
make_default,
make_with_path,
make_with_directory_name
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)"
end

View File

@@ -0,0 +1,119 @@
note
description: "Provide access to json configuration"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
APPLICATION_JSON_CONFIGURATION_HELPER
feature -- Application Configuration
new_smtp_configuration (a_path: PATH): READABLE_STRING_32
-- Build a new database configuration.
local
l_parser: JSON_PARSER
do
Result := ""
if attached json_file_from (a_path) as json_file then
l_parser := new_json_parser (json_file)
l_parser.parse_content
if
l_parser.is_valid and then
attached {JSON_OBJECT} l_parser.parsed_json_value as jv and then
attached {JSON_OBJECT} jv.item ("smtp") as l_smtp and then
attached {JSON_STRING} l_smtp.item ("server") as l_server
then
Result := l_server.item
end
end
end
new_database_configuration (a_path: PATH): detachable DATABASE_CONFIGURATION
-- Build a new database configuration.
local
l_parser: JSON_PARSER
do
if attached json_file_from (a_path) as json_file then
l_parser := new_json_parser (json_file)
l_parser.parse_content
if
l_parser.is_valid and then
attached {JSON_OBJECT} l_parser.parsed_json_value as jv and then
attached {JSON_OBJECT} jv.item ("database") as l_database and then
attached {JSON_OBJECT} l_database.item ("datasource") as l_datasource and then
attached {JSON_STRING} l_datasource.item ("driver") as l_driver and then
attached {JSON_STRING} l_datasource.item ("environment") as l_envrionment and then
attached {JSON_OBJECT} l_database.item ("environments") as l_environments and then
attached {JSON_OBJECT} l_environments.item (l_envrionment.item) as l_environment_selected and then
attached {JSON_STRING} l_environment_selected.item ("connection_string") as l_connection_string
then
create Result.make (l_driver.item, l_connection_string.unescaped_string_32)
end
end
end
new_logger_level_configuration (a_path: PATH): READABLE_STRING_32
-- Retrieve a new logger level configuration.
-- By default, level is set to `DEBUG'.
local
l_parser: JSON_PARSER
do
Result := "DEBUG"
if attached json_file_from (a_path) as json_file then
l_parser := new_json_parser (json_file)
l_parser.parse_content
if
l_parser.is_valid and then
attached {JSON_OBJECT} l_parser.parsed_json_value as jv and then
attached {JSON_OBJECT} jv.item ("logger") as l_logger and then
attached {JSON_STRING} l_logger.item ("level") as l_level
then
Result := l_level.item
end
end
end
new_database_configuration_test (a_path: PATH): detachable DATABASE_CONFIGURATION
-- Build a new database configuration for testing purposes.
local
l_parser: JSON_PARSER
do
if attached json_file_from (a_path) as json_file then
l_parser := new_json_parser (json_file)
l_parser.parse_content
if
l_parser.is_valid and then
attached {JSON_OBJECT} l_parser.parsed_json_value as jv and then
l_parser.is_parsed and then
attached {JSON_OBJECT} jv.item ("database") as l_database and then
attached {JSON_OBJECT} l_database.item ("datasource") as l_datasource and then
attached {JSON_STRING} l_datasource.item ("driver") as l_driver and then
attached {JSON_STRING} l_datasource.item ("environment") as l_envrionment and then
attached {JSON_STRING} l_datasource.item ("trusted") as l_trusted and then
attached {JSON_OBJECT} l_database.item ("environments") as l_environments and then
attached {JSON_OBJECT} l_environments.item ("test") as l_environment_selected and then
attached {JSON_STRING} l_environment_selected.item ("connection_string") as l_connection_string and then
attached {JSON_STRING} l_environment_selected.item ("name") as l_name
then
create Result.make (l_driver.item, l_connection_string.unescaped_string_8)
end
end
end
feature {NONE} -- JSON
json_file_from (a_fn: PATH): detachable STRING
do
Result := (create {JSON_FILE_READER}).read_json_from (a_fn.name.out)
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)"
end

View File

@@ -0,0 +1,97 @@
note
description: "Object that represent Database configuration settings"
date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $"
revision: "$Revision: 96596 $"
class
DATABASE_CONFIGURATION
create
make
feature {NONE} -- Initialization
make (a_driver: READABLE_STRING_32; a_connection: READABLE_STRING_32)
-- Create a database configuration setting: `driver' with `a_driver',
-- `database_string' with `a_connection'.
do
driver := a_driver
database_string := a_connection
ensure
driver_set: driver = a_driver
server_set: database_string = a_connection
end
feature -- Access
driver: READABLE_STRING_32
--Database driver.
database_string: READABLE_STRING_32
-- Database connection.
connection_string: READABLE_STRING_32
-- Connection string
do
Result := {STRING_32} "Driver={" + driver + {STRING_32} "};" + database_string
end
item (a_param: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
local
s: READABLE_STRING_32
lower_s: READABLE_STRING_32
i,j: INTEGER
k: STRING_32
do
create k.make_from_string_general (a_param)
k.to_lower
s := database_string
lower_s := s.as_lower
i := lower_s.substring_index (k + {STRING_32} "=", 1)
if i > 0 then
if i = 1 or else s[i-1] = ';' then
j := s.index_of (';', i + k.count + 1)
if j = 0 then
j := s.count + 1
end
Result := s.substring (i + k.count + 1, j - 1)
end
end
end
server_name: detachable READABLE_STRING_32
do
Result := item ("Server")
end
port: INTEGER
do
if
attached item ("Port") as l_port and then
l_port.is_integer
then
Result := l_port.to_integer
end
end
database_name: detachable READABLE_STRING_32
do
Result := item ("Database")
end
user_id: detachable READABLE_STRING_32
do
Result := item ("Uid")
end
user_password: detachable READABLE_STRING_32
do
Result := item ("Pwd")
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)"
end

View File

@@ -0,0 +1,102 @@
note
description: "Object that represents Logger configuration settings"
date: "$Date: 2015-02-03 19:11:23 +0100 (mar., 03 févr. 2015) $"
revision: "$Revision: 96575 $"
class
LOGGER_CONFIGURATION
inherit
LOG_PRIORITY_CONSTANTS
rename
default_create as log_default_create
end
ANY
redefine
default_create
select
default_create
end
create
default_create
feature -- Initialization
default_create
-- Initialize a Logger Instance configuration with default values
-- backups = `4' and level = `DEBUG'.
do
backup_count := 4
level := Log_debug
location := Void
ensure then
backup_count_set: backup_count = 4
level_set: level = Log_debug
end
feature -- Access
location: detachable PATH
-- Location for logs files, if none use default logs location.
backup_count: NATURAL
-- Max number of backup files.
-- When 0, no backup files are created, and the log file is simply truncated when it becomes larger than `max_file_size'.
-- When non-zero, the value specifies the maximum number of backup files.
level: INTEGER
-- Logger level.
feature -- Element Change
set_location (a_location: detachable PATH)
-- Set `location' to `a_location'.
do
location := a_location
ensure
location_set: a_location ~ location
end
set_location_with_string (a_location: READABLE_STRING_GENERAL)
require
a_location /= Void and then not a_location.is_whitespace
do
set_location (create {PATH}.make_from_string (a_location))
end
set_backup_count (a_backup: NATURAL)
-- Set backup_count to `a_backup'.
do
backup_count := a_backup
ensure
backup_count_set: backup_count = a_backup
end
set_level (a_level: READABLE_STRING_GENERAL)
-- Set a level based on `a_level'.
do
if a_level.is_case_insensitive_equal (emerg_str) then
level := log_emergency
elseif a_level.is_case_insensitive_equal (alert_str) then
level := log_alert
elseif a_level.is_case_insensitive_equal (crit_str) then
level := log_critical
elseif a_level.is_case_insensitive_equal (error_str) then
level := log_error
elseif a_level.is_case_insensitive_equal (warn_str) then
level := log_warning
elseif a_level.is_case_insensitive_equal (notic_str) then
level := log_notice
elseif a_level.is_case_insensitive_equal (info_str) then
level := log_information
elseif a_level.is_case_insensitive_equal (debug_str) then
level := log_debug
else
level := 0
end
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)"
end

View File

@@ -0,0 +1,54 @@
note
description: "Object handling error information"
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision: "$Revision: 95678 $"
class
BASIC_ERROR_HANDLER
create
make
feature -- Initialization
make (a_error_message: READABLE_STRING_32; a_error_location: READABLE_STRING_32)
-- Create an object error, set `error_message' to `a_error_message'
-- set `error_location' to `a_error_location'.
do
set_error_message (a_error_message)
set_error_location (a_error_location)
ensure
error_message_set: error_message = a_error_message
error_location_set: error_location = a_error_location
end
feature -- Access
error_message: READABLE_STRING_32
-- Message.
error_location: READABLE_STRING_32
-- Code to represent an error.
feature -- Change Element
set_error_message (a_message: like error_message)
-- Set error_message with `a_message'.
do
error_message := a_message
ensure
message_set: error_message = a_message
end
set_error_location (a_location: READABLE_STRING_32)
-- Set error_location with `a_location'.
do
error_location := a_location
ensure
error_location_set: error_location = a_location
end
note
copyright: "2011-2014, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,108 @@
note
description: "Provides error information"
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision: "$Revision: 95678 $"
class
SHARED_ERROR
inherit
SHARED_LOGGER
feature -- Access
last_error: detachable BASIC_ERROR_HANDLER
-- Object represent last error.
last_error_message: READABLE_STRING_32
-- Last error string representation.
do
if attached last_error as ll_error then
Result := ll_error.error_message
else
Result := ""
end
end
feature -- Status Report
successful: BOOLEAN
-- Was last operation successful?
-- If not, `last_error' must be set.
feature -- Element Settings
set_last_error_from_exception (a_location: STRING)
-- Initialize instance from last exception.
-- Don't show too much internal details (e.g. stack trace).
-- We really don't want this to fail since it is called from rescue clauses.
require
attached_location: a_location /= Void
local
l_exceptions: EXCEPTIONS
l_message: STRING
l_tag: detachable STRING
l_retried: BOOLEAN
do
if not l_retried then
create l_exceptions
create l_message.make (256)
l_tag := l_exceptions.tag_name
if l_tag /= Void then
l_message.append ("The following exception was raised: ")
l_message.append (l_tag)
else
l_message.append ("An unknown exception was raised.")
end
set_last_error (l_message, a_location)
write_critical_log (generator + ".set_last_error_from_exception " + l_message)
else
set_last_error ("Generic error", "")
write_critical_log (generator + ".set_last_error_from_exception Generic Error")
end
rescue
l_retried := True
retry
end
set_last_error (a_message, a_location: STRING)
-- Set `last_error_message' with `a_message',
-- `last_error_location' with `a_location' and
-- `successful' to `False'.
require
attached_message: a_message /= Void
attached_location: a_location /= Void
do
create last_error.make (a_message, a_location)
write_critical_log (generator + ".set_last_error " + a_message)
successful := False
ensure
last_error_set: attached last_error
failed: not successful
end
set_last_error_from_handler (a_error: detachable BASIC_ERROR_HANDLER)
-- Set `last_error' with `a_error'.
do
last_error := a_error
successful := False
ensure
last_error_set: attached last_error
failed: not successful
end
set_successful
-- Reset `last_error_message' and `last_error_location' and
-- set `successful' to `True'.
do
last_error := Void
successful := True
ensure
last_error__reset: last_error = Void
successful: successful
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)"
end

View File

@@ -0,0 +1,188 @@
note
description: "Object to log messages for a specific application. "
date: "$Date$"
revision: "$Revision$"
class
LOGGER
inherit
ANY
LOG_PRIORITY_CONSTANTS
export
{NONE} all
end
SHARED_EXECUTION_ENVIRONMENT
export
{NONE} all
end
create
make,
make_with_environment,
make_with_layout
feature {NONE} -- Initialization
make
-- Initialize a logger object.
do
create log.make
end
make_with_environment (app: APPLICATION_ENVIRONMENT)
-- Initialize a logger object with an application environment `app'.
do
make
apply_environment (app)
end
make_with_layout (app: APPLICATION_ENVIRONMENT)
-- Initialize a logger object with an application layout `app'.
obsolete
"Use make_with_environment"
do
make_with_environment (app)
end
feature -- Change
apply_environment (app: APPLICATION_ENVIRONMENT)
do
initialize_logger (app, log)
end
feature {NONE} -- Internal
log: LOGGING_FACILITY
feature -- Logging
put_information (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at information level.
do
log.write_information (create {STRING}.make_from_separate (a_message))
end
put_error (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at error level.
do
log.write_error (create {STRING}.make_from_separate (a_message))
end
put_warning (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at warning level.
do
log.write_warning (create {STRING}.make_from_separate (a_message))
end
put_critical (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at critical level.
do
log.write_critical (create {STRING}.make_from_separate (a_message))
end
put_alert (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at alert level.
do
log.write_alert (create {STRING}.make_from_separate (a_message))
end
put_debug (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at debug level.
do
log.write_debug (create {STRING}.make_from_separate (a_message))
end
feature {NONE} -- Implementation
initialize_logger (app: APPLICATION_ENVIRONMENT; a_log: like log)
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)
a_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
a_log_writer.enable_debug_log_level
elseif a_priority = Log_emergency then
a_log_writer.enable_emergency_log_level
elseif a_priority = Log_alert then
a_log_writer.enable_alert_log_level
elseif a_priority = Log_critical then
a_log_writer.enable_critical_log_level
elseif a_priority = Log_error then
a_log_writer.enable_error_log_level
elseif a_priority = Log_warning then
a_log_writer.enable_warning_log_level
elseif a_priority = Log_notice then
a_log_writer.enable_notice_log_level
elseif a_priority = Log_information then
a_log_writer.enable_information_log_level
else
a_log_writer.enable_unkno_log_level
end
end
new_logger_level_configuration (a_path: PATH): LOGGER_CONFIGURATION
-- Retrieve a new logger level configuration.
-- By default, level is set to `DEBUG'.
local
l_parser: JSON_PARSER
ut: FILE_UTILITIES
do
create Result
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
attached l_parser.parsed_json_object as jv and then
attached {JSON_OBJECT} jv.item ("logger") as l_logger
then
if attached {JSON_STRING} l_logger.item ("location") as l_location then
Result.set_location_with_string (l_location.item)
end
if attached {JSON_STRING} l_logger.item ("backup_count") as l_count then
if l_count.item.is_natural then
Result.set_backup_count (l_count.item.to_natural)
end
end
if attached {JSON_STRING} l_logger.item ("level") as l_level then
Result.set_level (l_level.item)
end
end
end
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)"
end

View File

@@ -0,0 +1,139 @@
note
description: "Wrapper class providing synchronize logging access."
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision: "$Revision: 95678 $"
class
LOGGING_FACILITY
create
make
feature -- Initialization
make
do
create logging.make
end
feature -- Access
logging: LOG_LOGGING_FACILITY
register_log_writer (a_log_writer: LOG_WRITER)
-- Register the non-default log writer `a_log_writer'.
do
logging.register_log_writer (a_log_writer)
end
feature -- Output
write_alert (msg: STRING)
-- Write `msg' to the log writers as an alert.
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_alert (msg)
end
rescue
l_retry := True
retry
end
write_critical (msg: STRING)
-- Write `msg' to the log writers as an critical
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_critical (msg)
end
rescue
l_retry := True
retry
end
write_debug (msg: STRING)
-- Write `msg' to the log writers as an debug.
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_debug (msg)
end
rescue
l_retry := True
retry
end
write_emergency (msg: STRING)
-- Write `msg' to the log writers as an emergency.
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_emergency (msg)
end
rescue
l_retry := True
retry
end
write_error (msg: STRING)
-- Write `msg' to the log writers as an error.
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_error (msg)
end
rescue
l_retry := True
retry
end
write_information (msg: STRING)
-- Write `msg' to the log writers as an information.
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_information (msg)
end
rescue
l_retry := True
retry
end
write_notice (msg: STRING)
-- Write `msg' to the log writers as an notice.
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_notice (msg)
end
rescue
l_retry := True
retry
end
write_warning (msg: STRING)
-- Write `msg' to the log writers as an warning.
local
l_retry: BOOLEAN
do
if not l_retry then
logging.write_warning (msg)
end
rescue
l_retry := True
retry
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)"
end

View File

@@ -0,0 +1,116 @@
note
description: "Provides logger information"
date: "$Date: 2015-02-05 10:25:53 +0100 (jeu., 05 févr. 2015) $"
revision: "$Revision: 96584 $"
class
SHARED_LOGGER
inherit
LOG_PRIORITY_CONSTANTS
SHARED_EXECUTION_ENVIRONMENT
feature -- Logger
logger: separate LOGGER
-- `log' facility (once per process)
-- that could be shared between threads
-- without reinitializing it.
do
Result := logger_cell_item (logger_cell)
end
logger_cell: separate CELL [separate LOGGER]
once ("PROCESS")
create Result.put (create {separate LOGGER}.make)
end
logger_cell_item (a_cell: like logger_cell): separate LOGGER
do
Result := a_cell.item
end
feature -- Logging
write_debug_log (m: READABLE_STRING_8)
do
write_debug_log_to (m, logger)
end
write_information_log (m: READABLE_STRING_8)
do
write_information_log_to (m, logger)
end
write_warning_log (m: READABLE_STRING_8)
do
write_warning_log_to (m, logger)
end
write_error_log (m: READABLE_STRING_8)
do
write_error_log_to (m, logger)
end
write_critical_log (m: READABLE_STRING_8)
do
write_critical_log_to (m, logger)
end
write_alert_log (m: READABLE_STRING_8)
do
write_alert_log_to (m, logger)
end
feature {NONE} -- Logger: separate implementation
write_debug_log_to (m: READABLE_STRING_8; a_log: like logger)
do
a_log.put_debug (m)
end
write_information_log_to (m: READABLE_STRING_8; a_log: like logger)
do
a_log.put_information (m)
end
write_warning_log_to (m: READABLE_STRING_8; a_log: like logger)
do
a_log.put_warning (m)
end
write_error_log_to (m: READABLE_STRING_8; a_log: like logger)
do
a_log.put_error (m)
end
write_critical_log_to (m: READABLE_STRING_8; a_log: like logger)
do
a_log.put_critical (m)
end
write_alert_log_to (m: READABLE_STRING_8; a_log: like logger)
do
a_log.put_alert (m)
end
feature {NONE} -- Implementation
initialize_logger (app: APPLICATION_ENVIRONMENT)
local
l_logger: LOGGER
do
create l_logger.make_with_environment (app)
set_logger_to (l_logger, logger_cell)
end
set_logger_to (a_logger: separate LOGGER; a_cell: like logger_cell)
do
a_cell.replace (a_logger)
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)"
end