Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ilios::Cassandra.log_level #13

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_TRACE)
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