Updated design related to logger, to prepare move to SCOOP concurrency.
This commit is contained in:
@@ -56,10 +56,10 @@ feature -- Element Settings
|
||||
l_message.append ("An unknown exception was raised.")
|
||||
end
|
||||
set_last_error (l_message, a_location)
|
||||
log.write_critical (generator + ".set_last_error_from_exception " + l_message)
|
||||
write_critical_log (generator + ".set_last_error_from_exception " + l_message)
|
||||
else
|
||||
set_last_error ("Generic error", "")
|
||||
log.write_critical (generator + ".set_last_error_from_exception Generic Error")
|
||||
write_critical_log (generator + ".set_last_error_from_exception Generic Error")
|
||||
end
|
||||
rescue
|
||||
l_retried := True
|
||||
@@ -75,7 +75,7 @@ feature -- Element Settings
|
||||
attached_location: a_location /= Void
|
||||
do
|
||||
create last_error.make (a_message, a_location)
|
||||
log.write_critical (generator + ".set_last_error " + a_message)
|
||||
write_critical_log (generator + ".set_last_error " + a_message)
|
||||
successful := False
|
||||
ensure
|
||||
last_error_set: attached last_error
|
||||
@@ -103,6 +103,6 @@ feature -- Element Settings
|
||||
successful: successful
|
||||
end
|
||||
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
|
||||
|
||||
172
library/layout/src/logger/logger.e
Normal file
172
library/layout/src/logger/logger.e
Normal file
@@ -0,0 +1,172 @@
|
||||
note
|
||||
description: "Summary description for {LOGGER}."
|
||||
author: ""
|
||||
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_layout
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
create log.make
|
||||
end
|
||||
|
||||
make_with_layout (app: APPLICATION_LAYOUT)
|
||||
do
|
||||
make
|
||||
apply_layout (app)
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
apply_layout (app: APPLICATION_LAYOUT)
|
||||
do
|
||||
initialize_logger (app, log)
|
||||
end
|
||||
|
||||
feature {NONE} -- Internal
|
||||
|
||||
log: LOGGING_FACILITY
|
||||
|
||||
feature -- Logging
|
||||
|
||||
put_information (a_message: separate READABLE_STRING_8)
|
||||
do
|
||||
log.write_information (create {STRING}.make_from_separate (a_message))
|
||||
end
|
||||
|
||||
put_error (a_message: separate READABLE_STRING_8)
|
||||
do
|
||||
log.write_error (create {STRING}.make_from_separate (a_message))
|
||||
end
|
||||
|
||||
put_warning (a_message: separate READABLE_STRING_8)
|
||||
do
|
||||
log.write_warning (create {STRING}.make_from_separate (a_message))
|
||||
end
|
||||
|
||||
put_critical (a_message: separate READABLE_STRING_8)
|
||||
do
|
||||
log.write_critical (create {STRING}.make_from_separate (a_message))
|
||||
end
|
||||
|
||||
put_alert (a_message: separate READABLE_STRING_8)
|
||||
do
|
||||
log.write_alert (create {STRING}.make_from_separate (a_message))
|
||||
end
|
||||
|
||||
put_debug (a_message: separate READABLE_STRING_8)
|
||||
do
|
||||
log.write_debug (create {STRING}.make_from_separate (a_message))
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
initialize_logger (app: APPLICATION_LAYOUT; 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
|
||||
@@ -67,7 +67,6 @@ feature -- Output
|
||||
rescue
|
||||
l_retry := True
|
||||
retry
|
||||
|
||||
end
|
||||
|
||||
write_emergency (msg: STRING)
|
||||
@@ -135,6 +134,6 @@ feature -- Output
|
||||
retry
|
||||
end
|
||||
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
|
||||
|
||||
@@ -13,100 +13,103 @@ inherit
|
||||
|
||||
feature -- Logger
|
||||
|
||||
log: LOGGING_FACILITY
|
||||
logger: separate LOGGER
|
||||
-- `log' facility (once per process)
|
||||
-- that could be shared between threads
|
||||
-- without reinitializing it.
|
||||
once ("PROCESS")
|
||||
create Result.make
|
||||
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_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
|
||||
l_logger: LOGGER
|
||||
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)
|
||||
create l_logger.make_with_layout (app)
|
||||
set_logger_to (l_logger, logger_cell)
|
||||
end
|
||||
|
||||
set_logger_level (a_log_writer: LOG_WRITER; a_priority: INTEGER)
|
||||
-- Setup the logger level based on `a_priority'
|
||||
set_logger_to (a_logger: separate LOGGER; a_cell: like logger_cell)
|
||||
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
|
||||
a_cell.replace (a_logger)
|
||||
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)"
|
||||
|
||||
Reference in New Issue
Block a user