]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Allow setting format of log filename in format_cdr
authorTravis Cross <tc@traviscross.com>
Wed, 25 Jun 2014 22:17:24 +0000 (22:17 +0000)
committerTravis Cross <tc@traviscross.com>
Wed, 25 Jun 2014 23:22:34 +0000 (23:22 +0000)
This commit allows you to set a `log-file` string parameter in a
format_cdr profile.  This string is a template that may (and should!)
contain variables.  This template will be expanded and used as the
file name of the CDR to be written.  This parameter should contain
only the template for the file name itself; the path is relative to
the `log-dir`.

src/mod/event_handlers/mod_format_cdr/conf/autoload_configs/format_cdr.conf.xml
src/mod/event_handlers/mod_format_cdr/mod_format_cdr.c

index 227bcb47222c8bec6433de43220f5cd8c4eaf36f..3e5cdaf1532ccb76a4c1daf0939ca3107d3688b9 100644 (file)
@@ -29,6 +29,8 @@
     <!-- optional: if not present we do not log every record to disk -->
     <!-- either an absolute path, a relative path assuming ${prefix}/logs or a blank value will default to ${prefix}/logs/format_cdr -->
     <param name="log-dir" value=""/>
+    <!-- template for the filename of the saved CDR -->
+    <!-- <param name="log-file" value="${uuid}.cdr.xml"/> -->
 
     <!-- optional: if not present we do log the b leg -->
     <!-- true or false if we should create a cdr for the b leg of a call-->
index 57d3e1ba562a42030d27105fb4ae3fbb27ba0f03..6852e8d078fe555bdb8a588c18ac73f71f7abb97 100644 (file)
@@ -63,6 +63,7 @@ struct cdr_profile {
        char *log_dir;
        char *err_log_dir[MAX_ERR_DIRS];
        int err_dir_count;
+       char *log_file;
        uint32_t delay;
        uint32_t retries;
        uint32_t enable_cacert_check;
@@ -198,6 +199,7 @@ static switch_status_t my_on_reporting_cb(switch_core_session_t *session, cdr_pr
        switch_xml_t xml_cdr = NULL;
        cJSON *json_cdr = NULL;
        char *cdr_text = NULL;
+       char *lfile = NULL;
        char *dpath = NULL;
        char *path = NULL;
        char *curl_cdr_text = NULL;
@@ -265,9 +267,14 @@ static switch_status_t my_on_reporting_cb(switch_core_session_t *session, cdr_pr
        }
 
        if (!zstr(logdir) && (profile->log_http_and_disk || !profile->url_count)) {
+               if (profile->log_file) {
+                       lfile = switch_channel_expand_variables(channel, profile->log_file);
+               } else {
+                       lfile = switch_mprintf("%s%s.cdr.%s", a_prefix, switch_core_session_get_uuid(session), profile->format);
+               }
                dpath = switch_mprintf("%s%s%s", logdir, SWITCH_PATH_SEPARATOR, a_prefix);
-               path = switch_mprintf("%s%s%s%s.cdr.%s", logdir, SWITCH_PATH_SEPARATOR, a_prefix, switch_core_session_get_uuid(session),
-                       profile->format);
+               path = switch_mprintf("%s%s%s", logdir, SWITCH_PATH_SEPARATOR, lfile);
+               if (lfile != profile->log_file) switch_safe_free(lfile);
                switch_thread_rwlock_unlock(profile->log_path_lock);
                if (path) {
                        if (switch_directory_exists(dpath, profile->pool) != SWITCH_STATUS_SUCCESS) {
@@ -427,9 +434,14 @@ static switch_status_t my_on_reporting_cb(switch_core_session_t *session, cdr_pr
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to post to web server, writing to file\n");
 
                switch_thread_rwlock_rdlock(profile->log_path_lock);
-               dpath = switch_mprintf("%s%s%s", profile->err_log_dir, SWITCH_PATH_SEPARATOR, a_prefix);
-               path = switch_mprintf("%s%s%s%s.cdr.%s", profile->err_log_dir, SWITCH_PATH_SEPARATOR, a_prefix, switch_core_session_get_uuid(session),
-                       profile->format);
+               if (profile->log_file) {
+                       lfile = switch_channel_expand_variables(channel, profile->log_file);
+               } else {
+                       lfile = switch_mprintf("%s%s.cdr.%s", a_prefix, switch_core_session_get_uuid(session), profile->format);
+               }
+               dpath = switch_mprintf("%s%s%s", logdir, SWITCH_PATH_SEPARATOR, a_prefix);
+               path = switch_mprintf("%s%s%s", logdir, SWITCH_PATH_SEPARATOR, lfile);
+               if (lfile != profile->log_file) switch_safe_free(lfile);
                switch_thread_rwlock_unlock(profile->log_path_lock);
                if (path) {
                        if (switch_directory_exists(dpath, profile->pool) != SWITCH_STATUS_SUCCESS) {
@@ -616,6 +628,8 @@ switch_status_t mod_format_cdr_load_profile_xml(switch_xml_t xprofile)
                                profile->retries = switch_atoui(val);
                        } else if (!strcasecmp(var, "rotate") && !zstr(val)) {
                                profile->rotate = switch_true(val);
+                       } else if (!strcasecmp(var, "log-file") && !zstr(val)) {
+                               profile->log_file = switch_core_strdup(profile->pool, val);
                        } else if (!strcasecmp(var, "log-dir")) {
                                if (zstr(val)) {
                                        profile->base_log_dir = switch_core_sprintf(profile->pool, "%s%sformat_cdr", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);