From 065399c4441855e88811b1eaa44efb79e3076f78 Mon Sep 17 00:00:00 2001 From: Daniel Zabel Date: Wed, 15 Apr 2015 14:36:31 +0200 Subject: [PATCH] use new uri for logger configuration, create_logger_level now use name and level as params, get_logging_info return key=>value json were key is logger and value is level, update README --- README.md | 4 ++-- lib/nexus_cli/mixins/logging_actions.rb | 32 +++++++++++++++---------- lib/nexus_cli/tasks.rb | 8 +++---- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2617c14..3c84afa 100755 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ nexus-cli get_artifact_info coordinates # nexus-cli get_global_settings # Prints out your Nexus' current setttings and saves them to a file. nexus-cli get_group_repository group_id # Gets information about the given group repository. nexus-cli get_license_info # Returns the license information of the server. -nexus-cli get_logging_info # Gets the log4j Settings of the Nexus server. +nexus-cli get_logging_info # Gets the logger settings of the Nexus server. nexus-cli get_nexus_configuration # Prints out configuration from the .nexus_cli file that helps inform where artifacts will be uploaded. nexus-cli get_nexus_status # Prints out information about the Nexus instance. nexus-cli get_pub_sub repository_id # Returns the publish/subscribe status of the given repository. @@ -69,7 +69,7 @@ nexus-cli remove_from_group_repository group_id repository_to_remove_id # nexus-cli reset_global_settings # Resets your Nexus global_settings to their out-of-the-box defaults. nexus-cli search_artifacts_custom param1 param2 ... # Searches for artifacts using artifact metadata and returns the result as a list with items in XML format. nexus-cli search_for_artifacts # Searches for all the versions of a particular artifact and prints it to the screen. -nexus-cli set_logger_level level # Updates the log4j logging level to a new value. +nexus-cli set_logger_level name level # Updates logging level to [level] for logger [name]. nexus-cli transfer_artifact coordinates from_repository to_repository # Transfers a given artifact from one repository to another. nexus-cli update_artifact_custom_info coordinates param1 param2 ... # Updates the artifact custom metadata with the given key-value pairs. nexus-cli update_user user_id # Updates a user's details. Leave fields blank for them to remain their current values. diff --git a/lib/nexus_cli/mixins/logging_actions.rb b/lib/nexus_cli/mixins/logging_actions.rb index ce8d4c7..040088a 100644 --- a/lib/nexus_cli/mixins/logging_actions.rb +++ b/lib/nexus_cli/mixins/logging_actions.rb @@ -8,25 +8,30 @@ module LoggingActions # # @return [String] a String of JSON representing the current logging levels of Nexus def get_logging_info - response = nexus.get(nexus_url("service/local/log/config"), :header => DEFAULT_ACCEPT_HEADER) + response = nexus.get(nexus_url("service/siesta/logging/loggers"), :header => DEFAULT_ACCEPT_HEADER) case response.status - when 200 - return response.content - else - raise UnexpectedStatusCodeException.new(response.status) + when 200 + data = Hash.new() + JSON.parse(response.content).each do |entry| + data["#{entry['name']}"] = "#{entry['level']}" + end + return JSON.dump(data) + else + raise UnexpectedStatusCodeException.new(response.status) end end # Sets the logging level of Nexus to one of - # "INFO", "DEBUG", or "ERROR". + # "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "OFF" or "DEFAULT". # + # @param name [String] logger to configure # @param level [String] the logging level to set - # + # # @return [Boolean] true if the logging level has been set, false otherwise - def set_logger_level(level) - raise InvalidLoggingLevelException unless ["INFO", "DEBUG", "ERROR"].include?(level.upcase) - response = nexus.put(nexus_url("service/local/log/config"), :body => create_logger_level_json(level), :header => DEFAULT_CONTENT_TYPE_HEADER) + def set_logger_level(name, level) + raise InvalidLoggingLevelException unless %w(TRACE DEBUG INFO WARN ERROR OFF DEFAULT).include?(level.upcase) + response = nexus.post(nexus_url("service/siesta/logging/loggers"), :body => create_logger_level_json(name, level), :header => DEFAULT_CONTENT_TYPE_HEADER) case response.status when 200 return true @@ -37,9 +42,10 @@ def set_logger_level(level) private - def create_logger_level_json(level) - params = {:rootLoggerLevel => level.upcase} - JSON.dump(:data => params) + def create_logger_level_json(name, level) + params = {:name => name} + params[:level] = level.upcase + JSON.dump(params) end end end \ No newline at end of file diff --git a/lib/nexus_cli/tasks.rb b/lib/nexus_cli/tasks.rb index 97dc9d7..7dd76cd 100755 --- a/lib/nexus_cli/tasks.rb +++ b/lib/nexus_cli/tasks.rb @@ -386,10 +386,10 @@ def get_logging_info say nexus_remote.get_logging_info, :green end - desc "set_logger_level level", "Updates the log4j logging level to a new value." - def set_logger_level(level) - if nexus_remote.set_logger_level(level) - say "The logging level of Nexus has been set to #{level.upcase}", :blue + desc "set_logger_level name level", "Updates the log4j logging level to a new value." + def set_logger_level(name, level) + if nexus_remote.set_logger_level(name, level) + say "The logging level of Logger #{name} has been set to #{level.upcase}", :blue end end