Adapted ROC CMS to concurrent EWF.

Revisited the shared logger to reduced number of useless calls.
This commit is contained in:
2015-06-09 19:42:37 +02:00
parent b8cfff487a
commit 5578a9e622
23 changed files with 768 additions and 230 deletions

View File

@@ -30,6 +30,7 @@ feature -- Initialization
backup_count := 4
level := Log_debug
location := Void
type := {STRING_32} "null"
ensure then
backup_count_set: backup_count = 4
level_set: level = Log_debug
@@ -48,6 +49,9 @@ feature -- Access
level: INTEGER
-- Logger level.
type: IMMUTABLE_STRING_32
-- Type of logging.
feature -- Element Change
set_location (a_location: detachable PATH)
@@ -65,6 +69,15 @@ feature -- Element Change
set_location (create {PATH}.make_from_string (a_location))
end
set_type_with_string (a_type: detachable READABLE_STRING_GENERAL)
do
if a_type /= Void and then not a_type.is_whitespace then
create type.make_from_string_general (a_type)
else
create type.make_from_string_general ("null")
end
end
set_backup_count (a_backup: NATURAL)
-- Set backup_count to `a_backup'.
do

View File

@@ -32,7 +32,7 @@ feature {NONE} -- Initialization
create log.make
end
make_with_environment (app: APPLICATION_ENVIRONMENT)
make_with_environment (app: separate APPLICATION_ENVIRONMENT)
-- Initialize a logger object with an application environment `app'.
do
make
@@ -49,7 +49,7 @@ feature {NONE} -- Initialization
feature -- Change
apply_environment (app: APPLICATION_ENVIRONMENT)
apply_environment (app: separate APPLICATION_ENVIRONMENT)
do
initialize_logger (app, log)
end
@@ -58,75 +58,107 @@ feature {NONE} -- Internal
log: LOGGING_FACILITY
feature -- Settings
level: INTEGER
feature -- Logging
put_debug (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at debug level.
do
if level >= log_debug then
log.write_debug (create {STRING}.make_from_separate (a_message))
end
end
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))
if level >= log_information then
log.write_information (create {STRING}.make_from_separate (a_message))
end
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))
if level >= log_warning then
log.write_warning (create {STRING}.make_from_separate (a_message))
end
end
put_error (a_message: separate READABLE_STRING_8)
-- Put message `a_message' to the log at error level.
do
if level >= log_error then
log.write_error (create {STRING}.make_from_separate (a_message))
end
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))
if level >= log_critical then
log.write_critical (create {STRING}.make_from_separate (a_message))
end
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))
if level >= log_alert then
log.write_alert (create {STRING}.make_from_separate (a_message))
end
end
feature {NONE} -- Implementation
initialize_logger (app: APPLICATION_ENVIRONMENT; a_log: like log)
initialize_logger (app: separate APPLICATION_ENVIRONMENT; a_log: like log)
local
l_log_writer_file: LOG_ROLLING_WRITER_FILE
l_log_writer: LOG_WRITER
l_log_writer: detachable LOG_WRITER
l_logs_path: detachable PATH
l_logger_config: LOGGER_CONFIGURATION
ut: FILE_UTILITIES
p: PATH
l_name: IMMUTABLE_STRING_32
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
create l_name.make_from_separate (app.name)
create p.make_from_separate (app.application_config_path)
-- l_name := app.name
-- p := app.application_config_path
l_logger_config := new_logger_level_configuration (p)
if l_logger_config.type.is_case_insensitive_equal_general ("file") then
l_logs_path := l_logger_config.location
if l_logs_path = Void then
create l_logs_path.make_from_separate (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 (l_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 ?
end
elseif l_logger_config.type.is_case_insensitive_equal_general ("stderr") then
create {LOG_WRITER_STDERR} l_log_writer
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 ?
if l_log_writer = Void then
create {LOG_WRITER_NULL} l_log_writer
set_logger_level (l_log_writer, log_notice)
else
set_logger_level (l_log_writer, 0) -- None
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
level := a_priority
if a_priority = log_debug then
a_log_writer.enable_debug_log_level
elseif a_priority = Log_emergency then
@@ -167,6 +199,9 @@ feature {NONE} -- Implementation
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 ("type") as l_type then
Result.set_type_with_string (l_type.item)
end
if attached {JSON_STRING} l_logger.item ("location") as l_location then
Result.set_location_with_string (l_location.item)
end

View File

@@ -35,72 +35,113 @@ feature -- Logging
write_debug_log (m: READABLE_STRING_8)
do
write_debug_log_to (m, logger)
-- write_debug_log_to (m, logger)
end
write_information_log (m: READABLE_STRING_8)
do
write_information_log_to (m, logger)
-- write_information_log_to (m, logger)
end
write_warning_log (m: READABLE_STRING_8)
do
write_warning_log_to (m, logger)
-- write_warning_log_to (m, logger)
end
write_error_log (m: READABLE_STRING_8)
do
write_error_log_to (m, logger)
-- write_error_log_to (m, logger)
end
write_critical_log (m: READABLE_STRING_8)
do
write_critical_log_to (m, logger)
-- write_critical_log_to (m, logger)
end
write_alert_log (m: READABLE_STRING_8)
do
write_alert_log_to (m, logger)
-- write_alert_log_to (m, logger)
end
feature {NONE} -- Logger: separate implementation
write_debug_log_to (m: READABLE_STRING_8; a_log: like logger)
local
retried: BOOLEAN
do
a_log.put_debug (m)
if not retried then
a_log.put_debug (m)
end
rescue
retried := True
retry
end
write_information_log_to (m: READABLE_STRING_8; a_log: like logger)
local
retried: BOOLEAN
do
a_log.put_information (m)
if not retried then
a_log.put_information (m)
end
rescue
retried := True
retry
end
write_warning_log_to (m: READABLE_STRING_8; a_log: like logger)
local
retried: BOOLEAN
do
a_log.put_warning (m)
if not retried then
a_log.put_warning (m)
end
rescue
retried := True
retry
end
write_error_log_to (m: READABLE_STRING_8; a_log: like logger)
local
retried: BOOLEAN
do
a_log.put_error (m)
if not retried then
a_log.put_error (m)
end
rescue
retried := True
retry
end
write_critical_log_to (m: READABLE_STRING_8; a_log: like logger)
local
retried: BOOLEAN
do
a_log.put_critical (m)
if not retried then
a_log.put_critical (m)
end
rescue
retried := True
retry
end
write_alert_log_to (m: READABLE_STRING_8; a_log: like logger)
local
retried: BOOLEAN
do
a_log.put_alert (m)
if not retried then
a_log.put_alert (m)
end
rescue
retried := True
retry
end
feature {NONE} -- Implementation
initialize_logger (app: APPLICATION_ENVIRONMENT)
local
l_logger: LOGGER
l_logger: separate LOGGER
do
create l_logger.make_with_environment (app)
set_logger_to (l_logger, logger_cell)

View File

@@ -32,6 +32,15 @@ feature -- Status report
Result := connection.is_connected
end
feature -- Basic operation
close
-- <Precursor>
-- Disconnect from SQL database.
do
connection.disconnect
end
feature {NONE} -- Implementation
db_handler: DATABASE_HANDLER

View File

@@ -29,15 +29,25 @@ feature -- Factory
storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_SQLITE
local
s: STRING
conn: DATABASE_CONNECTION
conn: detachable DATABASE_CONNECTION
do
if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.environment.application_config_path) as l_database_config then
if
attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.environment.application_config_path) as l_database_config
then
s := "Driver=SQLite3 ODBC Driver;Database="
if attached l_database_config.database_name as db_name then
s.append (db_name)
end
s.append (";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
create {DATABASE_CONNECTION_ODBC} conn.login_with_connection_string (s)
if attached reuseable_connection.item as d then
if s.same_string (d.name) then
conn := d.connection
end
end
if conn = Void or else not conn.is_connected then
create {DATABASE_CONNECTION_ODBC} conn.login_with_connection_string (s)
reuseable_connection.replace ([s, conn])
end
if conn.is_connected then
create Result.make (conn)
set_map_zero_null_value (False) --| This way we map 0 to 0, instead of Null as default.
@@ -50,4 +60,9 @@ feature -- Factory
end
end
reuseable_connection: CELL [detachable TUPLE [name: STRING; connection: DATABASE_CONNECTION]]
once
create Result.put (Void)
end
end