diff --git a/ext/ilios/ilios.c b/ext/ilios/ilios.c index 72bdb64..77b35ab 100644 --- a/ext/ilios/ilios.c +++ b/ext/ilios/ilios.c @@ -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); @@ -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(); diff --git a/sig/ilios.rbs b/sig/ilios.rbs index f9453e8..32a9385 100644 --- a/sig/ilios.rbs +++ b/sig/ilios.rbs @@ -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 diff --git a/test/helper.rb b/test/helper.rb index 6ab89f8..f2fbdb3 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -80,3 +80,5 @@ def verify_gc_compaction prepare_keyspace prepare_table + +Ilios::Cassandra.log_level(Ilios::Cassandra::LOG_TRACE) diff --git a/test/test_cassandra.rb b/test/test_cassandra.rb new file mode 100644 index 0000000..54686f0 --- /dev/null +++ b/test/test_cassandra.rb @@ -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