Github user danobi commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/274#discussion_r36781403 --- Diff: lib/ts/BaseLogFile.cc --- @@ -0,0 +1,571 @@ +/** @file + + Base class for log files implementation + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "BaseLogFile.h" + +/* + * This consturctor creates a BaseLogFile based on a given name. + * This is the most common way BaseLogFiles are created. + */ +BaseLogFile::BaseLogFile(const char *name) + : m_name(ats_strdup(name)), m_hostname(NULL), m_is_regfile(false), m_has_signature(false), m_signature(0), m_is_init(false) +{ + m_fp = NULL; + m_start_time = time(0); + m_end_time = 0L; + m_bytes_written = 0; + m_meta_info = NULL; + + log_log_trace("exiting BaseLogFile constructor, m_name=%s, this=%p\n", m_name, this); +} + +/* + * This consturctor creates a BaseLogFile based on a given name. + * Similar to above constructor, but is overloaded with the object signature + */ +BaseLogFile::BaseLogFile(const char *name, uint64_t sig) + : m_name(ats_strdup(name)), m_hostname(NULL), m_is_regfile(false), m_has_signature(true), m_signature(sig), m_is_init(false) +{ + m_fp = NULL; + m_start_time = time(0); + m_end_time = 0L; + m_bytes_written = 0; + m_meta_info = NULL; + + log_log_trace("exiting BaseLogFile constructor, m_name=%s, this=%p\n", m_name, this); +} + +/* + * This copy constructor creates a BaseLogFile based on a given copy. + */ +BaseLogFile::BaseLogFile(const BaseLogFile ©) + : m_fp(NULL), m_start_time(copy.m_start_time), m_end_time(0L), m_bytes_written(0), m_name(ats_strdup(copy.m_name)), + m_hostname(ats_strdup(m_hostname)), m_is_regfile(false), m_has_signature(copy.m_has_signature), m_signature(copy.m_signature), + m_is_init(copy.m_is_init), m_meta_info(NULL) +{ + log_log_trace("exiting BaseLogFile copy constructor, m_name=%s, this=%p\n", m_name, this); +} + +/* + * Destructor. + */ +BaseLogFile::~BaseLogFile() +{ + log_log_trace("entering BaseLogFile destructor, m_name=%s, this=%p\n", m_name, this); + + if (m_is_regfile) + close_file(); + else + log_log_trace("not a regular file, not closing, m_name=%s, this=%p\n", m_name, this); + if (m_name) + ats_free(m_name); + if (m_hostname) + ats_free(m_hostname); + + log_log_trace("exiting BaseLogFile destructor, this=%p\n", this); +} + +/* + * This function is called by a client of BaseLogFile to roll the underlying + * file The tricky part to this routine is in coming up with the new file name, + * which contains the bounding timestamp interval for the entries + * within the file. + + * Under normal operating conditions, this BaseLogFile object was in existence + * for all writes to the file. In this case, the LogFile members m_start_time + * and m_end_time will have the starting and ending times for the actual + * entries written to the file. + + * On restart situations, it is possible to re-open an existing BaseLogFile, + * which means that the m_start_time variable will be later than the actual + * entries recorded in the file. In this case, we'll use the creation time + * of the file, which should be recorded in the meta-information located on + * disk. + + * If we can't use the meta-file, either because it's not there or because + * it's not valid, then we'll use timestamp 0 (Jan 1, 1970) as the starting + * bound. + + * Return 1 if file rolled, 0 otherwise + */ +int +BaseLogFile::roll(long interval_start, long interval_end) --- End diff -- It was originally like that in LogFile.cc. I assume for reasons related to the `snprintf()` calls later.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---