2022-03-31 15:59:19 +00:00
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/**
|
2013-05-03 06:02:03 +00:00
|
|
|
* Copyright (c) 2007-2012, Timothy Stack
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
2013-05-28 04:35:00 +00:00
|
|
|
*
|
2013-05-03 06:02:03 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
2013-05-28 04:35:00 +00:00
|
|
|
*
|
2013-05-03 06:02:03 +00:00
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of Timothy Stack nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2013-05-28 04:35:00 +00:00
|
|
|
*
|
2013-05-03 06:02:03 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2022-03-16 22:38:08 +00:00
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2013-05-03 06:02:03 +00:00
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2009-09-14 01:07:32 +00:00
|
|
|
* @file logfile.hh
|
|
|
|
*/
|
|
|
|
|
2020-08-31 05:13:56 +00:00
|
|
|
#ifndef logfile_hh
|
|
|
|
#define logfile_hh
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
#include <set>
|
2022-03-16 22:38:08 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
#include <stdint.h>
|
2022-03-16 22:38:08 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/resource.h>
|
2011-08-06 16:33:55 +00:00
|
|
|
#include <sys/stat.h>
|
2009-09-14 01:07:32 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2022-06-29 05:23:56 +00:00
|
|
|
#include "ArenaAlloc/arenaalloc.h"
|
2019-05-08 12:30:59 +00:00
|
|
|
#include "base/lnav_log.hh"
|
2019-06-15 13:32:02 +00:00
|
|
|
#include "base/result.h"
|
2022-08-20 03:01:25 +00:00
|
|
|
#include "bookmarks.hh"
|
2013-07-05 16:14:39 +00:00
|
|
|
#include "byte_array.hh"
|
2020-10-21 05:55:46 +00:00
|
|
|
#include "ghc/filesystem.hpp"
|
2022-03-16 22:38:08 +00:00
|
|
|
#include "line_buffer.hh"
|
2020-11-17 18:04:23 +00:00
|
|
|
#include "log_format_fwd.hh"
|
2022-03-16 22:38:08 +00:00
|
|
|
#include "logfile_fwd.hh"
|
2021-05-30 20:33:05 +00:00
|
|
|
#include "safe/safe.h"
|
2022-03-16 22:38:08 +00:00
|
|
|
#include "shared_buffer.hh"
|
|
|
|
#include "text_format.hh"
|
|
|
|
#include "unique_path.hh"
|
2009-09-14 01:07:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Observer interface for logfile indexing progress.
|
|
|
|
*
|
|
|
|
* @see logfile
|
|
|
|
*/
|
|
|
|
class logfile_observer {
|
|
|
|
public:
|
2019-07-25 14:31:46 +00:00
|
|
|
virtual ~logfile_observer() = default;
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2021-05-29 05:53:50 +00:00
|
|
|
enum class indexing_result {
|
|
|
|
CONTINUE,
|
|
|
|
BREAK,
|
|
|
|
};
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/**
|
|
|
|
* @param lf The logfile object that is doing the indexing.
|
|
|
|
* @param off The current offset in the file being processed.
|
|
|
|
* @param total The total size of the file.
|
2021-05-29 05:53:50 +00:00
|
|
|
* @return false
|
2009-09-14 01:07:32 +00:00
|
|
|
*/
|
2021-05-29 05:53:50 +00:00
|
|
|
virtual indexing_result logfile_indexing(const std::shared_ptr<logfile>& lf,
|
|
|
|
file_off_t off,
|
2022-03-16 22:38:08 +00:00
|
|
|
file_size_t total)
|
|
|
|
= 0;
|
2009-09-14 01:07:32 +00:00
|
|
|
};
|
|
|
|
|
2016-03-24 05:14:59 +00:00
|
|
|
struct logfile_activity {
|
2020-10-29 04:18:57 +00:00
|
|
|
int64_t la_polls{0};
|
|
|
|
int64_t la_reads{0};
|
2022-08-11 18:16:49 +00:00
|
|
|
struct rusage la_initial_index_rusage {};
|
2016-03-24 05:14:59 +00:00
|
|
|
};
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/**
|
|
|
|
* Container for the lines in a log file and some metadata.
|
|
|
|
*/
|
2022-03-16 22:38:08 +00:00
|
|
|
class logfile
|
|
|
|
: public unique_path_source
|
|
|
|
, public std::enable_shared_from_this<logfile> {
|
2009-09-14 01:07:32 +00:00
|
|
|
public:
|
2022-06-29 05:23:56 +00:00
|
|
|
using iterator = std::vector<logline>::iterator;
|
|
|
|
using const_iterator = std::vector<logline>::const_iterator;
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-08-29 01:55:32 +00:00
|
|
|
struct metadata {
|
|
|
|
text_format_t m_format;
|
|
|
|
std::string m_value;
|
|
|
|
};
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/**
|
|
|
|
* Construct a logfile with the given arguments.
|
|
|
|
*
|
|
|
|
* @param filename The name of the log file.
|
|
|
|
* @param fd The file descriptor for accessing the file or -1 if the
|
|
|
|
* constructor should open the file specified by 'filename'. The
|
|
|
|
* descriptor needs to be seekable.
|
|
|
|
*/
|
2021-05-29 05:53:50 +00:00
|
|
|
static Result<std::shared_ptr<logfile>, std::string> open(
|
2022-03-16 22:38:08 +00:00
|
|
|
std::string filename, logfile_open_options& loo);
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2020-11-17 18:04:23 +00:00
|
|
|
~logfile() override;
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
const logfile_activity& get_activity() const { return this->lf_activity; }
|
2016-03-24 05:14:59 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
nonstd::optional<ghc::filesystem::path> get_actual_path() const
|
|
|
|
{
|
2021-05-01 15:33:16 +00:00
|
|
|
return this->lf_actual_path;
|
|
|
|
}
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/** @return The filename as given in the constructor. */
|
2022-04-30 20:05:42 +00:00
|
|
|
const std::string& get_filename() const { return this->lf_filename; }
|
2011-08-06 16:33:55 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
/** @return The filename as given in the constructor, excluding the path
|
|
|
|
* prefix. */
|
2022-04-30 20:05:42 +00:00
|
|
|
const std::string& get_basename() const { return this->lf_basename; }
|
2016-11-19 16:54:53 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
int get_fd() const { return this->lf_line_buffer.get_fd(); }
|
2013-10-11 13:22:29 +00:00
|
|
|
|
2012-07-13 16:26:47 +00:00
|
|
|
/** @param filename The new filename for this log file. */
|
2022-04-30 20:05:42 +00:00
|
|
|
void set_filename(const std::string& filename);
|
2012-07-13 16:26:47 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
const std::string& get_content_id() const { return this->lf_content_id; }
|
2013-07-05 16:14:39 +00:00
|
|
|
|
2011-08-06 16:33:55 +00:00
|
|
|
/** @return The inode for this log file. */
|
2022-04-30 20:05:42 +00:00
|
|
|
const struct stat& get_stat() const { return this->lf_stat; }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
size_t get_longest_line_length() const { return this->lf_longest_line; }
|
2015-08-15 03:45:23 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
bool is_compressed() const { return this->lf_line_buffer.is_compressed(); }
|
2014-03-15 11:40:58 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
bool is_valid_filename() const { return this->lf_valid_filename; }
|
2016-03-12 22:12:23 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
file_off_t get_index_size() const { return this->lf_index_size; }
|
2020-10-29 04:21:57 +00:00
|
|
|
|
2022-05-23 03:44:18 +00:00
|
|
|
nonstd::optional<const_iterator> line_for_offset(file_off_t off) const;
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/**
|
|
|
|
* @return The detected format, rebuild_index() must be called before this
|
2010-11-22 05:44:45 +00:00
|
|
|
* will return a value other than NULL.
|
2009-09-14 01:07:32 +00:00
|
|
|
*/
|
2022-04-30 20:05:42 +00:00
|
|
|
std::shared_ptr<log_format> get_format() const { return this->lf_format; }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-07-01 23:02:14 +00:00
|
|
|
log_format* get_format_ptr() const { return this->lf_format.get(); }
|
|
|
|
|
2021-02-25 23:47:36 +00:00
|
|
|
intern_string_t get_format_name() const;
|
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
text_format_t get_text_format() const { return this->lf_text_format; }
|
2017-02-19 06:35:18 +00:00
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/**
|
|
|
|
* @return The last modified time of the file when the file was last
|
|
|
|
* indexed.
|
|
|
|
*/
|
2022-04-30 20:05:42 +00:00
|
|
|
time_t get_modified_time() const { return this->lf_index_time; }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
int get_time_offset_line() const { return this->lf_time_offset_line; }
|
2013-07-14 04:31:59 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
const struct timeval& get_time_offset() const
|
|
|
|
{
|
2013-06-30 23:43:08 +00:00
|
|
|
return this->lf_time_offset;
|
2022-04-30 20:05:42 +00:00
|
|
|
}
|
2013-06-30 23:43:08 +00:00
|
|
|
|
2013-07-14 04:31:59 +00:00
|
|
|
void adjust_content_time(int line,
|
2022-03-16 22:38:08 +00:00
|
|
|
const struct timeval& tv,
|
2022-04-30 20:05:42 +00:00
|
|
|
bool abs_offset = true);
|
2013-06-30 23:43:08 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
void clear_time_offset()
|
|
|
|
{
|
|
|
|
struct timeval tv = {0, 0};
|
2013-06-30 23:43:08 +00:00
|
|
|
|
2013-07-14 04:31:59 +00:00
|
|
|
this->adjust_content_time(-1, tv);
|
2022-04-30 20:05:42 +00:00
|
|
|
}
|
2013-06-30 23:43:08 +00:00
|
|
|
|
2021-05-30 20:33:05 +00:00
|
|
|
void mark_as_duplicate(const std::string& name);
|
2020-10-29 04:23:25 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
const logfile_open_options& get_open_options() const
|
|
|
|
{
|
2021-01-09 06:42:28 +00:00
|
|
|
return this->lf_options;
|
|
|
|
}
|
|
|
|
|
2020-10-29 04:23:25 +00:00
|
|
|
void reset_state();
|
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
bool is_time_adjusted() const
|
|
|
|
{
|
|
|
|
return (this->lf_time_offset.tv_sec != 0
|
|
|
|
|| this->lf_time_offset.tv_usec != 0);
|
2013-06-30 23:43:08 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
iterator begin() { return this->lf_index.begin(); }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
const_iterator begin() const { return this->lf_index.begin(); }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
const_iterator cbegin() const { return this->lf_index.begin(); }
|
2020-11-29 21:20:07 +00:00
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
iterator end() { return this->lf_index.end(); }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
const_iterator end() const { return this->lf_index.end(); }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
const_iterator cend() const { return this->lf_index.end(); }
|
2020-11-29 21:20:07 +00:00
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/** @return The number of lines in the index. */
|
2022-08-11 18:16:49 +00:00
|
|
|
size_t size() const { return this->lf_index.size(); }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
nonstd::optional<const_iterator> find_from_time(
|
|
|
|
const struct timeval& tv) const;
|
2021-04-24 21:38:26 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
logline& operator[](int index) { return this->lf_index[index]; }
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
logline& front() { return this->lf_index.front(); }
|
2020-10-29 04:21:57 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
logline& back() { return this->lf_index.back(); }
|
2018-03-29 14:32:57 +00:00
|
|
|
|
2012-10-29 23:38:58 +00:00
|
|
|
/** @return True if this log file still exists. */
|
2019-07-30 05:18:32 +00:00
|
|
|
bool exists() const;
|
2012-10-29 23:38:58 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
void close() { this->lf_is_closed = true; }
|
2013-07-14 04:31:59 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
bool is_closed() const { return this->lf_is_closed; }
|
2013-07-14 04:31:59 +00:00
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
struct timeval original_line_time(iterator ll);
|
2013-07-14 04:31:59 +00:00
|
|
|
|
2019-06-15 13:32:02 +00:00
|
|
|
Result<shared_buffer_ref, std::string> read_line(iterator ll);
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-05-23 03:44:18 +00:00
|
|
|
Result<std::string, std::string> read_file();
|
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
iterator line_base(iterator ll)
|
|
|
|
{
|
2020-11-17 18:04:23 +00:00
|
|
|
auto retval = ll;
|
2014-02-20 04:23:19 +00:00
|
|
|
|
|
|
|
while (retval != this->begin() && retval->get_sub_offset() != 0) {
|
|
|
|
--retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
2022-04-30 20:05:42 +00:00
|
|
|
}
|
2014-02-20 04:23:19 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
iterator message_start(iterator ll)
|
|
|
|
{
|
2020-11-17 18:04:23 +00:00
|
|
|
auto retval = ll;
|
2015-03-16 16:16:49 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
while (retval != this->begin()
|
|
|
|
&& (retval->get_sub_offset() != 0 || !retval->is_message()))
|
|
|
|
{
|
2015-03-16 16:16:49 +00:00
|
|
|
--retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2022-09-20 03:15:35 +00:00
|
|
|
struct message_length_result {
|
|
|
|
file_ssize_t mlr_length;
|
|
|
|
file_range::metadata mlr_metadata;
|
|
|
|
};
|
|
|
|
|
|
|
|
message_length_result message_byte_length(const_iterator ll,
|
|
|
|
bool include_continues = true);
|
2013-11-06 15:29:20 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
file_range get_file_range(const_iterator ll, bool include_continues = true)
|
|
|
|
{
|
2022-09-20 03:15:35 +00:00
|
|
|
auto mlr = this->message_byte_length(ll, include_continues);
|
|
|
|
|
2022-04-30 20:05:42 +00:00
|
|
|
return {
|
|
|
|
ll->get_offset(),
|
2022-09-20 03:15:35 +00:00
|
|
|
mlr.mlr_length,
|
|
|
|
mlr.mlr_metadata,
|
2022-04-30 20:05:42 +00:00
|
|
|
};
|
2019-06-15 13:32:02 +00:00
|
|
|
}
|
2013-07-31 04:21:28 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
void read_full_message(const_iterator ll,
|
|
|
|
shared_buffer_ref& msg_out,
|
|
|
|
int max_lines = 50);
|
2014-02-01 14:41:11 +00:00
|
|
|
|
2020-12-08 21:24:29 +00:00
|
|
|
Result<shared_buffer_ref, std::string> read_raw_message(const_iterator ll);
|
|
|
|
|
2021-05-30 04:46:48 +00:00
|
|
|
enum class rebuild_result_t {
|
|
|
|
INVALID,
|
|
|
|
NO_NEW_LINES,
|
|
|
|
NEW_LINES,
|
|
|
|
NEW_ORDER,
|
2017-04-23 14:11:21 +00:00
|
|
|
};
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/**
|
|
|
|
* Index any new data in the log file.
|
|
|
|
*
|
|
|
|
* @param lo The observer object that will be called regularly during
|
|
|
|
* indexing.
|
|
|
|
* @return True if any new lines were indexed.
|
|
|
|
*/
|
2022-03-16 22:38:08 +00:00
|
|
|
rebuild_result_t rebuild_index(
|
|
|
|
nonstd::optional<ui_clock::time_point> deadline = nonstd::nullopt);
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2014-10-20 05:16:40 +00:00
|
|
|
void reobserve_from(iterator iter);
|
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
void set_logfile_observer(logfile_observer* lo)
|
|
|
|
{
|
2014-11-03 14:07:36 +00:00
|
|
|
this->lf_logfile_observer = lo;
|
2022-04-30 20:05:42 +00:00
|
|
|
}
|
2014-11-03 14:07:36 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
void set_logline_observer(logline_observer* llo);
|
2013-06-22 20:44:50 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
logline_observer* get_logline_observer() const
|
|
|
|
{
|
2015-03-28 13:30:30 +00:00
|
|
|
return this->lf_logline_observer;
|
2022-04-30 20:05:42 +00:00
|
|
|
}
|
2015-03-28 13:30:30 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
bool operator<(const logfile& rhs) const
|
2009-09-14 01:07:32 +00:00
|
|
|
{
|
2013-05-28 04:35:00 +00:00
|
|
|
bool retval;
|
|
|
|
|
|
|
|
if (this->lf_index.empty()) {
|
|
|
|
retval = true;
|
2022-03-16 22:38:08 +00:00
|
|
|
} else if (rhs.lf_index.empty()) {
|
2013-05-28 04:35:00 +00:00
|
|
|
retval = false;
|
2022-03-16 22:38:08 +00:00
|
|
|
} else {
|
2013-05-28 04:35:00 +00:00
|
|
|
retval = this->lf_index[0].get_time() < rhs.lf_index[0].get_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
2022-04-30 20:05:42 +00:00
|
|
|
}
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-08-11 18:16:49 +00:00
|
|
|
bool is_indexing() const { return this->lf_indexing; }
|
2020-11-25 22:47:39 +00:00
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
/** Check the invariants for this object. */
|
2018-10-17 14:03:33 +00:00
|
|
|
bool invariant()
|
2009-09-14 01:07:32 +00:00
|
|
|
{
|
2018-10-17 14:03:33 +00:00
|
|
|
require(!this->lf_filename.empty());
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2013-05-28 04:35:00 +00:00
|
|
|
return true;
|
2018-04-03 14:36:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 05:55:46 +00:00
|
|
|
ghc::filesystem::path get_path() const override;
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2021-05-30 20:33:05 +00:00
|
|
|
enum class note_type {
|
|
|
|
indexing_disabled,
|
|
|
|
duplicate,
|
2021-05-30 22:07:09 +00:00
|
|
|
not_utf,
|
2021-05-30 20:33:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using note_map = std::map<note_type, std::string>;
|
|
|
|
using safe_notes = safe::Safe<note_map>;
|
|
|
|
|
2022-05-11 04:58:32 +00:00
|
|
|
note_map get_notes() const { return *this->lf_notes.readAccess(); }
|
|
|
|
|
2022-06-11 04:17:02 +00:00
|
|
|
using safe_opid_map = safe::Safe<log_opid_map>;
|
2022-05-11 04:58:32 +00:00
|
|
|
|
|
|
|
safe_opid_map& get_opids() { return this->lf_opids; }
|
2021-05-30 20:33:05 +00:00
|
|
|
|
2022-07-11 04:00:45 +00:00
|
|
|
void quiesce() { this->lf_line_buffer.quiesce(); }
|
|
|
|
|
2022-08-01 21:56:48 +00:00
|
|
|
void enable_cache() { this->lf_line_buffer.enable_cache(); }
|
|
|
|
|
2022-07-28 04:49:14 +00:00
|
|
|
void dump_stats();
|
|
|
|
|
2022-08-20 03:01:25 +00:00
|
|
|
robin_hood::unordered_map<uint32_t, bookmark_metadata>&
|
|
|
|
get_bookmark_metadata()
|
|
|
|
{
|
|
|
|
return this->lf_bookmark_metadata;
|
|
|
|
}
|
|
|
|
|
2022-08-29 01:55:32 +00:00
|
|
|
std::map<std::string, metadata>& get_embedded_metadata()
|
|
|
|
{
|
|
|
|
return this->lf_embedded_metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::map<std::string, metadata>& get_embedded_metadata() const
|
|
|
|
{
|
|
|
|
return this->lf_embedded_metadata;
|
|
|
|
}
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Process a line from the file.
|
|
|
|
*
|
|
|
|
* @param offset The offset of the line in the file.
|
|
|
|
* @param prefix The contents of the line.
|
|
|
|
* @param len The length of the 'prefix' string.
|
|
|
|
*/
|
2022-06-11 04:17:02 +00:00
|
|
|
bool process_prefix(shared_buffer_ref& sbr,
|
|
|
|
const line_info& li,
|
|
|
|
scan_batch_context& sbc);
|
2009-09-14 01:07:32 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
void set_format_base_time(log_format* lf);
|
2014-04-07 05:11:04 +00:00
|
|
|
|
2021-05-29 05:53:50 +00:00
|
|
|
private:
|
2022-03-16 22:38:08 +00:00
|
|
|
logfile(std::string filename, logfile_open_options& loo);
|
2021-05-29 05:53:50 +00:00
|
|
|
|
|
|
|
std::string lf_filename;
|
2016-03-12 22:12:23 +00:00
|
|
|
logfile_open_options lf_options;
|
2016-03-24 05:14:59 +00:00
|
|
|
logfile_activity lf_activity;
|
2022-03-16 22:38:08 +00:00
|
|
|
bool lf_named_file{true};
|
|
|
|
bool lf_valid_filename{true};
|
2021-05-01 15:33:16 +00:00
|
|
|
nonstd::optional<ghc::filesystem::path> lf_actual_path;
|
2016-11-19 16:54:53 +00:00
|
|
|
std::string lf_basename;
|
2013-07-05 16:14:39 +00:00
|
|
|
std::string lf_content_id;
|
2022-08-11 18:16:49 +00:00
|
|
|
struct stat lf_stat {};
|
2020-12-01 19:27:03 +00:00
|
|
|
std::shared_ptr<log_format> lf_format;
|
2022-03-16 22:38:08 +00:00
|
|
|
std::vector<logline> lf_index;
|
|
|
|
time_t lf_index_time{0};
|
|
|
|
file_off_t lf_index_size{0};
|
2018-05-17 14:06:50 +00:00
|
|
|
bool lf_sort_needed{false};
|
2013-05-28 04:35:00 +00:00
|
|
|
line_buffer lf_line_buffer;
|
2018-05-17 14:06:50 +00:00
|
|
|
int lf_time_offset_line{0};
|
2022-03-16 22:38:08 +00:00
|
|
|
struct timeval lf_time_offset {
|
|
|
|
0, 0
|
|
|
|
};
|
2018-05-17 14:06:50 +00:00
|
|
|
bool lf_is_closed{false};
|
2020-11-25 22:47:39 +00:00
|
|
|
bool lf_indexing{true};
|
2018-05-17 14:06:50 +00:00
|
|
|
bool lf_partial_line{false};
|
2022-03-16 22:38:08 +00:00
|
|
|
logline_observer* lf_logline_observer{nullptr};
|
|
|
|
logfile_observer* lf_logfile_observer{nullptr};
|
2018-05-17 14:06:50 +00:00
|
|
|
size_t lf_longest_line{0};
|
2019-06-15 13:32:02 +00:00
|
|
|
text_format_t lf_text_format{text_format_t::TF_UNKNOWN};
|
2018-10-17 14:03:33 +00:00
|
|
|
uint32_t lf_out_of_time_order_count{0};
|
2021-05-30 20:33:05 +00:00
|
|
|
safe_notes lf_notes;
|
2022-05-11 04:58:32 +00:00
|
|
|
safe_opid_map lf_opids;
|
2022-06-29 05:23:56 +00:00
|
|
|
size_t lf_watch_count{0};
|
2022-07-07 17:05:06 +00:00
|
|
|
ArenaAlloc::Alloc<char> lf_allocator{64 * 1024};
|
2022-07-08 05:13:18 +00:00
|
|
|
nonstd::optional<time_t> lf_cached_base_time;
|
|
|
|
nonstd::optional<tm> lf_cached_base_tm;
|
2020-03-11 14:25:39 +00:00
|
|
|
|
2021-02-13 20:41:48 +00:00
|
|
|
nonstd::optional<std::pair<file_off_t, size_t>> lf_next_line_cache;
|
2022-08-11 18:16:49 +00:00
|
|
|
std::set<intern_string_t> lf_mismatched_formats;
|
2022-08-20 03:01:25 +00:00
|
|
|
robin_hood::unordered_map<uint32_t, bookmark_metadata> lf_bookmark_metadata;
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<format_tag_def>> lf_applicable_taggers;
|
2022-08-29 01:55:32 +00:00
|
|
|
std::map<std::string, metadata> lf_embedded_metadata;
|
2009-09-14 01:07:32 +00:00
|
|
|
};
|
2014-10-20 05:16:40 +00:00
|
|
|
|
|
|
|
class logline_observer {
|
|
|
|
public:
|
2019-07-25 14:31:46 +00:00
|
|
|
virtual ~logline_observer() = default;
|
2014-10-20 05:16:40 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
virtual void logline_restart(const logfile& lf, file_size_t rollback_size)
|
|
|
|
= 0;
|
2014-10-20 05:16:40 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
virtual void logline_new_lines(const logfile& lf,
|
|
|
|
logfile::const_iterator ll_begin,
|
|
|
|
logfile::const_iterator ll_end,
|
2023-06-09 15:43:14 +00:00
|
|
|
const shared_buffer_ref& sbr)
|
2022-03-16 22:38:08 +00:00
|
|
|
= 0;
|
2014-10-20 05:16:40 +00:00
|
|
|
|
2022-03-16 22:38:08 +00:00
|
|
|
virtual void logline_eof(const logfile& lf) = 0;
|
2014-10-20 05:16:40 +00:00
|
|
|
};
|
|
|
|
|
2009-09-14 01:07:32 +00:00
|
|
|
#endif
|