Module: kamailio Branch: master Commit: 32b3a56489412816abc69f0d31b01a3cd5df61d8 URL: https://github.com/kamailio/kamailio/commit/32b3a56489412816abc69f0d31b01a3cd5df61d8
Author: Ben Kaufman <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2026-05-20T11:31:50+02:00 xlog: add auto_newline modparam - GH #4734 New module parameter to auto add new line character --- Modified: src/modules/xlog/doc/xlog_admin.xml Modified: src/modules/xlog/xlog.c --- Diff: https://github.com/kamailio/kamailio/commit/32b3a56489412816abc69f0d31b01a3cd5df61d8.diff Patch: https://github.com/kamailio/kamailio/commit/32b3a56489412816abc69f0d31b01a3cd5df61d8.patch --- diff --git a/src/modules/xlog/doc/xlog_admin.xml b/src/modules/xlog/doc/xlog_admin.xml index c6c3b4d742b..3f194b8982c 100644 --- a/src/modules/xlog/doc/xlog_admin.xml +++ b/src/modules/xlog/doc/xlog_admin.xml @@ -262,6 +262,28 @@ modparam("xlog", "methods_filter", 15) </example> </section> + + <section id="xlog.p.auto_newline"> + <title><varname>auto_newline</varname> (str)</title> + <para> + If set to 1, then all xlog logging functions will automatically append a newline character (<varname>\n</varname>). Any lines that already end in <varname>\n</varname> should not receive an additional newline. + </para> + <para> + <emphasis> + Default value is 0 (no automatic newline). + </emphasis> + </para> + <example> + <title>Set <varname>auto_newline</varname> parameter</title> + <programlisting format="linespecific"> +... +modparam("xlog", "auto_newline", 1) +... + </programlisting> + </example> + </section> + + </section> <section> <title>Functions</title> diff --git a/src/modules/xlog/xlog.c b/src/modules/xlog/xlog.c index fecf02c76d3..c06c8842283 100644 --- a/src/modules/xlog/xlog.c +++ b/src/modules/xlog/xlog.c @@ -72,6 +72,7 @@ static int force_color = 0; static int long_format = 0; static int xlog_facility = DEFAULT_FACILITY; static char *xlog_facility_name = NULL; +static int xlog_auto_newline = 0; /** cfg dynamic parameters */ struct cfg_group_xlog @@ -176,6 +177,7 @@ static param_export_t params[] = { {"log_colors", PARAM_STRING | PARAM_USE_FUNC, (void *)xlog_log_colors_param}, {"methods_filter", PARAM_INT, &xlog_default_cfg.methods_filter}, {"prefix_mode", PARAM_INT, &_xlog_prefix_mode}, + {"auto_newline", PARAM_INT, &xlog_auto_newline}, {0, 0, 0} }; @@ -254,6 +256,13 @@ static inline int xlog_helper( if(xl_print_log(msg, xm->m, _xlog_buf, &txt.len) < 0) return -1; + if(xlog_auto_newline != 0 && txt.len > 0 && txt.s[txt.len - 1] != '\n') { + if(txt.len < buf_size) { + txt.s[txt.len] = '\n'; + txt.len++; + } + } + if(_xlog_prefix_mode) { str _xlog_prefix_str; _xlog_prefix_str.s = _xlog_prefix_buf; _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
