Fixed shared logger code (there was an issue on non Windows machine)
Now, it is possible to set logs folder from config file.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
note
|
||||
description: "Object that represents Logger configuration settings"
|
||||
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
|
||||
revision: "$Revision: 95678 $"
|
||||
date: "$Date: 2015-02-03 19:11:23 +0100 (mar., 03 févr. 2015) $"
|
||||
revision: "$Revision: 96575 $"
|
||||
|
||||
class
|
||||
LOGGER_CONFIGURATION
|
||||
@@ -29,6 +29,7 @@ feature -- Initialization
|
||||
do
|
||||
backup_count := 4
|
||||
level := Log_debug
|
||||
location := Void
|
||||
ensure then
|
||||
backup_count_set: backup_count = 4
|
||||
level_set: level = Log_debug
|
||||
@@ -36,6 +37,9 @@ feature -- Initialization
|
||||
|
||||
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'.
|
||||
@@ -46,6 +50,21 @@ feature -- Access
|
||||
|
||||
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
|
||||
@@ -78,6 +97,6 @@ feature -- Element Change
|
||||
end
|
||||
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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
note
|
||||
description: "Provides logger information"
|
||||
date: "$Date: 2015-01-30 19:39:52 +0100 (ven., 30 janv. 2015) $"
|
||||
revision: "$Revision: 96564 $"
|
||||
date: "$Date: 2015-02-03 19:11:23 +0100 (mar., 03 févr. 2015) $"
|
||||
revision: "$Revision: 96575 $"
|
||||
|
||||
class
|
||||
SHARED_LOGGER
|
||||
@@ -28,18 +28,19 @@ feature -- Logger
|
||||
create Result.make
|
||||
create l_environment
|
||||
if attached separate_character_option_value ('d') as l_dir then
|
||||
l_path := create {PATH}.make_from_string (l_dir)
|
||||
create l_log_writer.make_at_location (l_path.extended ("logs").appended ("\api.log"))
|
||||
create l_path.make_from_string (l_dir)
|
||||
else
|
||||
l_path := create {PATH}.make_current
|
||||
create l_log_writer.make_at_location (l_path.extended("api.log"))
|
||||
create l_path.make_current
|
||||
l_path := l_path.extended ("site")
|
||||
end
|
||||
l_log_writer.set_max_file_size ({NATURAL_64}1024*1204)
|
||||
if attached separate_character_option_value ('d') as l_dir then
|
||||
l_logger_config := new_logger_level_configuration (l_path.extended("config").extended ("application_configuration.json"))
|
||||
l_logger_config := new_logger_level_configuration (l_path.extended ("site").extended("config").extended ("application_configuration.json"))
|
||||
if attached l_logger_config.location as p then
|
||||
create l_log_writer.make_at_location (p.appended ("api.log"))
|
||||
else
|
||||
l_logger_config := new_logger_level_configuration (l_path.extended ("site").extended("config").extended ("application_configuration.json"))
|
||||
create l_log_writer.make_at_location (l_path.extended ("logs").appended ("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)
|
||||
@@ -87,12 +88,18 @@ feature {NONE} -- JSON
|
||||
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 and then
|
||||
attached {JSON_STRING} l_logger.item ("backup_count") as l_count and then
|
||||
attached {JSON_STRING} l_logger.item ("level") as l_level then
|
||||
Result.set_level (l_level.item)
|
||||
if l_count.item.is_natural then
|
||||
Result.set_backup_count (l_count.item.to_natural)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user