Skip to content

Commit

Permalink
Add Ilios::Cassandra.log_level
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Feb 16, 2024
1 parent 6f19280 commit 48a2f42
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ext/ilios/ilios.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ static void ilios_free(void *ptr)
}
}

/**
* Sets the log level.
* Default is +LOG_ERROR+.
*
* @return [Cassandra] self.
*/
static VALUE cassandra_set_log_level(VALUE self, VALUE log_level)
{
cass_log_set_level(NUM2INT(log_level));
return self;
}

void Init_ilios(void)
{
rb_ext_ractor_safe(true);
Expand All @@ -83,6 +95,15 @@ void Init_ilios(void)
id_report_on_exception = rb_intern("report_on_exception=");
sym_unsupported_column_type = ID2SYM(rb_intern("unsupported_column_type"));

rb_define_module_function(mCassandra, "log_level", cassandra_set_log_level, 1);
rb_define_const(mCassandra, "LOG_DISABLED", INT2NUM(CASS_LOG_DISABLED));
rb_define_const(mCassandra, "LOG_CRITICAL", INT2NUM(CASS_LOG_CRITICAL));
rb_define_const(mCassandra, "LOG_ERROR", INT2NUM(CASS_LOG_ERROR));
rb_define_const(mCassandra, "LOG_WARN", INT2NUM(CASS_LOG_WARN));
rb_define_const(mCassandra, "LOG_INFO", INT2NUM(CASS_LOG_INFO));
rb_define_const(mCassandra, "LOG_DEBUG", INT2NUM(CASS_LOG_DEBUG));
rb_define_const(mCassandra, "LOG_TRACE", INT2NUM(CASS_LOG_TRACE));

Init_cluster();
Init_session();
Init_statement();
Expand Down
10 changes: 10 additions & 0 deletions sig/ilios.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ module Ilios
VERSION: String

module Cassandra
LOG_DISABLED: Integer
LOG_CRITICAL: Integer
LOG_ERROR: Integer
LOG_WARN: Integer
LOG_INFO: Integer
LOG_DEBUG: Integer
LOG_TRACE: Integer

def self.log_level: (Integer log_level) -> self

class Cluster
PROTOCOL_VERSION_V1: Integer
PROTOCOL_VERSION_V2: Integer
Expand Down
2 changes: 2 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ def verify_gc_compaction

prepare_keyspace
prepare_table

Ilios::Cassandra.log_level(Ilios::Cassandra::LOG_DEBUG)
12 changes: 12 additions & 0 deletions test/test_cassandra.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require_relative 'helper'

class CassandraTest < Minitest::Test
def test_log_level
assert_raises(TypeError) { Ilios::Cassandra.log_level(Object.new) }

Ilios::Cassandra.log_level(Ilios::Cassandra::LOG_DEBUG)
pass
end
end

0 comments on commit 48a2f42

Please sign in to comment.