<commit_before>require 'systemd/journal/version'
require 'systemd/journal/native'
require 'systemd/journal/flags'
require 'systemd/journal/writable'
require 'systemd/journal/fields'
require 'systemd/journal/navigable'
require 'systemd/journal/filterable'
require 'systemd/journal/waitable'
require 'systemd/journal_error'
require 'systemd/journal_entry'
require 'systemd/id128'
require 'systemd/ffi_size_t'
require 'systemd'

module Systemd
  # Class to allow interacting with the systemd journal.
  # To read from the journal, instantiate a new {Systemd::Journal}; to write to
  # the journal, use
  # {Systemd::Journal::Writable::ClassMethods#message Journal.message} or
  # {Systemd::Journal::Writable::ClassMethods#print Journal.print}.
  class Journal
    include Enumerable
    include Systemd::Journal::Writable
    include Systemd::Journal::Navigable
    include Systemd::Journal::Filterable
    include Systemd::Journal::Waitable

    # Returns a new instance of a Journal, opened with the provided options.
    # @param [Hash] opts optional initialization parameters.
    # @option opts [Integer] :flags a set of bitwise OR-ed
    #   {Systemd::Journal::Flags} which control what journal files are opened.
    #   Defaults to `0`, meaning all journals avaiable to the current user.
    # @option opts [String] :path if provided, open the journal files living
    #   in the provided directory only.  Any provided flags will be ignored
    #   since sd_journal_open_directory does not currently accept any flags.
    # @option opts [Array] :files if provided, open the provided journal files
    #   only.  Any provided flags will be ignored since sd_journal_open_files
    #   does not currently accept any flags.
    # @option opts [String] :container if provided, open the journal files from
    #   the container with the provided machine name only.
    # @example Read only system journal entries
    #   j = Systemd::Journal.new(flags: Systemd::Journal::Flags::SYSTEM_ONLY)
    # @example Directly open a journal directory
    #   j = Systemd::Journal.new(
    #     path: '/var/log/journal/5f5777e46c5f4131bd9b71cbed6b9abf'
    #   )
    def initialize(opts = {})
      open_type, flags = validate_options!(opts)
      ptr = FFI::MemoryPointer.new(:pointer, 1)

      @finalize = (flags.key?(:finalize) ? flags.delete(:finalize) : true)
      rc = open_journal(open_type, ptr, opts, flags)
      raise JournalError, rc if rc < 0

      @ptr = ptr.read_pointer
      file_descriptor<commit_msg>finalize needs to be removed from options and not flags<commit_after>require 'systemd/journal/version'
require 'systemd/journal/native'
require 'systemd/journal/flags'
require 'systemd/journal/writable'
require 'systemd/journal/fields'
require 'systemd/journal/navigable'
require 'systemd/journal/filterable'
require 'systemd/journal/waitable'
require 'systemd/journal_error'
require 'systemd/journal_entry'
require 'systemd/id128'
require 'systemd/ffi_size_t'
require 'systemd'

module Systemd
  # Class to allow interacting with the systemd journal.
  # To read from the journal, instantiate a new {Systemd::Journal}; to write to
  # the journal, use
  # {Systemd::Journal::Writable::ClassMethods#message Journal.message} or
  # {Systemd::Journal::Writable::ClassMethods#print Journal.print}.
  class Journal
    include Enumerable
    include Systemd::Journal::Writable
    include Systemd::Journal::Navigable
    include Systemd::Journal::Filterable
    include Systemd::Journal::Waitable

    # Returns a new instance of a Journal, opened with the provided options.
    # @param [Hash] opts optional initialization parameters.
    # @option opts [Integer] :flags a set of bitwise OR-ed
    #   {Systemd::Journal::Flags} which control what journal files are opened.
    #   Defaults to `0`, meaning all journals avaiable to the current user.
    # @option opts [String] :path if provided, open the journal files living
    #   in the provided directory only.  Any provided flags will be ignored
    #   since sd_journal_open_directory does not currently accept any flags.
    # @option opts [Array] :files if provided, open the provided journal files
    #   only.  Any provided flags will be ignored since sd_journal_open_files
    #   does not currently accept any flags.
    # @option opts [String] :container if provided, open the journal files from
    #   the container with the provided machine name only.
    # @example Read only system journal entries
    #   j = Systemd::Journal.new(flags: Systemd::Journal::Flags::SYSTEM_ONLY)
    # @example Directly open a journal directory
    #   j = Systemd::Journal.new(
    #     path: '/var/log/journal/5f5777e46c5f4131bd9b71cbed6b9abf'
    #   )
    def initialize(opts = {})
      open_type, flags = validate_options!(opts)
      ptr = FFI::MemoryPointer.new(:pointer, 1)

      @finalize = (opts.key?(:finalize) ? opts.delete(:finalize) : true)
      rc = open_journal(open_type, ptr, opts, flags)
      raise JournalError, rc if rc < 0

      @ptr = ptr.read_pointer
      file_descriptor
{'fraction_non_alphanumeric': 0.09173586397785687, 'fraction_numerical': 0.009094503756425464, 'mean_word_length': 4.02882703777336, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5683311', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1440, 'n_words': 476}