Module: Couchbase

Defined in:
lib/couchbase/utils.rb,
lib/couchbase/scope.rb,
lib/couchbase/bucket.rb,
lib/couchbase/errors.rb,
lib/couchbase/logger.rb,
lib/couchbase/subdoc.rb,
lib/couchbase/cluster.rb,
lib/couchbase/options.rb,
lib/couchbase/version.rb,
lib/couchbase/collection.rb,
lib/couchbase/management.rb,
lib/couchbase/utils/time.rb,
lib/couchbase/diagnostics.rb,
lib/couchbase/view_options.rb,
lib/couchbase/authenticator.rb,
lib/couchbase/configuration.rb,
lib/couchbase/query_options.rb,
lib/couchbase/datastructures.rb,
lib/couchbase/mutation_state.rb,
lib/couchbase/search_options.rb,
lib/couchbase/config_profiles.rb,
lib/couchbase/json_transcoder.rb,
lib/couchbase/cluster_registry.rb,
lib/couchbase/analytics_options.rb,
lib/couchbase/binary_collection.rb,
lib/couchbase/collection_options.rb,
lib/couchbase/management/user_manager.rb,
lib/couchbase/binary_collection_options.rb,
lib/couchbase/management/bucket_manager.rb,
lib/couchbase/utils/stdlib_logger_adapter.rb,
lib/couchbase/datastructures/couchbase_map.rb,
lib/couchbase/datastructures/couchbase_set.rb,
lib/couchbase/utils/generic_logger_adapter.rb,
lib/couchbase/datastructures/couchbase_list.rb,
lib/couchbase/management/collection_manager.rb,
lib/couchbase/management/view_index_manager.rb,
lib/couchbase/datastructures/couchbase_queue.rb,
lib/couchbase/management/query_index_manager.rb,
lib/couchbase/management/search_index_manager.rb,
lib/couchbase/management/analytics_index_manager.rb,
lib/rails/generators/couchbase/config/config_generator.rb,
lib/couchbase/management/collection_query_index_manager.rb

Overview

Copyright 2020-2021 Couchbase, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Defined Under Namespace

Modules: ConfigProfiles, Datastructures, Error, Generators, Management, Options, Utils Classes: BinaryCollection, Bucket, CertificateAuthenticator, Cluster, ClusterRegistry, Collection, Configuration, DiagnosticsResult, JsonTranscoder, LookupInSpec, MutateInSpec, MutationState, MutationToken, PasswordAuthenticator, PingResult, Scope

Constant Summary collapse

VERSION =

Version of the library and all bundled dependencies

Examples:

Display version (Couchbase::BUILD_INFO contains more details)

$ ruby -rcouchbase -e 'pp Couchbase::VERSION'
{:sdk=>"3.4.0", :ruby_abi=>"3.1.0", :revision=>"416fe68e6029ec8a4c40611cf6e6b30d3b90d20f"}
{}

Class Method Summary collapse

Class Method Details

.log_levelSymbol

Get current log level

Returns:

  • (Symbol)

    current log level



41
42
43
# File 'lib/couchbase/logger.rb', line 41

def self.log_level
  Backend.get_log_level
end

.log_level=(level) ⇒ void

Note:

The level might be also be set with environment variable COUCHBASE_BACKEND_LOG_LEVEL

This method returns an undefined value.

Set log level

Parameters:

  • level (Symbol)

    new log level.

    Allowed levels (in order of decreasing verbosity):

    • :trace

    • :debug

    • :info (default)

    • :warn

    • :error

    • :critical

    • :off



34
35
36
# File 'lib/couchbase/logger.rb', line 34

def self.log_level=(level)
  Backend.set_log_level(level)
end

.loggerObject

Return logger associated with the library



46
47
48
# File 'lib/couchbase/logger.rb', line 46

def self.logger
  @logger # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
end

.set_logger(logger, adapter_class: nil, verbose: false, level: :info) ⇒ Object

Associate logger with the library

The log messages, that are generated by extension might come with out of order timestamps, in order to reduce number of switches between Ruby and Native code.

Examples:

Specify custom logger and limit core messages to debug level

Couchbase.set_logger(Logger.new(STDERR), level: :debug)

Parameters:

  • logger (Logger)

    an object implementing logging interface, e.g. stdlib Logger, or something that responds to “level”-methods like #debug, #error, etc.

  • adapter_class (Class) (defaults to: nil)

    custom implementation of the logger adapter interface between extension and ruby code. See Couchbase::Utils::StdlibLoggerAdapter and Couchbase::Utils::GenericLoggerAdapter

  • verbose (Boolean) (defaults to: false)

    if true, the message will also include source code location, where the message was generated (if available)

  • level (Symbol) (defaults to: :info)

    log level, see log_level= for allowed values

Since:

  • 3.4.0



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/couchbase/logger.rb', line 67

def self.set_logger(logger, adapter_class: nil, verbose: false, level: :info)
  @logger = logger # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
  if @logger.nil? # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
    Backend.install_logger_shim(nil)
    return
  end
  shim =
    if adapter_class
      adapter_class
    elsif logger.is_a?(::Logger)
      require "couchbase/utils/stdlib_logger_adapter"
      Utils::StdlibLoggerAdapter
    else
      require "couchbase/utils/generic_logger_adapter"
      Utils::GenericLoggerAdapter
    end
  Backend.install_logger_shim(shim.new(logger, verbose: verbose), level)
end