Logger: Add manager command 'LoggerRotate' to rotate logger
authorJonathan Rose <jrose@digium.com>
Fri, 20 Jun 2014 20:29:45 +0000 (20:29 +0000)
committerJonathan Rose <jrose@digium.com>
Fri, 20 Jun 2014 20:29:45 +0000 (20:29 +0000)
Part of a series of AMI command equivalents to existing CLI
commands

Review: https://reviewboard.asterisk.org/r/3651/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416848 65c4cc65-6c06-0410-ace0-fbb531ad65f3

CHANGES
include/asterisk/logger.h
main/logger.c
main/manager.c

diff --git a/CHANGES b/CHANGES
index c3774fa..176c038 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,9 @@ AMI
    res_manager_presence_state.so. If the high frequency of these events is
    problematic for you, do not load these modules.
 
+ * New AMI action LoggerRotate reloads and rotates logger in the same manner
+   as CLI command 'logger rotate'
+
 chan_dahdi
 ------------------
  * SS7 support now requires libss7 v2.0 or later.
index bd9c9c7..e105683 100644 (file)
@@ -88,6 +88,9 @@ void ast_log_backtrace(void);
 /*! \brief Reload logger without rotating log files */
 int logger_reload(void);
 
+/*! \brief Reload logger while rotating log files */
+int ast_logger_rotate(void);
+
 void __attribute__((format(printf, 5, 6))) ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...);
 
 /*!
index c58b97c..86cd0d4 100644 (file)
@@ -928,6 +928,11 @@ static char *handle_logger_rotate(struct ast_cli_entry *e, int cmd, struct ast_c
        return CLI_SUCCESS;
 }
 
+int ast_logger_rotate()
+{
+       return reload_logger(1, NULL);
+}
+
 static char *handle_logger_set_level(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
        int x;
index 6e056a1..253517d 100644 (file)
@@ -802,6 +802,17 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        <para>List currently defined channels and some information about them.</para>
                </description>
        </manager>
+       <manager name="LoggerRotate" language="en_US">
+               <synopsis>
+                       Reload and rotate the Asterisk logger.
+               </synopsis>
+               <syntax>
+                       <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+               </syntax>
+               <description>
+                       <para>Reload and rotate the logger. Analogous to the CLI command 'logger rotate'.</para>
+               </description>
+       </manager>
        <manager name="ModuleLoad" language="en_US">
                <synopsis>
                        Module management.
@@ -5444,6 +5455,19 @@ static int action_coreshowchannels(struct mansession *s, const struct message *m
        return 0;
 }
 
+/*! \brief  Manager command "LoggerRotate" - reloads and rotates the logger in
+ *          the same manner as the CLI command 'logger rotate'. */
+static int action_loggerrotate(struct mansession *s, const struct message *m)
+{
+       if (ast_logger_rotate()) {
+               astman_send_error(s, m, "Failed to reload the logger and rotate log files");
+               return 0;
+       }
+
+       astman_send_ack(s, m, "Reloaded the logger and rotated log files");
+       return 0;
+}
+
 /*! \brief Manager function to check if module is loaded */
 static int manager_modulecheck(struct mansession *s, const struct message *m)
 {
@@ -7930,6 +7954,7 @@ static void manager_shutdown(void)
        ast_manager_unregister("CoreSettings");
        ast_manager_unregister("CoreStatus");
        ast_manager_unregister("Reload");
+       ast_manager_unregister("LoggerRotate");
        ast_manager_unregister("CoreShowChannels");
        ast_manager_unregister("ModuleLoad");
        ast_manager_unregister("ModuleCheck");
@@ -8126,6 +8151,7 @@ static int __init_manager(int reload, int by_external_config)
                ast_manager_register_xml_core("CoreSettings", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, action_coresettings);
                ast_manager_register_xml_core("CoreStatus", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, action_corestatus);
                ast_manager_register_xml_core("Reload", EVENT_FLAG_CONFIG | EVENT_FLAG_SYSTEM, action_reload);
+               ast_manager_register_xml_core("LoggerRotate", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, action_loggerrotate);
                ast_manager_register_xml_core("CoreShowChannels", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, action_coreshowchannels);
                ast_manager_register_xml_core("ModuleLoad", EVENT_FLAG_SYSTEM, manager_moduleload);
                ast_manager_register_xml_core("ModuleCheck", EVENT_FLAG_SYSTEM, manager_modulecheck);