Skip to content
Merged
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
5 changes: 4 additions & 1 deletion doc/admin-guide/files/logging.yaml.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ Name Type Description
====================== =========== =================================================
filename string The name of the logfile relative to the default
logging directory (set with
:ts:cv:`proxy.config.log.logfile_dir`).
:ts:cv:`proxy.config.log.logfile_dir`). If
this is set to ``stdout`` or ``stderr``,
then the stdout or stderr stream will be
logged to, respectively.
format string a string with a valid named format specification.
header string If present, emitted as the first line of each
new log file.
Expand Down
32 changes: 31 additions & 1 deletion doc/admin-guide/files/records.config.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ Network
Local Manager
=============

.. ts:cv:: CONFIG proxy.node.config.manager_log_filename STRING manager.log

The name of the file to which :program:`traffic_manager` logs will be emitted.

If this is set to ``stdout`` or ``stderr``, then all :program:`traffic_manager`
logging will go to the stdout or stderr stream, respectively.


.. ts:cv:: CONFIG proxy.config.admin.user_id STRING nobody

Designates the non-privileged account to run the :program:`traffic_server`
Expand Down Expand Up @@ -3152,6 +3160,8 @@ Logging Configuration
Diagnostic Logging Configuration
================================

.. _DiagnosticOutputConfigurationVariables:

.. ts:cv:: CONFIG proxy.config.diags.output.diag STRING E
.. ts:cv:: CONFIG proxy.config.diags.output.debug STRING E
.. ts:cv:: CONFIG proxy.config.diags.output.status STRING L
Expand All @@ -3173,7 +3183,8 @@ Diagnostic Logging Configuration
``O`` Log to standard output.
``E`` Log to standard error.
``S`` Log to syslog.
``L`` Log to :file:`diags.log`.
``L`` Log to :file:`diags.log` (with the filename configurable via
:ts:cv:`proxy.config.diags.logfile.filename`).
===== ======================================================================

.. topic:: Example
Expand Down Expand Up @@ -3231,6 +3242,25 @@ Diagnostic Logging Configuration
:ts:cv:`log.throttling_interval_msec
<proxy.config.log.proxy.config.log.throttling_interval_msec>`.

.. ts:cv:: CONFIG proxy.config.diags.logfile.filename STRING diags.log

The name of the file to which |TS| diagnostic logs will be emitted. For
information on the diagnostic log file, see :file:`diags.log`. For the
configurable parameters concerning what log content is emitted to
:file:`diags.log`, see the :ref:`Diagnostic Output Configuration Variables
<DiagnosticOutputConfigurationVariables>` above.

If this is set to ``stdout`` or ``stderr``, then all diagnostic logging will
go to the stdout or stderr stream, respectively.

.. ts:cv:: CONFIG proxy.config.error.logfile.filename STRING error.log

The name of the file to which |TS| transaction error logs will be emitted.
For more information on these log messages, see :file:`error.log`.

If this is set to ``stdout`` or ``stderr``, then all transaction error
logging will go to the stdout or stderr stream, respectively.

.. ts:cv:: CONFIG proxy.config.diags.logfile_perm STRING rw-r--r--

The log file permissions. The standard UNIX file permissions are used (owner, group, other). Permissible values are:
Expand Down
7 changes: 7 additions & 0 deletions mgmt/RecordsConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ static const RecordElement RecordsConfig[] =
,
{RECT_CONFIG, "proxy.config.diags.logfile_perm", RECD_STRING, "rw-r--r--", RECU_RESTART_TS, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
,
{RECT_CONFIG, "proxy.config.diags.logfile.filename", RECD_STRING, "diags.log", RECU_DYNAMIC, RR_NULL, RECC_STR, "^[^[:space:]]+$", RECA_NULL}
,
// diags.log rotation, default is 0 (aka rolling turned off) to preserve compatibility
{RECT_CONFIG, "proxy.config.diags.logfile.rolling_enabled", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-2]", RECA_NULL}
,
Expand All @@ -237,6 +239,8 @@ static const RecordElement RecordsConfig[] =
,
{RECT_CONFIG, "proxy.config.diags.logfile.rolling_min_count", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_STR, "^0*[1-9][0-9]*$", RECA_NULL}
,
{RECT_CONFIG, "proxy.config.error.logfile.filename", RECD_STRING, "error.log", RECU_DYNAMIC, RR_NULL, RECC_STR, "^[^[:space:]]+$", RECA_NULL}
,

//##############################################################################
//#
Expand Down Expand Up @@ -1276,6 +1280,9 @@ static const RecordElement RecordsConfig[] =
,
{RECT_CONFIG, "proxy.node.config.manager_retry_cap", RECD_INT, "5", RECU_DYNAMIC, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
,
//# manager: log filename
{RECT_CONFIG, "proxy.node.config.manager_log_filename", RECD_STRING, "manager.log", RECU_DYNAMIC, RR_NULL, RECC_STR, "^[^[:space:]]+$", RECA_NULL}
,

//#
//# SSL parent proxying info
Expand Down
16 changes: 13 additions & 3 deletions proxy/logging/LogConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ LogConfig::setup_default_values()
max_secs_per_buffer = 5;
max_space_mb_for_logs = 100;
max_space_mb_headroom = 10;
error_log_filename = ats_strdup("error.log");
logfile_perm = 0644;
logfile_dir = ats_strdup(".");

Expand Down Expand Up @@ -165,6 +166,12 @@ LogConfig::read_configuration_variables()
hostname = ptr;
}

ptr = REC_ConfigReadString("proxy.config.error.logfile.filename");
if (ptr != nullptr) {
ats_free(error_log_filename);
error_log_filename = ptr;
}

ats_free(logfile_dir);
logfile_dir = ats_stringdup(RecConfigReadLogDir());

Expand Down Expand Up @@ -292,6 +299,7 @@ LogConfig::LogConfig() : m_partition_space_left(static_cast<int64_t>(UINT_MAX))

LogConfig::~LogConfig()
{
ats_free(error_log_filename);
ats_free(logfile_dir);
}

Expand Down Expand Up @@ -321,9 +329,9 @@ LogConfig::init(LogConfig *prev_config)

Debug("log", "creating predefined error log object");

errlog = new LogObject(this, fmt.get(), logfile_dir, "error.log", LOG_FILE_ASCII, nullptr, rolling_enabled, preproc_threads,
rolling_interval_sec, rolling_offset_hr, rolling_size_mb, /* auto_created */ false, rolling_max_count,
rolling_min_count);
errlog = new LogObject(this, fmt.get(), logfile_dir, error_log_filename, LOG_FILE_ASCII, nullptr, rolling_enabled,
preproc_threads, rolling_interval_sec, rolling_offset_hr, rolling_size_mb, /* auto_created */ false,
rolling_max_count, rolling_min_count);

log_object_manager.manage_object(errlog);
errlog->set_fmt_timestamps();
Expand Down Expand Up @@ -367,6 +375,7 @@ LogConfig::display(FILE *fd)
fprintf(fd, " hostname = %s\n", hostname);
fprintf(fd, " logfile_dir = %s\n", logfile_dir);
fprintf(fd, " logfile_perm = 0%o\n", logfile_perm);
fprintf(fd, " error_log_filename = %s\n", error_log_filename);

fprintf(fd, " preproc_threads = %d\n", preproc_threads);
fprintf(fd, " rolling_enabled = %d\n", rolling_enabled);
Expand Down Expand Up @@ -454,6 +463,7 @@ LogConfig::register_config_callbacks()
"proxy.config.log.max_secs_per_buffer",
"proxy.config.log.max_space_mb_for_logs",
"proxy.config.log.max_space_mb_headroom",
"proxy.config.log.error_log_filename",
"proxy.config.log.logfile_perm",
"proxy.config.log.hostname",
"proxy.config.log.logfile_dir",
Expand Down
5 changes: 3 additions & 2 deletions proxy/logging/LogConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ class LogConfig : public ConfigInfo
int max_line_size;
int logbuffer_max_iobuf_index;

char *hostname;
char *logfile_dir;
char *hostname = nullptr;
char *logfile_dir = nullptr;
char *error_log_filename = nullptr;

private:
bool evaluate_config();
Expand Down
31 changes: 26 additions & 5 deletions proxy/logging/LogObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ LogObject::~LogObject()
//
// This function generates an object filename according to the following rules:
//
// 1.- if no extension is given, add .log for ascii logs, and .blog for
// 1.- 'stdout' and 'stderr' are treated as special strings indicating file
// descriptors for the stdout and stderr streams.
// 2.- if no extension is given, add .log for ascii logs, and .blog for
// binary logs
// 2.- if an extension is given, then do not modify filename and use that
// 3.- if an extension is given, then do not modify filename and use that
// extension regardless of type of log
// 3.- if there is a '.' at the end of the name, then do not add an extension
// 4.- if there is a '.' at the end of the name, then do not add an extension
// and remove the '.'. To have a dot at the end of the filename, specify
// two ('..').
//
Expand All @@ -168,6 +170,18 @@ LogObject::generate_filenames(const char *log_dir, const char *basename, LogFile
{
ink_assert(log_dir && basename);

std::string_view basename_sv{basename};
if (basename_sv == "stdout" || basename_sv == "stderr") {
int buffer_size = basename_sv.length() + 1; // Include the null terminator.

m_filename = static_cast<char *>(ats_malloc(buffer_size));
m_basename = static_cast<char *>(ats_malloc(buffer_size));

strncpy(m_filename, basename, buffer_size);
strncpy(m_basename, basename, buffer_size);
return;
}

int i = -1, len = 0;
char c;
while (c = basename[len], c != 0) {
Expand Down Expand Up @@ -261,6 +275,10 @@ LogObject::set_filter_list(const LogFilterList &list, bool copy)
uint64_t
LogObject::compute_signature(LogFormat *format, char *filename, unsigned int flags)
{
std::string_view filename_sv{filename};
if (filename_sv == "stdout" || filename_sv == "stderr") {
return 0;
}
char *fl = format->fieldlist();
char *ps = format->printf_str();
uint64_t signature = 0;
Expand Down Expand Up @@ -983,14 +1001,17 @@ LogObjectManager::_filename_resolution_abort(const char *filename)
}

bool
LogObjectManager::_has_internal_filename_conflict(const char *filename, LogObjectList &objects)
LogObjectManager::_has_internal_filename_conflict(std::string_view filename, LogObjectList &objects)
{
if (filename == "stdout" || filename == "stderr") {
return false;
}
for (auto &object : objects) {
// an internal conflict exists if two objects request the
// same filename, regardless of the object signatures, since
// two objects writing to the same file would produce a
// log with duplicate entries and non monotonic timestamps
if (strcmp(object->get_full_filename(), filename) == 0) {
if (filename == object->get_full_filename()) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/logging/LogObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class LogObjectManager
ink_mutex *_APImutex; // synchronize access to array of API objects
private:
int _manage_object(LogObject *log_object, bool is_api_object, int maxConflicts);
static bool _has_internal_filename_conflict(const char *filename, LogObjectList &objects);
static bool _has_internal_filename_conflict(std::string_view filename, LogObjectList &objects);
int _solve_filename_conflicts(LogObject *log_obj, int maxConflicts);
int _solve_internal_filename_conflicts(LogObject *log_obj, int maxConflicts, int fileNum = 0);
void _filename_resolution_abort(const char *fname);
Expand Down
16 changes: 12 additions & 4 deletions proxy/shared/DiagsConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ DiagsConfig::DiagsConfig(std::string_view prefix_string, const char *filename, c
bool use_records)
: callbacks_established(false), diags_log(nullptr), _diags(nullptr)
{
char diags_logpath[PATH_NAME_MAX];
ats_scoped_str logpath;

////////////////////////////////////////////////////////////////////
Expand All @@ -275,7 +274,16 @@ DiagsConfig::DiagsConfig(std::string_view prefix_string, const char *filename, c
::exit(1);
}

ink_filepath_make(diags_logpath, sizeof(diags_logpath), logpath, filename);
std::string diags_logpath{filename};
// "stdout" and "stderr" are treated specially by BaseLogFile and are used to
// write to the stdout and stderr streams, respectively. If the caller
// specified these, we don't prepend any path and simply pass those strings
// as such to BaseLogFile.
if (diags_logpath != "stdout" && diags_logpath != "stderr") {
char buf[PATH_NAME_MAX];
ink_filepath_make(buf, sizeof(buf), logpath, filename);
diags_logpath = std::string(buf);
}

// Grab rolling intervals from configuration
// TODO error check these values
Expand All @@ -296,14 +304,14 @@ DiagsConfig::DiagsConfig(std::string_view prefix_string, const char *filename, c
ats_free(output_perm);

// Set up diags, FILE streams are opened in Diags constructor
diags_log = new BaseLogFile(diags_logpath);
diags_log = new BaseLogFile(diags_logpath.c_str());
_diags = new Diags(prefix_string, tags, actions, diags_log, diags_perm_parsed, output_perm_parsed);
::diags = _diags;
_diags->config_roll_diagslog(static_cast<RollingEnabledValues>(diags_log_roll_enable), diags_log_roll_int, diags_log_roll_size);
_diags->config_roll_outputlog(static_cast<RollingEnabledValues>(output_log_roll_enable), output_log_roll_int,
output_log_roll_size);

Status("opened %s", diags_logpath);
Status("opened %s", diags_logpath.c_str());

register_diags_callbacks();

Expand Down
20 changes: 13 additions & 7 deletions src/traffic_manager/traffic_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
limitations under the License.
*/

#include "tscore/ink_platform.h"
#include "tscore/ink_sys_control.h"
#include "tscore/ink_cap.h"
#include "tscore/ink_lockfile.h"
Expand Down Expand Up @@ -62,7 +63,8 @@
#include "tscore/bwf_std_format.h"

#define FD_THROTTLE_HEADROOM (128 + 64) // TODO: consolidate with THROTTLE_FD_HEADROOM
#define DIAGS_LOG_FILENAME "manager.log"
#define DEFAULT_DIAGS_LOG_FILENAME "manager.log"
static char diags_log_filename[PATH_NAME_MAX] = DEFAULT_DIAGS_LOG_FILENAME;

#if ATOMIC_INT_LOCK_FREE != 2
#error "Need lock free std::atomic<int>"
Expand Down Expand Up @@ -131,7 +133,7 @@ rotateLogs()

// Now we can actually roll the logs (if necessary)
if (diags->should_roll_diagslog()) {
mgmt_log("Rotated %s", DIAGS_LOG_FILENAME);
mgmt_log("Rotated %s", diags_log_filename);
}

if (diags->should_roll_outputlog()) {
Expand Down Expand Up @@ -545,7 +547,7 @@ main(int argc, const char **argv)

// Bootstrap the Diags facility so that we can use it while starting
// up the manager
diagsConfig = new DiagsConfig("Manager", DIAGS_LOG_FILENAME, debug_tags, action_tags, false);
diagsConfig = new DiagsConfig("Manager", DEFAULT_DIAGS_LOG_FILENAME, debug_tags, action_tags, false);
diags->set_std_output(StdStream::STDOUT, bind_stdout);
diags->set_std_output(StdStream::STDERR, bind_stderr);

Expand Down Expand Up @@ -591,8 +593,12 @@ main(int argc, const char **argv)

// INKqa11968: need to set up callbacks and diags data structures
// using configuration in records.config
REC_ReadConfigString(diags_log_filename, "proxy.node.config.manager_log_filename", sizeof(diags_log_filename));
if (strnlen(diags_log_filename, sizeof(diags_log_filename)) == 0) {
strncpy(diags_log_filename, DEFAULT_DIAGS_LOG_FILENAME, sizeof(diags_log_filename));
}
DiagsConfig *old_diagsconfig = diagsConfig;
diagsConfig = new DiagsConfig("Manager", DIAGS_LOG_FILENAME, debug_tags, action_tags, true);
diagsConfig = new DiagsConfig("Manager", diags_log_filename, debug_tags, action_tags, true);
if (old_diagsconfig) {
delete old_diagsconfig;
old_diagsconfig = nullptr;
Expand Down Expand Up @@ -731,7 +737,7 @@ main(int argc, const char **argv)
lmgmt->processEventQueue();
lmgmt->pollMgmtProcessServer();

// Handle rotation of output log (aka traffic.out) as well as DIAGS_LOG_FILENAME (aka manager.log)
// Handle rotation of output log (aka traffic.out) as well as DEFAULT_DIAGS_LOG_FILENAME (aka manager.log)
rotateLogs();

// Check for a SIGHUP
Expand Down Expand Up @@ -937,9 +943,9 @@ SignalHandler(int sig)
diags->set_std_output(StdStream::STDOUT, bind_stdout);
diags->set_std_output(StdStream::STDERR, bind_stderr);
if (diags->reseat_diagslog()) {
Note("Reseated %s", DIAGS_LOG_FILENAME);
Note("Reseated %s", diags_log_filename);
} else {
Note("Could not reseat %s", DIAGS_LOG_FILENAME);
Note("Could not reseat %s", diags_log_filename);
}
return;
}
Expand Down
Loading