Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/mod/applications/mod_dptools/mod_dptools.c
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,32 @@ SWITCH_STANDARD_APP(multiunset_function)
}


SWITCH_STANDARD_APP(set_log_tag_function)
{
char *name;
char *value = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session);

if (zstr(data)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No log tag name specified.\n");
return;
}

name = switch_core_session_strdup(session, data);
if ((value = strchr(name, '='))) {
*value++ = '\0';
}

if (zstr(name)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid empty log tag name.\n");
return;
}

if (switch_channel_set_log_tag(channel, name, value) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to update log tag [%s].\n", name);
}
}

SWITCH_STANDARD_APP(log_function)
{
char *level, *log_str;
Expand Down Expand Up @@ -6689,6 +6715,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);
SWITCH_ADD_APP(app_interface, "set", "Set a channel variable", SET_LONG_DESC, set_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);
SWITCH_ADD_APP(app_interface, "set_log_tag", "Set or remove a channel log tag",
"Set a tag with name=value; remove it with name= or name",
set_log_tag_function, "<tagname>[=<value>]",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);

SWITCH_ADD_APP(app_interface, "multiset", "Set many channel variables", SET_LONG_DESC, multiset_function, "[^^<delim>]<varname>=<value> <var2>=<val2>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC);
Expand Down
2 changes: 1 addition & 1 deletion src/mod/loggers/mod_logfile/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include $(top_srcdir)/build/modmake.rulesam
MODNAME=mod_logfile

mod_LTLIBRARIES = mod_logfile.la
mod_logfile_la_SOURCES = mod_logfile.c
mod_logfile_la_SOURCES = mod_logfile.c mod_logfile_prefix.c
mod_logfile_la_CFLAGS = $(AM_CFLAGS)
mod_logfile_la_LIBADD = $(switch_builddir)/libfreeswitch.la
mod_logfile_la_LDFLAGS = -avoid-version -module -no-undefined -shared
73 changes: 73 additions & 0 deletions src/mod/loggers/mod_logfile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# mod_logfile

`mod_logfile` writes selected FreeSWITCH log records to a file. The default
file is `freeswitch.log` in the FreeSWITCH log directory unless `logfile` is
configured.

## Structured prefixes

`uuid`, `log-tags`, and `channel-vars` are emitted in that order and are
prepended to every physical line. `log-tags` defaults to false and
`channel-vars` defaults to empty. `uuid` retains the historical default of
true; set it to false to omit the UUID.

The UUID is emitted as a bare token. Log tags and channel variables are
emitted as `name:value` tokens, with a space after each token. Only available
values produce tokens. For example, an enabled profile can produce:

```text
550e8400-e29b-41d4-a716-446655440000 tenant:acme callid:abc123 message
```

Log tags are captured in the `switch_log_node_t` when the log record is
created, so the captured values travel with a queued log node. The prefix is
then applied to every physical line in that record. Existing message bytes
and final-newline behavior are preserved; `mod_logfile` does not truncate the
message.

## set_log_tag

Use `<action application="set_log_tag" data="tenant=acme"/>` to set or
replace a tag. Use `tenant=` or `tenant` to remove it. Values may contain
additional `=` characters: the input is split at the first `=` only.

Tags are opt-in for the file logger with `log-tags="true"`:

```xml
<param name="log-tags" value="true"/>
```

## Channel variables

`channel-vars="callid=sip_call_id,tenant"` maps `sip_call_id` to `callid`
and uses `tenant` as both label and variable name. Values are read live while
the session exists. Use log tags for stable fields that must survive session
destruction or avoid per-log session lookup.

## Safety limits

Names are limited to 128 bytes and values to 512 bytes. Unsafe name bytes,
whitespace/control bytes in values, and brackets are replaced with `_`.
These limits apply to token names and values, not to the log message:
messages are not limited to 2048 bytes and are not truncated by this module.

## File rotation

`rollover` sets the file-size threshold in bytes; `0` disables size-based
rotation. When `maximum-rotate` is omitted, `max_rot` remains `0` and rotated
files use a timestamp and an index (`logfile.YYYY-MM-DD-HH-MM-SS.N`). A nonzero
`maximum-rotate` value of `N` keeps numbered files up to the configured count
(`logfile.1` through `logfile.N`). If `maximum-rotate` is explicitly `0` (or
parses as zero), it is normalized to `MAX_ROT` (`4096`), so numbered rotation
is kept up to `4096` files.

`rotate-on-hup` controls SIGHUP handling. When true, SIGHUP rotates each
profile; when false, it closes and reopens each file. The sample configuration
enables rotation on HUP and sets a 10 MiB rollover threshold.

## Mappings

Each `<map>` selects log levels for `all`, a source file, a function, or a
`file:function` pair. Its `value` is a comma-separated list of `debug`,
`info`, `notice`, `warning`, `err`, `crit`, `alert`, or `all`. The sample maps
all listed levels for all sources.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<!-- <param name="maximum-rotate" value="32"/> -->
<!-- Prefix all log lines by the session's uuid -->
<param name="uuid" value="true" />
<!-- Include channel log tags captured by switch_log_node_t. -->
<!-- <param name="log-tags" value="true"/> -->
<!-- Add live channel variables as label:value tokens. -->
<!-- <param name="channel-vars" value="callid=sip_call_id,tenant"/> -->
</settings>
<mappings>
<!--
Expand Down
6 changes: 5 additions & 1 deletion src/mod/loggers/mod_logfile/mod_logfile.2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="mod_logfile.c" />
<ClCompile Include="mod_logfile_prefix.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="mod_logfile_prefix.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\w32\Library\FreeSwitchCore.2017.vcxproj">
Expand All @@ -136,4 +140,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
Loading
Loading