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

fixes #93 #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
32 changes: 19 additions & 13 deletions lib/nexus_cli/mixins/logging_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions lib/nexus_cli/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down