Added logs admin viewer.
Added CMS_SETUP.is_debug: BOOLEAN (see cms.ini site.debug setting)
This commit is contained in:
@@ -20,6 +20,9 @@ feature {NONE} -- Initialization
|
||||
do
|
||||
site_location := environment.path
|
||||
|
||||
-- Debug mode.
|
||||
is_debug := attached string_8_item ("site.debug") as l_debug and then l_debug.is_case_insensitive_equal_general ("yes")
|
||||
|
||||
--| Site id, used to identified a site, this could be set to a uuid, or else
|
||||
site_id := string_8_item_or_default ("site.id", "_ROC_CMS_NO_ID_")
|
||||
|
||||
@@ -259,6 +262,11 @@ feature -- Access: Site
|
||||
-- Optional path defining the front page.
|
||||
-- By default "" or "/".
|
||||
|
||||
feature -- Settings
|
||||
|
||||
is_debug: BOOLEAN
|
||||
-- Is debug mode enabled?
|
||||
|
||||
feature -- Query
|
||||
|
||||
text_item (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
|
||||
|
||||
@@ -93,6 +93,14 @@ feature -- Logs
|
||||
do
|
||||
end
|
||||
|
||||
logs (a_category: detachable READABLE_STRING_GENERAL; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_LOG]
|
||||
-- List of recent logs from `a_lower' to `a_lower+a_count'.
|
||||
-- If `a_category' is set, filter to return only associated logs.
|
||||
-- If `a_count' <= 0 then, return all logs.
|
||||
do
|
||||
create {ARRAYED_LIST [CMS_LOG]} Result.make (0)
|
||||
end
|
||||
|
||||
feature -- Custom
|
||||
|
||||
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
|
||||
@@ -128,6 +136,6 @@ feature -- Custom
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -59,6 +59,13 @@ feature -- Logs
|
||||
deferred
|
||||
end
|
||||
|
||||
logs (a_category: detachable READABLE_STRING_GENERAL; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_LOG]
|
||||
-- List of recent logs from `a_lower' to `a_lower+a_count'.
|
||||
-- If `a_category' is set, filter to return only associated logs.
|
||||
-- If `a_count' <= 0 then, return all logs.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Misc
|
||||
|
||||
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
|
||||
@@ -82,6 +89,6 @@ feature -- Misc
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -206,9 +206,94 @@ feature -- Logs
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
logs (a_category: detachable READABLE_STRING_GENERAL; a_lower: INTEGER; a_count: INTEGER): ARRAYED_LIST [CMS_LOG]
|
||||
-- <Precursor>.
|
||||
local
|
||||
l_parameters: detachable STRING_TABLE [detachable ANY]
|
||||
l_sql: READABLE_STRING_8
|
||||
do
|
||||
error_handler.reset
|
||||
create l_parameters.make (3)
|
||||
if a_category /= Void then
|
||||
l_parameters.put (a_category, "category")
|
||||
l_sql := sql_select_categorized_logs
|
||||
else
|
||||
l_sql := sql_select_logs
|
||||
end
|
||||
if a_count > 0 then
|
||||
l_parameters.put (a_lower, "offset")
|
||||
l_parameters.put (a_count, "size")
|
||||
check l_sql.ends_with_general (";") end
|
||||
l_sql := l_sql.substring (1, l_sql.count - 1) -- Remove ';'
|
||||
+ "LIMIT :size OFFSET :offset ;"
|
||||
end
|
||||
|
||||
from
|
||||
if a_count > 0 then
|
||||
create Result.make (a_count)
|
||||
else
|
||||
create Result.make (10)
|
||||
end
|
||||
if l_parameters.is_empty then
|
||||
l_parameters := Void
|
||||
end
|
||||
sql_query (l_sql, l_parameters)
|
||||
sql_start
|
||||
until
|
||||
sql_after
|
||||
loop
|
||||
if attached fetch_log as l_log then
|
||||
Result.force (l_log)
|
||||
end
|
||||
sql_forth
|
||||
end
|
||||
sql_finalize
|
||||
end
|
||||
|
||||
fetch_log: detachable CMS_LOG
|
||||
-- SQL: 1:id, 2:category, 3:level, 4:uid, 5:message, 6:info, 7:link, 8:date
|
||||
local
|
||||
l_cat: detachable READABLE_STRING_8
|
||||
l_mesg: detachable READABLE_STRING_8
|
||||
l_level: INTEGER
|
||||
l_date: detachable DATE_TIME
|
||||
i: INTEGER
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
l_cat := sql_read_string (2)
|
||||
l_mesg := sql_read_string (5)
|
||||
l_level := sql_read_integer_32 (3)
|
||||
l_date := sql_read_date_time (8)
|
||||
|
||||
if l_cat = Void then
|
||||
l_cat := "unknown"
|
||||
end
|
||||
if l_mesg = Void then
|
||||
l_mesg := ""
|
||||
end
|
||||
|
||||
create Result.make (l_cat, l_mesg, l_level, l_date)
|
||||
Result.set_id (sql_read_integer_64 (1))
|
||||
Result.set_info (sql_read_string (6))
|
||||
if attached sql_read_string_32 (7) as l_link_text then
|
||||
-- Format: "[title](location)"
|
||||
i := l_link_text.index_of ('(', 1)
|
||||
if i > 0 then
|
||||
create lnk.make (l_link_text.substring (2, i - 2), l_link_text.substring (i + 1, l_link_text.count - 1))
|
||||
Result.set_link (lnk)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sql_insert_log: STRING = "INSERT INTO logs (category, level, uid, message, info, link, date) VALUES (:category, :level, :uid, :message, :info, :link, :date);"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
sql_select_logs: STRING = "SELECT id, category, level, uid, message, info, link, date FROM logs ORDER by date DESC;"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
sql_select_categorized_logs: STRING = "SELECT id, category, level, uid, message, info, link, date FROM logs WHERE category=:category ORDER by date DESC;"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
feature -- Misc
|
||||
|
||||
set_custom_value (a_name: READABLE_STRING_8; a_value: attached like custom_value; a_type: detachable READABLE_STRING_8)
|
||||
@@ -326,6 +411,6 @@ feature -- Misc
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -170,6 +170,14 @@ feature -- Access
|
||||
storage: CMS_STORAGE
|
||||
-- Default persistence storage.
|
||||
|
||||
feature -- Settings
|
||||
|
||||
is_debug: BOOLEAN
|
||||
-- Is debug mode enabled?
|
||||
do
|
||||
Result := setup.is_debug
|
||||
end
|
||||
|
||||
feature {NONE} -- Access: request
|
||||
|
||||
request: WSF_REQUEST
|
||||
@@ -261,6 +269,14 @@ feature -- Status Report
|
||||
|
||||
feature -- Logging
|
||||
|
||||
logs (a_category: detachable READABLE_STRING_8; a_lower: INTEGER; a_count: INTEGER): LIST [CMS_LOG]
|
||||
-- List of recent logs from `a_lower' to `a_lower+a_count'.
|
||||
-- If `a_category' is set, filter to return only associated logs.
|
||||
-- If `a_count' <= 0 then, return all logs.
|
||||
do
|
||||
Result := storage.logs (a_category, a_lower, a_count)
|
||||
end
|
||||
|
||||
log (a_category: READABLE_STRING_8; a_message: READABLE_STRING_8; a_level: INTEGER; a_link: detachable CMS_LINK)
|
||||
local
|
||||
l_log: CMS_LOG
|
||||
@@ -674,11 +690,16 @@ feature -- Environment/ module
|
||||
create {INI_CONFIG} Result.make_from_file (l_path)
|
||||
end
|
||||
end
|
||||
if Result = Void and a_name /= Void then
|
||||
-- Use sub config from default?
|
||||
if attached {CONFIG_READER} module_configuration_by_name_in_location (a_module_name, a_dir, Void) as cfg then
|
||||
if Result = Void then
|
||||
if
|
||||
a_name /= Void and then
|
||||
attached {CONFIG_READER} module_configuration_by_name_in_location (a_module_name, a_dir, Void) as cfg
|
||||
then
|
||||
-- Use sub config from default.
|
||||
Result := cfg.sub_config (a_name)
|
||||
end
|
||||
elseif Result.has_error then
|
||||
log ("modules", "module configuration has error %"" + p.utf_8_name + "%"", {CMS_LOG}.level_error, Void)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,9 +3,12 @@ note
|
||||
date: "$Date: 2015-02-13 14:54:27 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96620 $"
|
||||
|
||||
deferred class
|
||||
class
|
||||
CMS_MODULE_API
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_api: CMS_API)
|
||||
@@ -67,6 +70,6 @@ feature -- Bridge to CMS API
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
|
||||
@@ -992,6 +992,13 @@ feature -- Message
|
||||
m.append (a_msg + "</li>")
|
||||
end
|
||||
|
||||
add_debug_message (a_msg: READABLE_STRING_8)
|
||||
do
|
||||
if api.is_debug_enabled then
|
||||
add_message (a_msg, "debug")
|
||||
end
|
||||
end
|
||||
|
||||
add_notice_message (a_msg: READABLE_STRING_8)
|
||||
do
|
||||
add_message (a_msg, "notice")
|
||||
|
||||
Reference in New Issue
Block a user