mirror of https://github.com/qos-ch/slf4j
Reformat all code with the exception of the slf4j-android module to use 4 space indentation and max line width of 160.
This commit is contained in:
parent
32d133d01e
commit
3121243572
558
codeStyle.xml
558
codeStyle.xml
|
|
@ -1,295 +1,295 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<profiles version="12">
|
||||
<profile kind="CodeFormatterProfile" name="slf4jCodeStyle" version="12">
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="4"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="160"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
|
|
|||
|
|
@ -37,24 +37,24 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public class Activator implements BundleActivator {
|
||||
|
||||
private BundleContext m_context = null;
|
||||
private BundleContext m_context = null;
|
||||
|
||||
public void start(BundleContext context) {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
logger.info("Activator.start()");
|
||||
m_context = context;
|
||||
}
|
||||
|
||||
public void stop(BundleContext context) {
|
||||
m_context = null;
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
logger.info("Activator.stop");
|
||||
}
|
||||
|
||||
public Bundle[] getBundles() {
|
||||
if (m_context != null) {
|
||||
return m_context.getBundles();
|
||||
public void start(BundleContext context) {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
logger.info("Activator.start()");
|
||||
m_context = context;
|
||||
}
|
||||
|
||||
public void stop(BundleContext context) {
|
||||
m_context = null;
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
logger.info("Activator.stop");
|
||||
}
|
||||
|
||||
public Bundle[] getBundles() {
|
||||
if (m_context != null) {
|
||||
return m_context.getBundles();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,31 +32,30 @@ import junit.framework.TestCase;
|
|||
|
||||
public class CompatibilityAssertionTest extends TestCase {
|
||||
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
|
||||
public CompatibilityAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public CompatibilityAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
|
||||
public void test() throws Exception {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world "+diff;
|
||||
logger.info(msg);
|
||||
assertEquals(1, sps.stringList.size());
|
||||
String s0 = (String) sps.stringList.get(0);
|
||||
assertTrue(s0.contains(msg));
|
||||
}
|
||||
public void test() throws Exception {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
assertEquals(1, sps.stringList.size());
|
||||
String s0 = (String) sps.stringList.get(0);
|
||||
assertTrue(s0.contains(msg));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,44 +32,43 @@ import junit.framework.TestCase;
|
|||
|
||||
public class IncompatibleMultiBindingAssertionTest extends TestCase {
|
||||
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
|
||||
public IncompatibleMultiBindingAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
try {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
fail("was expecting NoSuchMethodError");
|
||||
} catch (NoSuchMethodError e) {
|
||||
public IncompatibleMultiBindingAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
List<String> list = sps.stringList;
|
||||
assertMsgContains(list, 0, "Class path contains multiple SLF4J bindings.");
|
||||
assertMsgContains(list, 1, "Found binding in");
|
||||
assertMsgContains(list, 2, "Found binding in");
|
||||
assertMsgContains(list, 3, "See http://www.slf4j.org/codes.html");
|
||||
assertMsgContains(list, 4,
|
||||
"slf4j-api 1.6.x (or later) is incompatible with this binding");
|
||||
assertMsgContains(list, 5, "Your binding is version 1.5.5 or earlier.");
|
||||
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
void assertMsgContains(List<String> strList, int index, String msg) {
|
||||
assertTrue(((String) strList.get(index)).contains(msg));
|
||||
}
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
try {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
fail("was expecting NoSuchMethodError");
|
||||
} catch (NoSuchMethodError e) {
|
||||
}
|
||||
List<String> list = sps.stringList;
|
||||
assertMsgContains(list, 0, "Class path contains multiple SLF4J bindings.");
|
||||
assertMsgContains(list, 1, "Found binding in");
|
||||
assertMsgContains(list, 2, "Found binding in");
|
||||
assertMsgContains(list, 3, "See http://www.slf4j.org/codes.html");
|
||||
assertMsgContains(list, 4, "slf4j-api 1.6.x (or later) is incompatible with this binding");
|
||||
assertMsgContains(list, 5, "Your binding is version 1.5.5 or earlier.");
|
||||
|
||||
}
|
||||
|
||||
void assertMsgContains(List<String> strList, int index, String msg) {
|
||||
assertTrue(((String) strList.get(index)).contains(msg));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,57 +31,53 @@ import junit.framework.TestCase;
|
|||
|
||||
public class MissingSingletonMethodAssertionTest extends TestCase {
|
||||
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
|
||||
public MissingSingletonMethodAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
try {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
fail("NoSuchMethodError expected");
|
||||
} catch (NoSuchMethodError e) {
|
||||
public MissingSingletonMethodAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
int lineCount = sps.stringList
|
||||
.size();
|
||||
assertTrue("number of lines should be 3 but was "+lineCount, lineCount == 3);
|
||||
|
||||
|
||||
// expected output:
|
||||
// SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
|
||||
// SLF4J: Your binding is version 1.4.x or earlier.
|
||||
// SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x
|
||||
|
||||
{
|
||||
String s = (String) sps.stringList.get(0);
|
||||
assertTrue(s
|
||||
.contains("SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding."));
|
||||
}
|
||||
{
|
||||
String s = (String) sps.stringList.get(1);
|
||||
assertTrue(s.contains("SLF4J: Your binding is version 1.5.5 or earlier."));
|
||||
}
|
||||
{
|
||||
String s = (String) sps.stringList.get(2);
|
||||
assertTrue(s
|
||||
.contains("SLF4J: Upgrade your binding to version 1.6.x."));
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
}
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
try {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
fail("NoSuchMethodError expected");
|
||||
} catch (NoSuchMethodError e) {
|
||||
}
|
||||
|
||||
int lineCount = sps.stringList.size();
|
||||
assertTrue("number of lines should be 3 but was " + lineCount, lineCount == 3);
|
||||
|
||||
// expected output:
|
||||
// SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
|
||||
// SLF4J: Your binding is version 1.4.x or earlier.
|
||||
// SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x
|
||||
|
||||
{
|
||||
String s = (String) sps.stringList.get(0);
|
||||
assertTrue(s.contains("SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding."));
|
||||
}
|
||||
{
|
||||
String s = (String) sps.stringList.get(1);
|
||||
assertTrue(s.contains("SLF4J: Your binding is version 1.5.5 or earlier."));
|
||||
}
|
||||
{
|
||||
String s = (String) sps.stringList.get(2);
|
||||
assertTrue(s.contains("SLF4J: Upgrade your binding to version 1.6.x."));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,37 +32,37 @@ import junit.framework.TestCase;
|
|||
|
||||
public class MultiBindingAssertionTest extends TestCase {
|
||||
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
|
||||
public MultiBindingAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public MultiBindingAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
List<String> list = sps.stringList;
|
||||
assertMsgContains(list, 0, "Class path contains multiple SLF4J bindings.");
|
||||
assertMsgContains(list, 1, "Found binding in");
|
||||
assertMsgContains(list, 2, "Found binding in");
|
||||
assertMsgContains(list, 3, "See http://www.slf4j.org/codes.html");
|
||||
assertMsgContains(list, 4, "Actual binding is of type [");
|
||||
}
|
||||
public void test() throws Exception {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
List<String> list = sps.stringList;
|
||||
assertMsgContains(list, 0, "Class path contains multiple SLF4J bindings.");
|
||||
assertMsgContains(list, 1, "Found binding in");
|
||||
assertMsgContains(list, 2, "Found binding in");
|
||||
assertMsgContains(list, 3, "See http://www.slf4j.org/codes.html");
|
||||
assertMsgContains(list, 4, "Actual binding is of type [");
|
||||
}
|
||||
|
||||
void assertMsgContains(List<String> strList, int index, String msg) {
|
||||
assertTrue(((String) strList.get(index)).contains(msg));
|
||||
}
|
||||
void assertMsgContains(List<String> strList, int index, String msg) {
|
||||
assertTrue(((String) strList.get(index)).contains(msg));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,28 +30,27 @@ import java.util.List;
|
|||
|
||||
public class StringPrintStream extends PrintStream {
|
||||
|
||||
public static final String LINE_SEP = System.getProperty("line.separator");
|
||||
PrintStream other;
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
public static final String LINE_SEP = System.getProperty("line.separator");
|
||||
PrintStream other;
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
|
||||
public StringPrintStream(PrintStream ps) {
|
||||
super(ps);
|
||||
other = ps;
|
||||
}
|
||||
public StringPrintStream(PrintStream ps) {
|
||||
super(ps);
|
||||
other = ps;
|
||||
}
|
||||
|
||||
public void print(String s) {
|
||||
other.print(s);
|
||||
stringList.add(s);
|
||||
}
|
||||
public void print(String s) {
|
||||
other.print(s);
|
||||
stringList.add(s);
|
||||
}
|
||||
|
||||
public void println(String s) {
|
||||
other.println(s);
|
||||
stringList.add(s);
|
||||
}
|
||||
public void println(String s) {
|
||||
other.println(s);
|
||||
stringList.add(s);
|
||||
}
|
||||
|
||||
public void println(Object o) {
|
||||
other.println(o);
|
||||
stringList.add(o.toString());
|
||||
}
|
||||
public void println(Object o) {
|
||||
other.println(o);
|
||||
stringList.add(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,37 +31,37 @@ import junit.framework.TestCase;
|
|||
|
||||
public class VersionMismatchAssertionTest extends TestCase {
|
||||
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
StringPrintStream sps = new StringPrintStream(System.err);
|
||||
PrintStream old = System.err;
|
||||
int diff = 1024 + new Random().nextInt(10000);
|
||||
|
||||
public VersionMismatchAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public VersionMismatchAssertionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
public void test() throws Exception {
|
||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
|
||||
String s0 = (String) sps.stringList.get(0);
|
||||
assertTrue(s0.matches("SLF4J: The requested version .* by your slf4j binding is not compatible with.*"));
|
||||
String s0 = (String) sps.stringList.get(0);
|
||||
assertTrue(s0.matches("SLF4J: The requested version .* by your slf4j binding is not compatible with.*"));
|
||||
|
||||
String s1 = (String) sps.stringList.get(1);
|
||||
assertTrue(s1.contains(LoggerFactory.VERSION_MISMATCH));
|
||||
String s1 = (String) sps.stringList.get(1);
|
||||
assertTrue(s1.contains(LoggerFactory.VERSION_MISMATCH));
|
||||
|
||||
String s2 = (String) sps.stringList.get(2);
|
||||
assertTrue(s2.contains(msg));
|
||||
String s2 = (String) sps.stringList.get(2);
|
||||
assertTrue(s2.contains(msg));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,30 +30,30 @@ import junit.framework.TestCase;
|
|||
|
||||
public class BundleTest extends TestCase {
|
||||
|
||||
FrameworkErrorListener fel = new FrameworkErrorListener();
|
||||
CheckingBundleListener mbl = new CheckingBundleListener();
|
||||
FrameworkErrorListener fel = new FrameworkErrorListener();
|
||||
CheckingBundleListener mbl = new CheckingBundleListener();
|
||||
|
||||
FelixHost felixHost = new FelixHost(fel, mbl);
|
||||
FelixHost felixHost = new FelixHost(fel, mbl);
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
felixHost.doLaunch();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
felixHost.stop();
|
||||
}
|
||||
|
||||
public void testSmoke() {
|
||||
System.out.println("==========="+new File(".").getAbsolutePath());
|
||||
mbl.dumpAll();
|
||||
// check that the bundle was installed
|
||||
assertTrue(mbl.exists("iBundle"));
|
||||
if(fel.errorList.size() != 0) {
|
||||
fel.dumpAll();
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
felixHost.doLaunch();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
felixHost.stop();
|
||||
}
|
||||
|
||||
public void testSmoke() {
|
||||
System.out.println("===========" + new File(".").getAbsolutePath());
|
||||
mbl.dumpAll();
|
||||
// check that the bundle was installed
|
||||
assertTrue(mbl.exists("iBundle"));
|
||||
if (fel.errorList.size() != 0) {
|
||||
fel.dumpAll();
|
||||
}
|
||||
// check that no errors occured
|
||||
assertEquals(0, fel.errorList.size());
|
||||
}
|
||||
// check that no errors occured
|
||||
assertEquals(0, fel.errorList.size());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,35 +33,34 @@ import org.osgi.framework.BundleListener;
|
|||
|
||||
public class CheckingBundleListener implements BundleListener {
|
||||
|
||||
List<BundleEvent> eventList = new ArrayList<BundleEvent>();
|
||||
List<BundleEvent> eventList = new ArrayList<BundleEvent>();
|
||||
|
||||
public void bundleChanged(BundleEvent be) {
|
||||
eventList.add(be);
|
||||
}
|
||||
|
||||
private void dump(BundleEvent be) {
|
||||
System.out.println("BE:" + ", source " + be.getSource() + ", bundle="
|
||||
+ be.getBundle() + ", type=" + be.getType());
|
||||
|
||||
}
|
||||
|
||||
public void dumpAll() {
|
||||
for (int i = 0; i < eventList.size(); i++) {
|
||||
BundleEvent fe = (BundleEvent) eventList.get(i);
|
||||
dump(fe);
|
||||
public void bundleChanged(BundleEvent be) {
|
||||
eventList.add(be);
|
||||
}
|
||||
}
|
||||
|
||||
boolean exists(String bundleName) {
|
||||
for (int i = 0; i < eventList.size(); i++) {
|
||||
BundleEvent fe = (BundleEvent) eventList.get(i);
|
||||
Bundle b = fe.getBundle();
|
||||
System.out.println("===["+b+"]");
|
||||
if (bundleName.equals(b.getSymbolicName())) {
|
||||
return true;
|
||||
}
|
||||
private void dump(BundleEvent be) {
|
||||
System.out.println("BE:" + ", source " + be.getSource() + ", bundle=" + be.getBundle() + ", type=" + be.getType());
|
||||
|
||||
}
|
||||
|
||||
public void dumpAll() {
|
||||
for (int i = 0; i < eventList.size(); i++) {
|
||||
BundleEvent fe = (BundleEvent) eventList.get(i);
|
||||
dump(fe);
|
||||
}
|
||||
}
|
||||
|
||||
boolean exists(String bundleName) {
|
||||
for (int i = 0; i < eventList.size(); i++) {
|
||||
BundleEvent fe = (BundleEvent) eventList.get(i);
|
||||
Bundle b = fe.getBundle();
|
||||
System.out.println("===[" + b + "]");
|
||||
if (bundleName.equals(b.getSymbolicName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,84 +45,75 @@ import org.osgi.framework.Constants;
|
|||
*/
|
||||
public class FelixHost {
|
||||
|
||||
private Felix felix = null;
|
||||
private Felix felix = null;
|
||||
|
||||
Properties otherProps = new Properties();
|
||||
Properties otherProps = new Properties();
|
||||
|
||||
final FrameworkErrorListener frameworkErrorListener;
|
||||
final CheckingBundleListener myBundleListener;
|
||||
final FrameworkErrorListener frameworkErrorListener;
|
||||
final CheckingBundleListener myBundleListener;
|
||||
|
||||
public FelixHost(FrameworkErrorListener frameworkErrorListener,
|
||||
CheckingBundleListener myBundleListener) {
|
||||
this.frameworkErrorListener = frameworkErrorListener;
|
||||
this.myBundleListener = myBundleListener;
|
||||
}
|
||||
|
||||
public void doLaunch() {
|
||||
// Create a case-insensitive configuration property map.
|
||||
StringMap configMap = new StringMap(false);
|
||||
// Configure the Felix instance to be embedded.
|
||||
// configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true");
|
||||
// Add core OSGi packages to be exported from the class path
|
||||
// via the system bundle.
|
||||
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
|
||||
"org.osgi.framework; version=1.3.0,"
|
||||
+ "org.osgi.service.packageadmin; version=1.2.0,"
|
||||
+ "org.osgi.service.startlevel; version=1.0.0,"
|
||||
+ "org.osgi.service.url; version=1.0.0");
|
||||
|
||||
configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN,
|
||||
Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
|
||||
|
||||
// Explicitly specify the directory to use for caching bundles.
|
||||
// configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");
|
||||
|
||||
try {
|
||||
// Create host activator;
|
||||
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
|
||||
// list.add(new HostActivator());
|
||||
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
|
||||
"org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming");
|
||||
configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
|
||||
configMap.put("felix.log.level", "4");
|
||||
|
||||
// Now create an instance of the framework with
|
||||
// our configuration properties and activator.
|
||||
felix = new Felix(configMap);
|
||||
felix.init();
|
||||
|
||||
// otherProps.put(Constants.FRAMEWORK_STORAGE, "bundles");
|
||||
|
||||
otherProps.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY,
|
||||
AutoProcessor.AUTO_DEPLOY_DIR_VALUE);
|
||||
otherProps.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY,
|
||||
AutoProcessor.AUTO_DEPLOY_START_VALUE + ","
|
||||
+ AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE);
|
||||
|
||||
BundleContext felixBudleContext = felix.getBundleContext();
|
||||
|
||||
AutoProcessor.process(otherProps, felixBudleContext);
|
||||
// listen to errors
|
||||
felixBudleContext.addFrameworkListener(frameworkErrorListener);
|
||||
felixBudleContext.addBundleListener(myBundleListener);
|
||||
// Now start Felix instance.
|
||||
felix.start();
|
||||
System.out.println("felix started");
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
public FelixHost(FrameworkErrorListener frameworkErrorListener, CheckingBundleListener myBundleListener) {
|
||||
this.frameworkErrorListener = frameworkErrorListener;
|
||||
this.myBundleListener = myBundleListener;
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws BundleException {
|
||||
felix.stop();
|
||||
}
|
||||
public void doLaunch() {
|
||||
// Create a case-insensitive configuration property map.
|
||||
StringMap configMap = new StringMap(false);
|
||||
// Configure the Felix instance to be embedded.
|
||||
// configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true");
|
||||
// Add core OSGi packages to be exported from the class path
|
||||
// via the system bundle.
|
||||
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0,"
|
||||
+ "org.osgi.service.startlevel; version=1.0.0," + "org.osgi.service.url; version=1.0.0");
|
||||
|
||||
public Bundle[] getInstalledBundles() {
|
||||
// Use the system bundle activator to gain external
|
||||
// access to the set of installed bundles.
|
||||
return null;// m_activator.getBundles();
|
||||
}
|
||||
configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
|
||||
|
||||
// Explicitly specify the directory to use for caching bundles.
|
||||
// configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");
|
||||
|
||||
try {
|
||||
// Create host activator;
|
||||
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
|
||||
// list.add(new HostActivator());
|
||||
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming");
|
||||
configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
|
||||
configMap.put("felix.log.level", "4");
|
||||
|
||||
// Now create an instance of the framework with
|
||||
// our configuration properties and activator.
|
||||
felix = new Felix(configMap);
|
||||
felix.init();
|
||||
|
||||
// otherProps.put(Constants.FRAMEWORK_STORAGE, "bundles");
|
||||
|
||||
otherProps.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY, AutoProcessor.AUTO_DEPLOY_DIR_VALUE);
|
||||
otherProps.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY, AutoProcessor.AUTO_DEPLOY_START_VALUE + "," + AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE);
|
||||
|
||||
BundleContext felixBudleContext = felix.getBundleContext();
|
||||
|
||||
AutoProcessor.process(otherProps, felixBudleContext);
|
||||
// listen to errors
|
||||
felixBudleContext.addFrameworkListener(frameworkErrorListener);
|
||||
felixBudleContext.addBundleListener(myBundleListener);
|
||||
// Now start Felix instance.
|
||||
felix.start();
|
||||
System.out.println("felix started");
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws BundleException {
|
||||
felix.stop();
|
||||
}
|
||||
|
||||
public Bundle[] getInstalledBundles() {
|
||||
// Use the system bundle activator to gain external
|
||||
// access to the set of installed bundles.
|
||||
return null;// m_activator.getBundles();
|
||||
}
|
||||
}
|
||||
|
|
@ -32,32 +32,31 @@ import org.osgi.framework.FrameworkListener;
|
|||
|
||||
public class FrameworkErrorListener implements FrameworkListener {
|
||||
|
||||
public List<FrameworkEvent> errorList = new ArrayList<FrameworkEvent>();
|
||||
public List<FrameworkEvent> errorList = new ArrayList<FrameworkEvent>();
|
||||
|
||||
public void frameworkEvent(FrameworkEvent fe) {
|
||||
if (fe.getType() == FrameworkEvent.ERROR) {
|
||||
errorList.add(fe);
|
||||
public void frameworkEvent(FrameworkEvent fe) {
|
||||
if (fe.getType() == FrameworkEvent.ERROR) {
|
||||
errorList.add(fe);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dump(FrameworkEvent fe) {
|
||||
Throwable t = fe.getThrowable();
|
||||
String tString = null;
|
||||
if (t != null) {
|
||||
tString = t.toString();
|
||||
private void dump(FrameworkEvent fe) {
|
||||
Throwable t = fe.getThrowable();
|
||||
String tString = null;
|
||||
if (t != null) {
|
||||
tString = t.toString();
|
||||
}
|
||||
System.out.println("Framework ERROR:" + ", source " + fe.getSource() + ", bundle=" + fe.getBundle() + ", ex=" + tString);
|
||||
if (t != null) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
System.out.println("Framework ERROR:" + ", source " + fe.getSource()
|
||||
+ ", bundle=" + fe.getBundle() + ", ex=" + tString);
|
||||
if(t != null) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void dumpAll() {
|
||||
for(int i = 0; i < errorList.size(); i++) {
|
||||
FrameworkEvent fe = (FrameworkEvent) errorList.get(i);
|
||||
dump(fe);
|
||||
public void dumpAll() {
|
||||
for (int i = 0; i < errorList.size(); i++) {
|
||||
FrameworkEvent fe = (FrameworkEvent) errorList.get(i);
|
||||
dump(fe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,8 @@ package org.apache.commons.logging;
|
|||
*/
|
||||
public interface Log {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Logging Properties
|
||||
|
||||
|
||||
/**
|
||||
* <p> Is debug logging currently enabled? </p>
|
||||
*
|
||||
|
|
@ -75,7 +73,6 @@ public interface Log {
|
|||
*/
|
||||
public boolean isDebugEnabled();
|
||||
|
||||
|
||||
/**
|
||||
* <p> Is error logging currently enabled? </p>
|
||||
*
|
||||
|
|
@ -85,7 +82,6 @@ public interface Log {
|
|||
*/
|
||||
public boolean isErrorEnabled();
|
||||
|
||||
|
||||
/**
|
||||
* <p> Is fatal logging currently enabled? </p>
|
||||
*
|
||||
|
|
@ -95,7 +91,6 @@ public interface Log {
|
|||
*/
|
||||
public boolean isFatalEnabled();
|
||||
|
||||
|
||||
/**
|
||||
* <p> Is info logging currently enabled? </p>
|
||||
*
|
||||
|
|
@ -107,7 +102,6 @@ public interface Log {
|
|||
*/
|
||||
public boolean isInfoEnabled();
|
||||
|
||||
|
||||
/**
|
||||
* <p> Is trace logging currently enabled? </p>
|
||||
*
|
||||
|
|
@ -119,7 +113,6 @@ public interface Log {
|
|||
*/
|
||||
public boolean isTraceEnabled();
|
||||
|
||||
|
||||
/**
|
||||
* <p> Is warn logging currently enabled? </p>
|
||||
*
|
||||
|
|
@ -129,10 +122,8 @@ public interface Log {
|
|||
*/
|
||||
public boolean isWarnEnabled();
|
||||
|
||||
|
||||
// -------------------------------------------------------- Logging Methods
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log a message with trace log level. </p>
|
||||
*
|
||||
|
|
@ -140,7 +131,6 @@ public interface Log {
|
|||
*/
|
||||
public void trace(Object message);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log an error with trace log level. </p>
|
||||
*
|
||||
|
|
@ -149,7 +139,6 @@ public interface Log {
|
|||
*/
|
||||
public void trace(Object message, Throwable t);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log a message with debug log level. </p>
|
||||
*
|
||||
|
|
@ -157,7 +146,6 @@ public interface Log {
|
|||
*/
|
||||
public void debug(Object message);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log an error with debug log level. </p>
|
||||
*
|
||||
|
|
@ -166,7 +154,6 @@ public interface Log {
|
|||
*/
|
||||
public void debug(Object message, Throwable t);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log a message with info log level. </p>
|
||||
*
|
||||
|
|
@ -174,7 +161,6 @@ public interface Log {
|
|||
*/
|
||||
public void info(Object message);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log an error with info log level. </p>
|
||||
*
|
||||
|
|
@ -183,7 +169,6 @@ public interface Log {
|
|||
*/
|
||||
public void info(Object message, Throwable t);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log a message with warn log level. </p>
|
||||
*
|
||||
|
|
@ -191,7 +176,6 @@ public interface Log {
|
|||
*/
|
||||
public void warn(Object message);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log an error with warn log level. </p>
|
||||
*
|
||||
|
|
@ -200,7 +184,6 @@ public interface Log {
|
|||
*/
|
||||
public void warn(Object message, Throwable t);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log a message with error log level. </p>
|
||||
*
|
||||
|
|
@ -208,7 +191,6 @@ public interface Log {
|
|||
*/
|
||||
public void error(Object message);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log an error with error log level. </p>
|
||||
*
|
||||
|
|
@ -217,7 +199,6 @@ public interface Log {
|
|||
*/
|
||||
public void error(Object message, Throwable t);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log a message with fatal log level. </p>
|
||||
*
|
||||
|
|
@ -225,7 +206,6 @@ public interface Log {
|
|||
*/
|
||||
public void fatal(Object message);
|
||||
|
||||
|
||||
/**
|
||||
* <p> Log an error with fatal log level. </p>
|
||||
*
|
||||
|
|
@ -234,5 +214,4 @@ public interface Log {
|
|||
*/
|
||||
public void fatal(Object message, Throwable t);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,61 +33,61 @@ package org.apache.commons.logging;
|
|||
|
||||
public class LogConfigurationException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 8486587136871052495L;
|
||||
private static final long serialVersionUID = 8486587136871052495L;
|
||||
|
||||
/**
|
||||
* Construct a new exception with <code>null</code> as its detail message.
|
||||
*/
|
||||
public LogConfigurationException() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Construct a new exception with <code>null</code> as its detail message.
|
||||
*/
|
||||
public LogConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new exception with the specified detail message.
|
||||
*
|
||||
* @param message
|
||||
* The detail message
|
||||
*/
|
||||
public LogConfigurationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
/**
|
||||
* Construct a new exception with the specified detail message.
|
||||
*
|
||||
* @param message
|
||||
* The detail message
|
||||
*/
|
||||
public LogConfigurationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new exception with the specified cause and a derived detail
|
||||
* message.
|
||||
*
|
||||
* @param cause
|
||||
* The underlying cause
|
||||
*/
|
||||
public LogConfigurationException(Throwable cause) {
|
||||
/**
|
||||
* Construct a new exception with the specified cause and a derived detail
|
||||
* message.
|
||||
*
|
||||
* @param cause
|
||||
* The underlying cause
|
||||
*/
|
||||
public LogConfigurationException(Throwable cause) {
|
||||
|
||||
this((cause == null) ? null : cause.toString(), cause);
|
||||
this((cause == null) ? null : cause.toString(), cause);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new exception with the specified detail message and cause.
|
||||
*
|
||||
* @param message
|
||||
* The detail message
|
||||
* @param cause
|
||||
* The underlying cause
|
||||
*/
|
||||
public LogConfigurationException(String message, Throwable cause) {
|
||||
super(message + " (Caused by " + cause + ")");
|
||||
this.cause = cause; // Two-argument version requires JDK 1.4 or later
|
||||
}
|
||||
/**
|
||||
* Construct a new exception with the specified detail message and cause.
|
||||
*
|
||||
* @param message
|
||||
* The detail message
|
||||
* @param cause
|
||||
* The underlying cause
|
||||
*/
|
||||
public LogConfigurationException(String message, Throwable cause) {
|
||||
super(message + " (Caused by " + cause + ")");
|
||||
this.cause = cause; // Two-argument version requires JDK 1.4 or later
|
||||
}
|
||||
|
||||
/**
|
||||
* The underlying cause of this exception.
|
||||
*/
|
||||
protected Throwable cause = null;
|
||||
/**
|
||||
* The underlying cause of this exception.
|
||||
*/
|
||||
protected Throwable cause = null;
|
||||
|
||||
/**
|
||||
* Return the underlying cause of this exception (if any).
|
||||
*/
|
||||
public Throwable getCause() {
|
||||
return (this.cause);
|
||||
}
|
||||
/**
|
||||
* Return the underlying cause of this exception (if any).
|
||||
*/
|
||||
public Throwable getCause() {
|
||||
return (this.cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,387 +36,373 @@ import org.apache.commons.logging.impl.SLF4JLogFactory;
|
|||
@SuppressWarnings("rawtypes")
|
||||
public abstract class LogFactory {
|
||||
|
||||
static String UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J = "http://www.slf4j.org/codes.html#unsupported_operation_in_jcl_over_slf4j";
|
||||
static String UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J = "http://www.slf4j.org/codes.html#unsupported_operation_in_jcl_over_slf4j";
|
||||
|
||||
static LogFactory logFactory = new SLF4JLogFactory();
|
||||
static LogFactory logFactory = new SLF4JLogFactory();
|
||||
|
||||
/**
|
||||
* The name (<code>priority</code>) of the key in the config file used to
|
||||
* specify the priority of that particular config file. The associated value
|
||||
* is a floating-point number; higher values take priority over lower values.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String PRIORITY_KEY = "priority";
|
||||
/**
|
||||
* The name (<code>priority</code>) of the key in the config file used to
|
||||
* specify the priority of that particular config file. The associated value
|
||||
* is a floating-point number; higher values take priority over lower values.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String PRIORITY_KEY = "priority";
|
||||
|
||||
/**
|
||||
* The name (<code>use_tccl</code>) of the key in the config file used to
|
||||
* specify whether logging classes should be loaded via the thread context
|
||||
* class loader (TCCL), or not. By default, the TCCL is used.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String TCCL_KEY = "use_tccl";
|
||||
/**
|
||||
* The name (<code>use_tccl</code>) of the key in the config file used to
|
||||
* specify whether logging classes should be loaded via the thread context
|
||||
* class loader (TCCL), or not. By default, the TCCL is used.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String TCCL_KEY = "use_tccl";
|
||||
|
||||
/**
|
||||
* The name of the property used to identify the LogFactory implementation
|
||||
* class name.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory";
|
||||
/**
|
||||
* The name of the property used to identify the LogFactory implementation
|
||||
* class name.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory";
|
||||
|
||||
/**
|
||||
* The fully qualified class name of the fallback <code>LogFactory</code>
|
||||
* implementation class to use, if no other can be found.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String FACTORY_DEFAULT = "org.apache.commons.logging.impl.SLF4JLogFactory";
|
||||
/**
|
||||
* The fully qualified class name of the fallback <code>LogFactory</code>
|
||||
* implementation class to use, if no other can be found.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String FACTORY_DEFAULT = "org.apache.commons.logging.impl.SLF4JLogFactory";
|
||||
|
||||
/**
|
||||
* The name of the properties file to search for.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String FACTORY_PROPERTIES = "commons-logging.properties";
|
||||
/**
|
||||
* The name of the properties file to search for.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String FACTORY_PROPERTIES = "commons-logging.properties";
|
||||
|
||||
/**
|
||||
* JDK1.3+ <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider">
|
||||
* 'Service Provider' specification</a>.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
protected static final String SERVICE_ID = "META-INF/services/org.apache.commons.logging.LogFactory";
|
||||
|
||||
/**
|
||||
* JDK1.3+ <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider">
|
||||
* 'Service Provider' specification</a>.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
protected static final String SERVICE_ID =
|
||||
"META-INF/services/org.apache.commons.logging.LogFactory";
|
||||
/**
|
||||
* The name (<code>org.apache.commons.logging.diagnostics.dest</code>) of
|
||||
* the property used to enable internal commons-logging diagnostic output, in
|
||||
* order to get information on what logging implementations are being
|
||||
* discovered, what classloaders they are loaded through, etc.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String DIAGNOSTICS_DEST_PROPERTY = "org.apache.commons.logging.diagnostics.dest";
|
||||
|
||||
/**
|
||||
* The name (<code>org.apache.commons.logging.diagnostics.dest</code>) of
|
||||
* the property used to enable internal commons-logging diagnostic output, in
|
||||
* order to get information on what logging implementations are being
|
||||
* discovered, what classloaders they are loaded through, etc.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String DIAGNOSTICS_DEST_PROPERTY = "org.apache.commons.logging.diagnostics.dest";
|
||||
/**
|
||||
* <p>
|
||||
* Setting this system property value allows the <code>Hashtable</code> used
|
||||
* to store classloaders to be substituted by an alternative implementation.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String HASHTABLE_IMPLEMENTATION_PROPERTY = "org.apache.commons.logging.LogFactory.HashtableImpl";
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Setting this system property value allows the <code>Hashtable</code> used
|
||||
* to store classloaders to be substituted by an alternative implementation.
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
public static final String HASHTABLE_IMPLEMENTATION_PROPERTY = "org.apache.commons.logging.LogFactory.HashtableImpl";
|
||||
/**
|
||||
* The previously constructed <code>LogFactory</code> instances, keyed by
|
||||
* the <code>ClassLoader</code> with which it was created.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
protected static Hashtable factories = null;
|
||||
|
||||
/**
|
||||
* The previously constructed <code>LogFactory</code> instances, keyed by
|
||||
* the <code>ClassLoader</code> with which it was created.
|
||||
*
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
protected static Hashtable factories = null;
|
||||
/**
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
protected static LogFactory nullClassLoaderFactory = null;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This property is not used but preserved here for compatibility.
|
||||
*/
|
||||
protected static LogFactory nullClassLoaderFactory = null;
|
||||
|
||||
/**
|
||||
* Protected constructor that is not available for public use.
|
||||
*/
|
||||
protected LogFactory() {
|
||||
}
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Return the configuration attribute with the specified name (if any), or
|
||||
* <code>null</code> if there is no such attribute.
|
||||
*
|
||||
* @param name Name of the attribute to return
|
||||
* @return configuration attribute
|
||||
*/
|
||||
public abstract Object getAttribute(String name);
|
||||
|
||||
/**
|
||||
* Return an array containing the names of all currently defined configuration
|
||||
* attributes. If there are no such attributes, a zero length array is
|
||||
* returned.
|
||||
*
|
||||
* @return names of all currently defined configuration attributes
|
||||
*/
|
||||
public abstract String[] getAttributeNames();
|
||||
|
||||
/**
|
||||
* Convenience method to derive a name from the specified class and call
|
||||
* <code>getInstance(String)</code> with it.
|
||||
*
|
||||
* @param clazz
|
||||
* Class for which a suitable Log name will be derived
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public abstract Log getInstance(Class clazz) throws LogConfigurationException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Construct (if necessary) and return a <code>Log</code> instance, using
|
||||
* the factory's current set of configuration attributes.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE </strong>- Depending upon the implementation of the
|
||||
* <code>LogFactory</code> you are using, the <code>Log</code> instance
|
||||
* you are returned may or may not be local to the current application, and
|
||||
* may or may not be returned again on a subsequent call with the same name
|
||||
* argument.
|
||||
* </p>
|
||||
*
|
||||
* @param name
|
||||
* Logical name of the <code>Log</code> instance to be
|
||||
* returned (the meaning of this name is only known to the
|
||||
* underlying logging implementation that is being wrapped)
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public abstract Log getInstance(String name) throws LogConfigurationException;
|
||||
|
||||
/**
|
||||
* Release any internal references to previously created {@link Log}instances
|
||||
* returned by this factory. This is useful in environments like servlet
|
||||
* containers, which implement application reloading by throwing away a
|
||||
* ClassLoader. Dangling references to objects in that class loader would
|
||||
* prevent garbage collection.
|
||||
*/
|
||||
public abstract void release();
|
||||
|
||||
/**
|
||||
* Remove any configuration attribute associated with the specified name. If
|
||||
* there is no such attribute, no action is taken.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to remove
|
||||
*/
|
||||
public abstract void removeAttribute(String name);
|
||||
|
||||
/**
|
||||
* Set the configuration attribute with the specified name. Calling this with
|
||||
* a <code>null</code> value is equivalent to calling
|
||||
* <code>removeAttribute(name)</code>.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to set
|
||||
* @param value
|
||||
* Value of the attribute to set, or <code>null</code> to
|
||||
* remove any setting for this attribute
|
||||
*/
|
||||
public abstract void setAttribute(String name, Object value);
|
||||
|
||||
// --------------------------------------------------------- Static Methods
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Construct (if necessary) and return a <code>LogFactory</code> instance,
|
||||
* using the following ordered lookup procedure to determine the name of the
|
||||
* implementation class to be loaded.
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>The <code>org.apache.commons.logging.LogFactory</code> system
|
||||
* property.</li>
|
||||
* <li>The JDK 1.3 Service Discovery mechanism</li>
|
||||
* <li>Use the properties file <code>commons-logging.properties</code>
|
||||
* file, if found in the class path of this class. The configuration file is
|
||||
* in standard <code>java.util.Properties</code> format and contains the
|
||||
* fully qualified name of the implementation class with the key being the
|
||||
* system property defined above.</li>
|
||||
* <li>Fall back to a default implementation class (
|
||||
* <code>org.apache.commons.logging.impl.SLF4FLogFactory</code>).</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* <em>NOTE</em>- If the properties file method of identifying the
|
||||
* <code>LogFactory</code> implementation class is utilized, all of the
|
||||
* properties defined in this file will be set as configuration attributes on
|
||||
* the corresponding <code>LogFactory</code> instance.
|
||||
* </p>
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if the implementation class is not available or cannot
|
||||
* be instantiated.
|
||||
*/
|
||||
public static LogFactory getFactory() throws LogConfigurationException {
|
||||
return logFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to return a named logger, without the application having
|
||||
* to care about factories.
|
||||
*
|
||||
* @param clazz
|
||||
* Class from which a log name will be derived
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public static Log getLog(Class clazz) throws LogConfigurationException {
|
||||
return (getFactory().getInstance(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to return a named logger, without the application having
|
||||
* to care about factories.
|
||||
*
|
||||
* @param name
|
||||
* Logical name of the <code>Log</code> instance to be
|
||||
* returned (the meaning of this name is only known to the
|
||||
* underlying logging implementation that is being wrapped)
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public static Log getLog(String name) throws LogConfigurationException {
|
||||
return (getFactory().getInstance(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Release any internal references to previously created {@link LogFactory}
|
||||
* instances that have been associated with the specified class loader (if
|
||||
* any), after calling the instance method <code>release()</code> on each of
|
||||
* them.
|
||||
*
|
||||
* @param classLoader
|
||||
* ClassLoader for which to release the LogFactory
|
||||
*/
|
||||
public static void release(ClassLoader classLoader) {
|
||||
// since SLF4J based JCL does not make use of classloaders, there is nothing
|
||||
// to do here
|
||||
}
|
||||
|
||||
/**
|
||||
* Release any internal references to previously created {@link LogFactory}
|
||||
* instances, after calling the instance method <code>release()</code> on
|
||||
* each of them. This is useful in environments like servlet containers, which
|
||||
* implement application reloading by throwing away a ClassLoader. Dangling
|
||||
* references to objects in that class loader would prevent garbage
|
||||
* collection.
|
||||
*/
|
||||
public static void releaseAll() {
|
||||
// since SLF4J based JCL does not make use of classloaders, there is nothing
|
||||
// to do here
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that uniquely identifies the specified object, including
|
||||
* its class.
|
||||
* <p>
|
||||
* The returned string is of form "classname@hashcode", ie is the same as the
|
||||
* return value of the Object.toString() method, but works even when the
|
||||
* specified object's class has overidden the toString method.
|
||||
*
|
||||
* @param o
|
||||
* may be null.
|
||||
* @return a string of form classname@hashcode, or "null" if param o is null.
|
||||
* @since 1.1
|
||||
*/
|
||||
public static String objectId(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
} else {
|
||||
return o.getClass().getName() + "@" + System.identityHashCode(o);
|
||||
/**
|
||||
* Protected constructor that is not available for public use.
|
||||
*/
|
||||
protected LogFactory() {
|
||||
}
|
||||
}
|
||||
|
||||
// protected methods which were added in JCL 1.1. These are not used
|
||||
// by SLF4JLogFactory
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static Object createFactory(String factoryClass, ClassLoader classLoader) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [factoryClass] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
/**
|
||||
* Return the configuration attribute with the specified name (if any), or
|
||||
* <code>null</code> if there is no such attribute.
|
||||
*
|
||||
* @param name Name of the attribute to return
|
||||
* @return configuration attribute
|
||||
*/
|
||||
public abstract Object getAttribute(String name);
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static ClassLoader directGetContextClassLoader() {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [directGetContextClassLoader] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
/**
|
||||
* Return an array containing the names of all currently defined configuration
|
||||
* attributes. If there are no such attributes, a zero length array is
|
||||
* returned.
|
||||
*
|
||||
* @return names of all currently defined configuration attributes
|
||||
*/
|
||||
public abstract String[] getAttributeNames();
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static ClassLoader getContextClassLoader()
|
||||
throws LogConfigurationException {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [getContextClassLoader] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
/**
|
||||
* Convenience method to derive a name from the specified class and call
|
||||
* <code>getInstance(String)</code> with it.
|
||||
*
|
||||
* @param clazz
|
||||
* Class for which a suitable Log name will be derived
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public abstract Log getInstance(Class clazz) throws LogConfigurationException;
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static ClassLoader getClassLoader(Class clazz) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [getClassLoader] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
/**
|
||||
* <p>
|
||||
* Construct (if necessary) and return a <code>Log</code> instance, using
|
||||
* the factory's current set of configuration attributes.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <strong>NOTE </strong>- Depending upon the implementation of the
|
||||
* <code>LogFactory</code> you are using, the <code>Log</code> instance
|
||||
* you are returned may or may not be local to the current application, and
|
||||
* may or may not be returned again on a subsequent call with the same name
|
||||
* argument.
|
||||
* </p>
|
||||
*
|
||||
* @param name
|
||||
* Logical name of the <code>Log</code> instance to be
|
||||
* returned (the meaning of this name is only known to the
|
||||
* underlying logging implementation that is being wrapped)
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public abstract Log getInstance(String name) throws LogConfigurationException;
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static boolean isDiagnosticsEnabled() {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [isDiagnosticsEnabled] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
/**
|
||||
* Release any internal references to previously created {@link Log}instances
|
||||
* returned by this factory. This is useful in environments like servlet
|
||||
* containers, which implement application reloading by throwing away a
|
||||
* ClassLoader. Dangling references to objects in that class loader would
|
||||
* prevent garbage collection.
|
||||
*/
|
||||
public abstract void release();
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static void logRawDiagnostic(String msg) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [logRawDiagnostic] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
/**
|
||||
* Remove any configuration attribute associated with the specified name. If
|
||||
* there is no such attribute, no action is taken.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to remove
|
||||
*/
|
||||
public abstract void removeAttribute(String name);
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static LogFactory newFactory(final String factoryClass,
|
||||
final ClassLoader classLoader, final ClassLoader contextClassLoader) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [logRawDiagnostic] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
/**
|
||||
* Set the configuration attribute with the specified name. Calling this with
|
||||
* a <code>null</code> value is equivalent to calling
|
||||
* <code>removeAttribute(name)</code>.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to set
|
||||
* @param value
|
||||
* Value of the attribute to set, or <code>null</code> to
|
||||
* remove any setting for this attribute
|
||||
*/
|
||||
public abstract void setAttribute(String name, Object value);
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static LogFactory newFactory(final String factoryClass,
|
||||
final ClassLoader classLoader) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Operation [newFactory] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
// --------------------------------------------------------- Static Methods
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Construct (if necessary) and return a <code>LogFactory</code> instance,
|
||||
* using the following ordered lookup procedure to determine the name of the
|
||||
* implementation class to be loaded.
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>The <code>org.apache.commons.logging.LogFactory</code> system
|
||||
* property.</li>
|
||||
* <li>The JDK 1.3 Service Discovery mechanism</li>
|
||||
* <li>Use the properties file <code>commons-logging.properties</code>
|
||||
* file, if found in the class path of this class. The configuration file is
|
||||
* in standard <code>java.util.Properties</code> format and contains the
|
||||
* fully qualified name of the implementation class with the key being the
|
||||
* system property defined above.</li>
|
||||
* <li>Fall back to a default implementation class (
|
||||
* <code>org.apache.commons.logging.impl.SLF4FLogFactory</code>).</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* <em>NOTE</em>- If the properties file method of identifying the
|
||||
* <code>LogFactory</code> implementation class is utilized, all of the
|
||||
* properties defined in this file will be set as configuration attributes on
|
||||
* the corresponding <code>LogFactory</code> instance.
|
||||
* </p>
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if the implementation class is not available or cannot
|
||||
* be instantiated.
|
||||
*/
|
||||
public static LogFactory getFactory() throws LogConfigurationException {
|
||||
return logFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to return a named logger, without the application having
|
||||
* to care about factories.
|
||||
*
|
||||
* @param clazz
|
||||
* Class from which a log name will be derived
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public static Log getLog(Class clazz) throws LogConfigurationException {
|
||||
return (getFactory().getInstance(clazz));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to return a named logger, without the application having
|
||||
* to care about factories.
|
||||
*
|
||||
* @param name
|
||||
* Logical name of the <code>Log</code> instance to be
|
||||
* returned (the meaning of this name is only known to the
|
||||
* underlying logging implementation that is being wrapped)
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be
|
||||
* returned
|
||||
*/
|
||||
public static Log getLog(String name) throws LogConfigurationException {
|
||||
return (getFactory().getInstance(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Release any internal references to previously created {@link LogFactory}
|
||||
* instances that have been associated with the specified class loader (if
|
||||
* any), after calling the instance method <code>release()</code> on each of
|
||||
* them.
|
||||
*
|
||||
* @param classLoader
|
||||
* ClassLoader for which to release the LogFactory
|
||||
*/
|
||||
public static void release(ClassLoader classLoader) {
|
||||
// since SLF4J based JCL does not make use of classloaders, there is nothing
|
||||
// to do here
|
||||
}
|
||||
|
||||
/**
|
||||
* Release any internal references to previously created {@link LogFactory}
|
||||
* instances, after calling the instance method <code>release()</code> on
|
||||
* each of them. This is useful in environments like servlet containers, which
|
||||
* implement application reloading by throwing away a ClassLoader. Dangling
|
||||
* references to objects in that class loader would prevent garbage
|
||||
* collection.
|
||||
*/
|
||||
public static void releaseAll() {
|
||||
// since SLF4J based JCL does not make use of classloaders, there is nothing
|
||||
// to do here
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string that uniquely identifies the specified object, including
|
||||
* its class.
|
||||
* <p>
|
||||
* The returned string is of form "classname@hashcode", ie is the same as the
|
||||
* return value of the Object.toString() method, but works even when the
|
||||
* specified object's class has overidden the toString method.
|
||||
*
|
||||
* @param o
|
||||
* may be null.
|
||||
* @return a string of form classname@hashcode, or "null" if param o is null.
|
||||
* @since 1.1
|
||||
*/
|
||||
public static String objectId(Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
} else {
|
||||
return o.getClass().getName() + "@" + System.identityHashCode(o);
|
||||
}
|
||||
}
|
||||
|
||||
// protected methods which were added in JCL 1.1. These are not used
|
||||
// by SLF4JLogFactory
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static Object createFactory(String factoryClass, ClassLoader classLoader) {
|
||||
throw new UnsupportedOperationException("Operation [factoryClass] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static ClassLoader directGetContextClassLoader() {
|
||||
throw new UnsupportedOperationException("Operation [directGetContextClassLoader] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static ClassLoader getContextClassLoader() throws LogConfigurationException {
|
||||
throw new UnsupportedOperationException("Operation [getContextClassLoader] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static ClassLoader getClassLoader(Class clazz) {
|
||||
throw new UnsupportedOperationException("Operation [getClassLoader] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static boolean isDiagnosticsEnabled() {
|
||||
throw new UnsupportedOperationException("Operation [isDiagnosticsEnabled] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static void logRawDiagnostic(String msg) {
|
||||
throw new UnsupportedOperationException("Operation [logRawDiagnostic] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static LogFactory newFactory(final String factoryClass, final ClassLoader classLoader, final ClassLoader contextClassLoader) {
|
||||
throw new UnsupportedOperationException("Operation [logRawDiagnostic] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method exists to ensure signature compatibility.
|
||||
*/
|
||||
protected static LogFactory newFactory(final String factoryClass, final ClassLoader classLoader) {
|
||||
throw new UnsupportedOperationException("Operation [newFactory] is not supported in jcl-over-slf4j. See also "
|
||||
+ UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,116 +30,116 @@ import org.apache.commons.logging.Log;
|
|||
* @version $Id: NoOpLog.java,v 1.8 2004/06/06 21:13:12 rdonkin Exp $
|
||||
*/
|
||||
public class NoOpLog implements Log, Serializable {
|
||||
private static final long serialVersionUID = 561423906191706148L;
|
||||
private static final long serialVersionUID = 561423906191706148L;
|
||||
|
||||
/** Convenience constructor */
|
||||
public NoOpLog() {
|
||||
}
|
||||
/** Convenience constructor */
|
||||
public NoOpLog() {
|
||||
}
|
||||
|
||||
/** Base constructor */
|
||||
public NoOpLog(String name) {
|
||||
}
|
||||
/** Base constructor */
|
||||
public NoOpLog(String name) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void trace(Object message) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void trace(Object message) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void trace(Object message, Throwable t) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void trace(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void debug(Object message) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void debug(Object message) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void debug(Object message, Throwable t) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void debug(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void info(Object message) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void info(Object message) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void info(Object message, Throwable t) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void info(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void warn(Object message) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void warn(Object message) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void warn(Object message, Throwable t) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void warn(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void error(Object message) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void error(Object message) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void error(Object message, Throwable t) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void error(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void fatal(Object message) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void fatal(Object message) {
|
||||
}
|
||||
|
||||
/** Do nothing */
|
||||
public void fatal(Object message, Throwable t) {
|
||||
}
|
||||
/** Do nothing */
|
||||
public void fatal(Object message, Throwable t) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isDebugEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Debug is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isDebugEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isErrorEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Error is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isErrorEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fatal is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isFatalEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Fatal is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isFatalEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Info is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isInfoEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Info is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isInfoEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trace is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Trace is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warn is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isWarnEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Warn is never enabled.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isWarnEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,231 +36,219 @@ import org.slf4j.spi.LocationAwareLogger;
|
|||
*/
|
||||
public class SLF4JLocationAwareLog implements Log, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2379157579039314822L;
|
||||
private static final long serialVersionUID = -2379157579039314822L;
|
||||
|
||||
// used to store this logger's name to recreate it after serialization
|
||||
protected String name;
|
||||
// used to store this logger's name to recreate it after serialization
|
||||
protected String name;
|
||||
|
||||
// in both Log4jLogger and Jdk14Logger classes in the original JCL, the
|
||||
// logger instance is transient
|
||||
private transient LocationAwareLogger logger;
|
||||
// in both Log4jLogger and Jdk14Logger classes in the original JCL, the
|
||||
// logger instance is transient
|
||||
private transient LocationAwareLogger logger;
|
||||
|
||||
private static final String FQCN = SLF4JLocationAwareLog.class.getName();
|
||||
private static final String FQCN = SLF4JLocationAwareLog.class.getName();
|
||||
|
||||
SLF4JLocationAwareLog(LocationAwareLogger logger) {
|
||||
this.logger = logger;
|
||||
this.name = logger.getName();
|
||||
}
|
||||
SLF4JLocationAwareLog(LocationAwareLogger logger) {
|
||||
this.logger = logger;
|
||||
this.name = logger.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the <code>isTraceEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isTraceEnabled() {
|
||||
return logger.isTraceEnabled();
|
||||
}
|
||||
/**
|
||||
* Delegates to the <code>isTraceEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isTraceEnabled() {
|
||||
return logger.isTraceEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isDebugEnabled() {
|
||||
return logger.isDebugEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isDebugEnabled() {
|
||||
return logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isInfoEnabled() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isInfoEnabled() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isWarnEnabled() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isWarnEnabled() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isErrorEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isErrorEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the <code>isErrorEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isFatalEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
/**
|
||||
* Delegates to the <code>isErrorEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isFatalEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the debug
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void trace(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String
|
||||
.valueOf(message), null, null);
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the debug
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void trace(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* debug method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void trace(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String
|
||||
.valueOf(message), null, t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* debug method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void trace(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void debug(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String
|
||||
.valueOf(message), null, null);
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void debug(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void debug(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String
|
||||
.valueOf(message), null, t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void debug(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void info(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String
|
||||
.valueOf(message), null, null);
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void info(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void info(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String
|
||||
.valueOf(message), null, t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void info(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void warn(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String
|
||||
.valueOf(message), null, null);
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void warn(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void warn(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String
|
||||
.valueOf(message), null, t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void warn(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void error(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
|
||||
.valueOf(message), null, null);
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void error(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void error(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
|
||||
.valueOf(message), null, t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void error(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the error
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void fatal(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
|
||||
.valueOf(message), null, null);
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the error
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void fatal(Object message) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* error method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void fatal(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
|
||||
.valueOf(message), null, t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* error method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void fatal(Object message, Throwable t) {
|
||||
logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace this instance with a homonymous (same name) logger returned by
|
||||
* LoggerFactory. Note that this method is only called during deserialization.
|
||||
*
|
||||
* @return logger with same name as returned by LoggerFactory
|
||||
* @throws ObjectStreamException
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException {
|
||||
Logger logger = LoggerFactory.getLogger(this.name);
|
||||
return new SLF4JLocationAwareLog((LocationAwareLogger) logger);
|
||||
}
|
||||
/**
|
||||
* Replace this instance with a homonymous (same name) logger returned by
|
||||
* LoggerFactory. Note that this method is only called during deserialization.
|
||||
*
|
||||
* @return logger with same name as returned by LoggerFactory
|
||||
* @throws ObjectStreamException
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException {
|
||||
Logger logger = LoggerFactory.getLogger(this.name);
|
||||
return new SLF4JLocationAwareLog((LocationAwareLogger) logger);
|
||||
}
|
||||
}
|
||||
|
|
@ -35,217 +35,217 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public class SLF4JLog implements Log, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 680728617011167209L;
|
||||
private static final long serialVersionUID = 680728617011167209L;
|
||||
|
||||
// used to store this logger's name to recreate it after serialization
|
||||
protected String name;
|
||||
// used to store this logger's name to recreate it after serialization
|
||||
protected String name;
|
||||
|
||||
// in both Log4jLogger and Jdk14Logger classes in the original JCL, the
|
||||
// logger instance is transient
|
||||
private transient Logger logger;
|
||||
// in both Log4jLogger and Jdk14Logger classes in the original JCL, the
|
||||
// logger instance is transient
|
||||
private transient Logger logger;
|
||||
|
||||
SLF4JLog(Logger logger) {
|
||||
this.logger = logger;
|
||||
this.name = logger.getName();
|
||||
}
|
||||
SLF4JLog(Logger logger) {
|
||||
this.logger = logger;
|
||||
this.name = logger.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isDebugEnabled() {
|
||||
return logger.isDebugEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isDebugEnabled() {
|
||||
return logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isErrorEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isErrorEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the <code>isErrorEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isFatalEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
/**
|
||||
* Delegates to the <code>isErrorEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isFatalEnabled() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isInfoEnabled() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isInfoEnabled() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to the <code>isDebugEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isTraceEnabled() {
|
||||
return logger.isTraceEnabled();
|
||||
}
|
||||
/**
|
||||
* Delegates to the <code>isDebugEnabled<code> method of the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isTraceEnabled() {
|
||||
return logger.isTraceEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isWarnEnabled() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
/**
|
||||
* Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*/
|
||||
public boolean isWarnEnabled() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the debug
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void trace(Object message) {
|
||||
logger.trace(String.valueOf(message));
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the debug
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void trace(Object message) {
|
||||
logger.trace(String.valueOf(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* debug method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void trace(Object message, Throwable t) {
|
||||
logger.trace(String.valueOf(message), t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* debug method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void trace(Object message, Throwable t) {
|
||||
logger.trace(String.valueOf(message), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void debug(Object message) {
|
||||
logger.debug(String.valueOf(message));
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void debug(Object message) {
|
||||
logger.debug(String.valueOf(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void debug(Object message, Throwable t) {
|
||||
logger.debug(String.valueOf(message), t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void debug(Object message, Throwable t) {
|
||||
logger.debug(String.valueOf(message), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void info(Object message) {
|
||||
logger.info(String.valueOf(message));
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void info(Object message) {
|
||||
logger.info(String.valueOf(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void info(Object message, Throwable t) {
|
||||
logger.info(String.valueOf(message), t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void info(Object message, Throwable t) {
|
||||
logger.info(String.valueOf(message), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void warn(Object message) {
|
||||
logger.warn(String.valueOf(message));
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void warn(Object message) {
|
||||
logger.warn(String.valueOf(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void warn(Object message, Throwable t) {
|
||||
logger.warn(String.valueOf(message), t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void warn(Object message, Throwable t) {
|
||||
logger.warn(String.valueOf(message), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void error(Object message) {
|
||||
logger.error(String.valueOf(message));
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the wrapped
|
||||
* <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void error(Object message) {
|
||||
logger.error(String.valueOf(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void error(Object message, Throwable t) {
|
||||
logger.error(String.valueOf(message), t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void error(Object message, Throwable t) {
|
||||
logger.error(String.valueOf(message), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the error
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void fatal(Object message) {
|
||||
logger.error(String.valueOf(message));
|
||||
}
|
||||
/**
|
||||
* Converts the input parameter to String and then delegates to the error
|
||||
* method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
*/
|
||||
public void fatal(Object message) {
|
||||
logger.error(String.valueOf(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* error method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void fatal(Object message, Throwable t) {
|
||||
logger.error(String.valueOf(message), t);
|
||||
}
|
||||
/**
|
||||
* Converts the first input parameter to String and then delegates to the
|
||||
* error method of the wrapped <code>org.slf4j.Logger</code> instance.
|
||||
*
|
||||
* @param message
|
||||
* the message to log. Converted to {@link String}
|
||||
* @param t
|
||||
* the exception to log
|
||||
*/
|
||||
public void fatal(Object message, Throwable t) {
|
||||
logger.error(String.valueOf(message), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace this instance with a homonymous (same name) logger returned by
|
||||
* LoggerFactory. Note that this method is only called during deserialization.
|
||||
*
|
||||
* @return logger with same name as returned by LoggerFactory
|
||||
* @throws ObjectStreamException
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException {
|
||||
Logger logger = LoggerFactory.getLogger(this.name);
|
||||
return new SLF4JLog(logger);
|
||||
}
|
||||
/**
|
||||
* Replace this instance with a homonymous (same name) logger returned by
|
||||
* LoggerFactory. Note that this method is only called during deserialization.
|
||||
*
|
||||
* @return logger with same name as returned by LoggerFactory
|
||||
* @throws ObjectStreamException
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException {
|
||||
Logger logger = LoggerFactory.getLogger(this.name);
|
||||
return new SLF4JLog(logger);
|
||||
}
|
||||
}
|
||||
|
|
@ -52,170 +52,168 @@ import java.util.concurrent.ConcurrentMap;
|
|||
@SuppressWarnings("rawtypes")
|
||||
public class SLF4JLogFactory extends LogFactory {
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
/**
|
||||
* The {@link org.apache.commons.logging.Log}instances that have already been
|
||||
* created, keyed by logger name.
|
||||
*/
|
||||
ConcurrentMap<String, Log> loggerMap;
|
||||
/**
|
||||
* The {@link org.apache.commons.logging.Log}instances that have already been
|
||||
* created, keyed by logger name.
|
||||
*/
|
||||
ConcurrentMap<String, Log> loggerMap;
|
||||
|
||||
/**
|
||||
* Public no-arguments constructor required by the lookup mechanism.
|
||||
*/
|
||||
public SLF4JLogFactory() {
|
||||
loggerMap = new ConcurrentHashMap<String, Log>();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- Manifest Constants
|
||||
|
||||
/**
|
||||
* The name of the system property identifying our {@link Log}implementation
|
||||
* class.
|
||||
*/
|
||||
public static final String LOG_PROPERTY = "org.apache.commons.logging.Log";
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* Configuration attributes.
|
||||
*/
|
||||
protected Hashtable attributes = new Hashtable();
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Return the configuration attribute with the specified name (if any), or
|
||||
* <code>null</code> if there is no such attribute.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to return
|
||||
*/
|
||||
public Object getAttribute(String name) {
|
||||
|
||||
return (attributes.get(name));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing the names of all currently defined configuration
|
||||
* attributes. If there are no such attributes, a zero length array is
|
||||
* returned.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String[] getAttributeNames() {
|
||||
|
||||
List<String> names = new ArrayList<String>();
|
||||
Enumeration<String> keys = attributes.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
names.add((String) keys.nextElement());
|
||||
}
|
||||
String results[] = new String[names.size()];
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
results[i] = (String) names.get(i);
|
||||
}
|
||||
return (results);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to derive a name from the specified class and call
|
||||
* <code>getInstance(String)</code> with it.
|
||||
*
|
||||
* @param clazz
|
||||
* Class for which a suitable Log name will be derived
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be returned
|
||||
*/
|
||||
public Log getInstance(Class clazz) throws LogConfigurationException {
|
||||
return (getInstance(clazz.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Construct (if necessary) and return a <code>Log</code> instance, using
|
||||
* the factory's current set of configuration attributes.
|
||||
* </p>
|
||||
*
|
||||
* @param name
|
||||
* Logical name of the <code>Log</code> instance to be returned
|
||||
* (the meaning of this name is only known to the underlying logging
|
||||
* implementation that is being wrapped)
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be returned
|
||||
*/
|
||||
public Log getInstance(String name) throws LogConfigurationException {
|
||||
Log instance = loggerMap.get(name);
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
} else {
|
||||
Log newInstance;
|
||||
Logger slf4jLogger = LoggerFactory.getLogger(name);
|
||||
if (slf4jLogger instanceof LocationAwareLogger) {
|
||||
newInstance = new SLF4JLocationAwareLog((LocationAwareLogger) slf4jLogger);
|
||||
} else {
|
||||
newInstance = new SLF4JLog(slf4jLogger);
|
||||
}
|
||||
Log oldInstance = loggerMap.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release any internal references to previously created
|
||||
* {@link org.apache.commons.logging.Log}instances returned by this factory.
|
||||
* This is useful in environments like servlet containers, which implement
|
||||
* application reloading by throwing away a ClassLoader. Dangling references
|
||||
* to objects in that class loader would prevent garbage collection.
|
||||
*/
|
||||
public void release() {
|
||||
// This method is never called by jcl-over-slf4j classes. However,
|
||||
// in certain deployment scenarios, in particular if jcl-over-slf4j.jar
|
||||
// is
|
||||
// in the the web-app class loader and the official commons-logging.jar is
|
||||
// deployed in some parent class loader (e.g. commons/lib), then it is
|
||||
// possible
|
||||
// for the parent class loader to mask the classes shipping in
|
||||
// jcl-over-slf4j.jar.
|
||||
System.out.println("WARN: The method " + SLF4JLogFactory.class
|
||||
+ "#release() was invoked.");
|
||||
System.out
|
||||
.println("WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.");
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any configuration attribute associated with the specified name. If
|
||||
* there is no such attribute, no action is taken.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to remove
|
||||
*/
|
||||
public void removeAttribute(String name) {
|
||||
attributes.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the configuration attribute with the specified name. Calling this with
|
||||
* a <code>null</code> value is equivalent to calling
|
||||
* <code>removeAttribute(name)</code>.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to set
|
||||
* @param value
|
||||
* Value of the attribute to set, or <code>null</code> to remove
|
||||
* any setting for this attribute
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setAttribute(String name, Object value) {
|
||||
|
||||
if (value == null) {
|
||||
attributes.remove(name);
|
||||
} else {
|
||||
attributes.put(name, value);
|
||||
/**
|
||||
* Public no-arguments constructor required by the lookup mechanism.
|
||||
*/
|
||||
public SLF4JLogFactory() {
|
||||
loggerMap = new ConcurrentHashMap<String, Log>();
|
||||
}
|
||||
|
||||
}
|
||||
// ----------------------------------------------------- Manifest Constants
|
||||
|
||||
/**
|
||||
* The name of the system property identifying our {@link Log}implementation
|
||||
* class.
|
||||
*/
|
||||
public static final String LOG_PROPERTY = "org.apache.commons.logging.Log";
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* Configuration attributes.
|
||||
*/
|
||||
protected Hashtable attributes = new Hashtable();
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Return the configuration attribute with the specified name (if any), or
|
||||
* <code>null</code> if there is no such attribute.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to return
|
||||
*/
|
||||
public Object getAttribute(String name) {
|
||||
|
||||
return (attributes.get(name));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing the names of all currently defined configuration
|
||||
* attributes. If there are no such attributes, a zero length array is
|
||||
* returned.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String[] getAttributeNames() {
|
||||
|
||||
List<String> names = new ArrayList<String>();
|
||||
Enumeration<String> keys = attributes.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
names.add((String) keys.nextElement());
|
||||
}
|
||||
String results[] = new String[names.size()];
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
results[i] = (String) names.get(i);
|
||||
}
|
||||
return (results);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to derive a name from the specified class and call
|
||||
* <code>getInstance(String)</code> with it.
|
||||
*
|
||||
* @param clazz
|
||||
* Class for which a suitable Log name will be derived
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be returned
|
||||
*/
|
||||
public Log getInstance(Class clazz) throws LogConfigurationException {
|
||||
return (getInstance(clazz.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Construct (if necessary) and return a <code>Log</code> instance, using
|
||||
* the factory's current set of configuration attributes.
|
||||
* </p>
|
||||
*
|
||||
* @param name
|
||||
* Logical name of the <code>Log</code> instance to be returned
|
||||
* (the meaning of this name is only known to the underlying logging
|
||||
* implementation that is being wrapped)
|
||||
*
|
||||
* @exception LogConfigurationException
|
||||
* if a suitable <code>Log</code> instance cannot be returned
|
||||
*/
|
||||
public Log getInstance(String name) throws LogConfigurationException {
|
||||
Log instance = loggerMap.get(name);
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
} else {
|
||||
Log newInstance;
|
||||
Logger slf4jLogger = LoggerFactory.getLogger(name);
|
||||
if (slf4jLogger instanceof LocationAwareLogger) {
|
||||
newInstance = new SLF4JLocationAwareLog((LocationAwareLogger) slf4jLogger);
|
||||
} else {
|
||||
newInstance = new SLF4JLog(slf4jLogger);
|
||||
}
|
||||
Log oldInstance = loggerMap.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release any internal references to previously created
|
||||
* {@link org.apache.commons.logging.Log}instances returned by this factory.
|
||||
* This is useful in environments like servlet containers, which implement
|
||||
* application reloading by throwing away a ClassLoader. Dangling references
|
||||
* to objects in that class loader would prevent garbage collection.
|
||||
*/
|
||||
public void release() {
|
||||
// This method is never called by jcl-over-slf4j classes. However,
|
||||
// in certain deployment scenarios, in particular if jcl-over-slf4j.jar
|
||||
// is
|
||||
// in the the web-app class loader and the official commons-logging.jar is
|
||||
// deployed in some parent class loader (e.g. commons/lib), then it is
|
||||
// possible
|
||||
// for the parent class loader to mask the classes shipping in
|
||||
// jcl-over-slf4j.jar.
|
||||
System.out.println("WARN: The method " + SLF4JLogFactory.class + "#release() was invoked.");
|
||||
System.out.println("WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.");
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any configuration attribute associated with the specified name. If
|
||||
* there is no such attribute, no action is taken.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to remove
|
||||
*/
|
||||
public void removeAttribute(String name) {
|
||||
attributes.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the configuration attribute with the specified name. Calling this with
|
||||
* a <code>null</code> value is equivalent to calling
|
||||
* <code>removeAttribute(name)</code>.
|
||||
*
|
||||
* @param name
|
||||
* Name of the attribute to set
|
||||
* @param value
|
||||
* Value of the attribute to set, or <code>null</code> to remove
|
||||
* any setting for this attribute
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setAttribute(String name, Object value) {
|
||||
|
||||
if (value == null) {
|
||||
attributes.remove(name);
|
||||
} else {
|
||||
attributes.put(name, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -27,59 +27,57 @@ package org.apache.commons.logging;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
public class InvokeJCLTest extends TestCase {
|
||||
|
||||
public void testIsEnabledAPI() {
|
||||
// assume that we are running over slf4j-jdk14
|
||||
Log log = LogFactory.getLog(InvokeJCLTest.class);
|
||||
assertFalse(log.isTraceEnabled());
|
||||
assertFalse(log.isDebugEnabled());
|
||||
assertTrue(log.isInfoEnabled());
|
||||
assertTrue(log.isWarnEnabled());
|
||||
assertTrue(log.isErrorEnabled());
|
||||
assertTrue(log.isFatalEnabled());
|
||||
}
|
||||
public void testIsEnabledAPI() {
|
||||
// assume that we are running over slf4j-jdk14
|
||||
Log log = LogFactory.getLog(InvokeJCLTest.class);
|
||||
assertFalse(log.isTraceEnabled());
|
||||
assertFalse(log.isDebugEnabled());
|
||||
assertTrue(log.isInfoEnabled());
|
||||
assertTrue(log.isWarnEnabled());
|
||||
assertTrue(log.isErrorEnabled());
|
||||
assertTrue(log.isFatalEnabled());
|
||||
}
|
||||
|
||||
public void testPrintAPI() {
|
||||
Log log = LogFactory.getLog(InvokeJCLTest.class);
|
||||
Exception e = new Exception("just testing");
|
||||
public void testPrintAPI() {
|
||||
Log log = LogFactory.getLog(InvokeJCLTest.class);
|
||||
Exception e = new Exception("just testing");
|
||||
|
||||
log.trace(null);
|
||||
log.trace("trace message");
|
||||
log.trace(null);
|
||||
log.trace("trace message");
|
||||
|
||||
log.debug(null);
|
||||
log.debug("debug message");
|
||||
log.debug(null);
|
||||
log.debug("debug message");
|
||||
|
||||
log.info(null);
|
||||
log.info("info message");
|
||||
log.info(null);
|
||||
log.info("info message");
|
||||
|
||||
log.warn(null);
|
||||
log.warn("warn message");
|
||||
log.warn(null);
|
||||
log.warn("warn message");
|
||||
|
||||
log.error(null);
|
||||
log.error("error message");
|
||||
log.error(null);
|
||||
log.error("error message");
|
||||
|
||||
log.fatal(null);
|
||||
log.fatal("fatal message");
|
||||
log.fatal(null);
|
||||
log.fatal("fatal message");
|
||||
|
||||
log.trace(null, e);
|
||||
log.trace("trace message", e);
|
||||
|
||||
log.trace(null, e);
|
||||
log.trace("trace message", e);
|
||||
log.debug(null, e);
|
||||
log.debug("debug message", e);
|
||||
|
||||
log.debug(null, e);
|
||||
log.debug("debug message", e);
|
||||
log.info(null, e);
|
||||
log.info("info message", e);
|
||||
|
||||
log.info(null, e);
|
||||
log.info("info message", e);
|
||||
log.warn(null, e);
|
||||
log.warn("warn message", e);
|
||||
|
||||
log.warn(null, e);
|
||||
log.warn("warn message", e);
|
||||
log.error(null, e);
|
||||
log.error("error message", e);
|
||||
|
||||
log.error(null, e);
|
||||
log.error("error message", e);
|
||||
|
||||
log.fatal(null, e);
|
||||
log.fatal("fatal message", e);
|
||||
}
|
||||
log.fatal(null, e);
|
||||
log.fatal("fatal message", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,52 +39,51 @@ import org.slf4j.spi.LocationAwareLogger;
|
|||
|
||||
public class SerializationTest extends TestCase {
|
||||
|
||||
ObjectInputStream ois;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos;
|
||||
ObjectInputStream ois;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos;
|
||||
|
||||
public SerializationTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
public SerializationTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
oos = new ObjectOutputStream(baos);
|
||||
super.setUp();
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
oos = new ObjectOutputStream(baos);
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
oos.close();
|
||||
}
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
oos.close();
|
||||
}
|
||||
|
||||
public void verify() throws IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
|
||||
ois = new ObjectInputStream(bis);
|
||||
public void verify() throws IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
|
||||
ois = new ObjectInputStream(bis);
|
||||
|
||||
Log resuscitatedLog = (Log) ois.readObject();
|
||||
// tests that the "private transient Logger logger" field is non-null
|
||||
resuscitatedLog.debug("");
|
||||
resuscitatedLog.isDebugEnabled();
|
||||
}
|
||||
Log resuscitatedLog = (Log) ois.readObject();
|
||||
// tests that the "private transient Logger logger" field is non-null
|
||||
resuscitatedLog.debug("");
|
||||
resuscitatedLog.isDebugEnabled();
|
||||
}
|
||||
|
||||
public void testSLF4JLog() throws Exception {
|
||||
JDK14LoggerFactory factory = new JDK14LoggerFactory();
|
||||
SLF4JLog log = new SLF4JLog(factory.getLogger("x"));
|
||||
oos.writeObject(log);
|
||||
verify();
|
||||
}
|
||||
public void testSLF4JLog() throws Exception {
|
||||
JDK14LoggerFactory factory = new JDK14LoggerFactory();
|
||||
SLF4JLog log = new SLF4JLog(factory.getLogger("x"));
|
||||
oos.writeObject(log);
|
||||
verify();
|
||||
}
|
||||
|
||||
public void testSmoke() throws Exception {
|
||||
Log log = LogFactory.getLog("testing");
|
||||
oos.writeObject(log);
|
||||
verify();
|
||||
}
|
||||
public void testSmoke() throws Exception {
|
||||
Log log = LogFactory.getLog("testing");
|
||||
oos.writeObject(log);
|
||||
verify();
|
||||
}
|
||||
|
||||
public void testLocationAware() throws Exception {
|
||||
JDK14LoggerFactory factory = new JDK14LoggerFactory();
|
||||
SLF4JLocationAwareLog log = new SLF4JLocationAwareLog(
|
||||
(LocationAwareLogger) factory.getLogger("x"));
|
||||
oos.writeObject(log);
|
||||
verify();
|
||||
}
|
||||
public void testLocationAware() throws Exception {
|
||||
JDK14LoggerFactory factory = new JDK14LoggerFactory();
|
||||
SLF4JLocationAwareLog log = new SLF4JLocationAwareLog((LocationAwareLogger) factory.getLogger("x"));
|
||||
oos.writeObject(log);
|
||||
verify();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,210 +98,206 @@ import org.slf4j.spi.LocationAwareLogger;
|
|||
*/
|
||||
public class SLF4JBridgeHandler extends Handler {
|
||||
|
||||
// The caller is java.util.logging.Logger
|
||||
private static final String FQCN = java.util.logging.Logger.class.getName();
|
||||
private static final String UNKNOWN_LOGGER_NAME = "unknown.jul.logger";
|
||||
// The caller is java.util.logging.Logger
|
||||
private static final String FQCN = java.util.logging.Logger.class.getName();
|
||||
private static final String UNKNOWN_LOGGER_NAME = "unknown.jul.logger";
|
||||
|
||||
private static final int TRACE_LEVEL_THRESHOLD = Level.FINEST.intValue();
|
||||
private static final int DEBUG_LEVEL_THRESHOLD = Level.FINE.intValue();
|
||||
private static final int INFO_LEVEL_THRESHOLD = Level.INFO.intValue();
|
||||
private static final int WARN_LEVEL_THRESHOLD = Level.WARNING.intValue();
|
||||
private static final int TRACE_LEVEL_THRESHOLD = Level.FINEST.intValue();
|
||||
private static final int DEBUG_LEVEL_THRESHOLD = Level.FINE.intValue();
|
||||
private static final int INFO_LEVEL_THRESHOLD = Level.INFO.intValue();
|
||||
private static final int WARN_LEVEL_THRESHOLD = Level.WARNING.intValue();
|
||||
|
||||
/**
|
||||
* Adds a SLF4JBridgeHandler instance to jul's root logger.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* This handler will redirect j.u.l. logging to SLF4J. However, only logs enabled
|
||||
* in j.u.l. will be redirected. For example, if a log statement invoking a
|
||||
* j.u.l. logger is disabled, then the corresponding non-event will <em>not</em>
|
||||
* reach SLF4JBridgeHandler and cannot be redirected.
|
||||
*/
|
||||
public static void install() {
|
||||
LogManager.getLogManager().getLogger("").addHandler(
|
||||
new SLF4JBridgeHandler());
|
||||
}
|
||||
|
||||
private static java.util.logging.Logger getRootLogger() {
|
||||
return LogManager.getLogManager().getLogger("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes previously installed SLF4JBridgeHandler instances. See also
|
||||
* {@link #install()}.
|
||||
*
|
||||
* @throws SecurityException A <code>SecurityException</code> is thrown, if a security manager
|
||||
* exists and if the caller does not have
|
||||
* LoggingPermission("control").
|
||||
*/
|
||||
public static void uninstall() throws SecurityException {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (handlers[i] instanceof SLF4JBridgeHandler) {
|
||||
rootLogger.removeHandler(handlers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.
|
||||
*
|
||||
* @return true if SLF4JBridgeHandler is already installed, false other wise
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public static boolean isInstalled() throws SecurityException {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (handlers[i] instanceof SLF4JBridgeHandler) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoking this method removes/unregisters/detaches all handlers currently attached to the root logger
|
||||
* @since 1.6.5
|
||||
*/
|
||||
public static void removeHandlersForRootLogger() {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
java.util.logging.Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
rootLogger.removeHandler(handlers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize this handler.
|
||||
*/
|
||||
public SLF4JBridgeHandler() {
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op implementation.
|
||||
*/
|
||||
public void close() {
|
||||
// empty
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op implementation.
|
||||
*/
|
||||
public void flush() {
|
||||
// empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Logger instance that will be used for logging.
|
||||
*/
|
||||
protected Logger getSLF4JLogger(LogRecord record) {
|
||||
String name = record.getLoggerName();
|
||||
if (name == null) {
|
||||
name = UNKNOWN_LOGGER_NAME;
|
||||
}
|
||||
return LoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
protected void callLocationAwareLogger(LocationAwareLogger lal,
|
||||
LogRecord record) {
|
||||
int julLevelValue = record.getLevel().intValue();
|
||||
int slf4jLevel;
|
||||
|
||||
if (julLevelValue <= TRACE_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.TRACE_INT;
|
||||
} else if (julLevelValue <= DEBUG_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.DEBUG_INT;
|
||||
} else if (julLevelValue <= INFO_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.INFO_INT;
|
||||
} else if (julLevelValue <= WARN_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.WARN_INT;
|
||||
} else {
|
||||
slf4jLevel = LocationAwareLogger.ERROR_INT;
|
||||
}
|
||||
String i18nMessage = getMessageI18N(record);
|
||||
lal.log(null, FQCN, slf4jLevel, i18nMessage, null, record.getThrown());
|
||||
}
|
||||
|
||||
protected void callPlainSLF4JLogger(Logger slf4jLogger, LogRecord record) {
|
||||
String i18nMessage = getMessageI18N(record);
|
||||
int julLevelValue = record.getLevel().intValue();
|
||||
if (julLevelValue <= TRACE_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.trace(i18nMessage, record.getThrown());
|
||||
} else if (julLevelValue <= DEBUG_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.debug(i18nMessage, record.getThrown());
|
||||
} else if (julLevelValue <= INFO_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.info(i18nMessage, record.getThrown());
|
||||
} else if (julLevelValue <= WARN_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.warn(i18nMessage, record.getThrown());
|
||||
} else {
|
||||
slf4jLogger.error(i18nMessage, record.getThrown());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the record's message, possibly via a resource bundle.
|
||||
*
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
private String getMessageI18N(LogRecord record) {
|
||||
String message = record.getMessage();
|
||||
|
||||
if (message == null) {
|
||||
return null;
|
||||
/**
|
||||
* Adds a SLF4JBridgeHandler instance to jul's root logger.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* This handler will redirect j.u.l. logging to SLF4J. However, only logs enabled
|
||||
* in j.u.l. will be redirected. For example, if a log statement invoking a
|
||||
* j.u.l. logger is disabled, then the corresponding non-event will <em>not</em>
|
||||
* reach SLF4JBridgeHandler and cannot be redirected.
|
||||
*/
|
||||
public static void install() {
|
||||
LogManager.getLogManager().getLogger("").addHandler(new SLF4JBridgeHandler());
|
||||
}
|
||||
|
||||
ResourceBundle bundle = record.getResourceBundle();
|
||||
if (bundle != null) {
|
||||
try {
|
||||
message = bundle.getString(message);
|
||||
} catch (MissingResourceException e) {
|
||||
}
|
||||
}
|
||||
Object[] params = record.getParameters();
|
||||
// avoid formatting when there are no or 0 parameters. see also
|
||||
// http://bugzilla.slf4j.org/show_bug.cgi?id=212
|
||||
if (params != null && params.length > 0) {
|
||||
message = MessageFormat.format(message, params);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a LogRecord.
|
||||
* <p/>
|
||||
* The logging request was made initially to a Logger object, which
|
||||
* initialized the LogRecord and forwarded it here.
|
||||
* <p/>
|
||||
* This handler ignores the Level attached to the LogRecord, as SLF4J cares
|
||||
* about discarding log statements.
|
||||
*
|
||||
* @param record Description of the log event. A null record is silently ignored
|
||||
* and is not published.
|
||||
*/
|
||||
public void publish(LogRecord record) {
|
||||
// Silently ignore null records.
|
||||
if (record == null) {
|
||||
return;
|
||||
private static java.util.logging.Logger getRootLogger() {
|
||||
return LogManager.getLogManager().getLogger("");
|
||||
}
|
||||
|
||||
Logger slf4jLogger = getSLF4JLogger(record);
|
||||
String message = record.getMessage(); // can be null!
|
||||
// this is a check to avoid calling the underlying logging system
|
||||
// with a null message. While it is legitimate to invoke j.u.l. with
|
||||
// a null message, other logging frameworks do not support this.
|
||||
// see also http://bugzilla.slf4j.org/show_bug.cgi?id=108
|
||||
if (message == null) {
|
||||
message = "";
|
||||
/**
|
||||
* Removes previously installed SLF4JBridgeHandler instances. See also
|
||||
* {@link #install()}.
|
||||
*
|
||||
* @throws SecurityException A <code>SecurityException</code> is thrown, if a security manager
|
||||
* exists and if the caller does not have
|
||||
* LoggingPermission("control").
|
||||
*/
|
||||
public static void uninstall() throws SecurityException {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (handlers[i] instanceof SLF4JBridgeHandler) {
|
||||
rootLogger.removeHandler(handlers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (slf4jLogger instanceof LocationAwareLogger) {
|
||||
callLocationAwareLogger((LocationAwareLogger) slf4jLogger, record);
|
||||
} else {
|
||||
callPlainSLF4JLogger(slf4jLogger, record);
|
||||
|
||||
/**
|
||||
* Returns true if SLF4JBridgeHandler has been previously installed, returns false otherwise.
|
||||
*
|
||||
* @return true if SLF4JBridgeHandler is already installed, false other wise
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public static boolean isInstalled() throws SecurityException {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
if (handlers[i] instanceof SLF4JBridgeHandler) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoking this method removes/unregisters/detaches all handlers currently attached to the root logger
|
||||
* @since 1.6.5
|
||||
*/
|
||||
public static void removeHandlersForRootLogger() {
|
||||
java.util.logging.Logger rootLogger = getRootLogger();
|
||||
java.util.logging.Handler[] handlers = rootLogger.getHandlers();
|
||||
for (int i = 0; i < handlers.length; i++) {
|
||||
rootLogger.removeHandler(handlers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this handler.
|
||||
*/
|
||||
public SLF4JBridgeHandler() {
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op implementation.
|
||||
*/
|
||||
public void close() {
|
||||
// empty
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op implementation.
|
||||
*/
|
||||
public void flush() {
|
||||
// empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Logger instance that will be used for logging.
|
||||
*/
|
||||
protected Logger getSLF4JLogger(LogRecord record) {
|
||||
String name = record.getLoggerName();
|
||||
if (name == null) {
|
||||
name = UNKNOWN_LOGGER_NAME;
|
||||
}
|
||||
return LoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
protected void callLocationAwareLogger(LocationAwareLogger lal, LogRecord record) {
|
||||
int julLevelValue = record.getLevel().intValue();
|
||||
int slf4jLevel;
|
||||
|
||||
if (julLevelValue <= TRACE_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.TRACE_INT;
|
||||
} else if (julLevelValue <= DEBUG_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.DEBUG_INT;
|
||||
} else if (julLevelValue <= INFO_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.INFO_INT;
|
||||
} else if (julLevelValue <= WARN_LEVEL_THRESHOLD) {
|
||||
slf4jLevel = LocationAwareLogger.WARN_INT;
|
||||
} else {
|
||||
slf4jLevel = LocationAwareLogger.ERROR_INT;
|
||||
}
|
||||
String i18nMessage = getMessageI18N(record);
|
||||
lal.log(null, FQCN, slf4jLevel, i18nMessage, null, record.getThrown());
|
||||
}
|
||||
|
||||
protected void callPlainSLF4JLogger(Logger slf4jLogger, LogRecord record) {
|
||||
String i18nMessage = getMessageI18N(record);
|
||||
int julLevelValue = record.getLevel().intValue();
|
||||
if (julLevelValue <= TRACE_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.trace(i18nMessage, record.getThrown());
|
||||
} else if (julLevelValue <= DEBUG_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.debug(i18nMessage, record.getThrown());
|
||||
} else if (julLevelValue <= INFO_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.info(i18nMessage, record.getThrown());
|
||||
} else if (julLevelValue <= WARN_LEVEL_THRESHOLD) {
|
||||
slf4jLogger.warn(i18nMessage, record.getThrown());
|
||||
} else {
|
||||
slf4jLogger.error(i18nMessage, record.getThrown());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the record's message, possibly via a resource bundle.
|
||||
*
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
private String getMessageI18N(LogRecord record) {
|
||||
String message = record.getMessage();
|
||||
|
||||
if (message == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ResourceBundle bundle = record.getResourceBundle();
|
||||
if (bundle != null) {
|
||||
try {
|
||||
message = bundle.getString(message);
|
||||
} catch (MissingResourceException e) {
|
||||
}
|
||||
}
|
||||
Object[] params = record.getParameters();
|
||||
// avoid formatting when there are no or 0 parameters. see also
|
||||
// http://bugzilla.slf4j.org/show_bug.cgi?id=212
|
||||
if (params != null && params.length > 0) {
|
||||
message = MessageFormat.format(message, params);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a LogRecord.
|
||||
* <p/>
|
||||
* The logging request was made initially to a Logger object, which
|
||||
* initialized the LogRecord and forwarded it here.
|
||||
* <p/>
|
||||
* This handler ignores the Level attached to the LogRecord, as SLF4J cares
|
||||
* about discarding log statements.
|
||||
*
|
||||
* @param record Description of the log event. A null record is silently ignored
|
||||
* and is not published.
|
||||
*/
|
||||
public void publish(LogRecord record) {
|
||||
// Silently ignore null records.
|
||||
if (record == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger slf4jLogger = getSLF4JLogger(record);
|
||||
String message = record.getMessage(); // can be null!
|
||||
// this is a check to avoid calling the underlying logging system
|
||||
// with a null message. While it is legitimate to invoke j.u.l. with
|
||||
// a null message, other logging frameworks do not support this.
|
||||
// see also http://bugzilla.slf4j.org/show_bug.cgi?id=108
|
||||
if (message == null) {
|
||||
message = "";
|
||||
}
|
||||
if (slf4jLogger instanceof LocationAwareLogger) {
|
||||
callLocationAwareLogger((LocationAwareLogger) slf4jLogger, record);
|
||||
} else {
|
||||
callPlainSLF4JLogger(slf4jLogger, record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,22 +32,22 @@ import org.apache.log4j.spi.LoggingEvent;
|
|||
|
||||
public class ListAppender extends AppenderSkeleton {
|
||||
|
||||
public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
|
||||
public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
|
||||
|
||||
public boolean extractLocationInfo = false;
|
||||
public boolean extractLocationInfo = false;
|
||||
|
||||
protected void append(LoggingEvent event) {
|
||||
list.add(event);
|
||||
if(extractLocationInfo) {
|
||||
event.getLocationInformation();
|
||||
protected void append(LoggingEvent event) {
|
||||
list.add(event);
|
||||
if (extractLocationInfo) {
|
||||
event.getLocationInformation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
public void close() {
|
||||
}
|
||||
|
||||
public boolean requiresLayout() {
|
||||
return false;
|
||||
}
|
||||
public boolean requiresLayout() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,81 +35,78 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
public class SLF4JBridgeHandlerPerfTest extends TestCase {
|
||||
|
||||
static String LOGGER_NAME = "yay";
|
||||
static int RUN_LENGTH = 100*1000;
|
||||
static String LOGGER_NAME = "yay";
|
||||
static int RUN_LENGTH = 100 * 1000;
|
||||
|
||||
// set to false to test enabled logging performance
|
||||
boolean disabledLogger = true;
|
||||
|
||||
// set to false to test enabled logging performance
|
||||
boolean disabledLogger = true;
|
||||
FileAppender fileAppender;
|
||||
org.apache.log4j.Logger log4jRoot;
|
||||
java.util.logging.Logger julRootLogger = LogManager.getLogManager().getLogger("");
|
||||
|
||||
FileAppender fileAppender;
|
||||
org.apache.log4j.Logger log4jRoot;
|
||||
java.util.logging.Logger julRootLogger = LogManager.getLogManager()
|
||||
.getLogger("");
|
||||
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(LOGGER_NAME);
|
||||
org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger(LOGGER_NAME);
|
||||
|
||||
java.util.logging.Logger julLogger = java.util.logging.Logger
|
||||
.getLogger(LOGGER_NAME);
|
||||
org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger(LOGGER_NAME);
|
||||
Handler[] existingHandlers;
|
||||
|
||||
Handler[] existingHandlers;
|
||||
|
||||
public SLF4JBridgeHandlerPerfTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fileAppender = new FileAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"), "target/test-output/toto.log");
|
||||
|
||||
existingHandlers = julRootLogger.getHandlers();
|
||||
for (int i = 0; i < existingHandlers.length; i++) {
|
||||
julRootLogger.removeHandler(existingHandlers[i]);
|
||||
public SLF4JBridgeHandlerPerfTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
log4jRoot = org.apache.log4j.Logger.getRootLogger();
|
||||
log4jRoot.addAppender(fileAppender);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
SLF4JBridgeHandler.uninstall();
|
||||
fileAppender.close();
|
||||
log4jRoot.getLoggerRepository().resetConfiguration();
|
||||
for (int i = 0; i < existingHandlers.length; i++) {
|
||||
julRootLogger.addHandler(existingHandlers[i]);
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fileAppender = new FileAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"), "target/test-output/toto.log");
|
||||
|
||||
existingHandlers = julRootLogger.getHandlers();
|
||||
for (int i = 0; i < existingHandlers.length; i++) {
|
||||
julRootLogger.removeHandler(existingHandlers[i]);
|
||||
}
|
||||
log4jRoot = org.apache.log4j.Logger.getRootLogger();
|
||||
log4jRoot.addAppender(fileAppender);
|
||||
}
|
||||
}
|
||||
|
||||
double julLoggerLoop() {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < RUN_LENGTH; i++) {
|
||||
julLogger.info("jul");
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
SLF4JBridgeHandler.uninstall();
|
||||
fileAppender.close();
|
||||
log4jRoot.getLoggerRepository().resetConfiguration();
|
||||
for (int i = 0; i < existingHandlers.length; i++) {
|
||||
julRootLogger.addHandler(existingHandlers[i]);
|
||||
}
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start) * 1.0 / RUN_LENGTH;
|
||||
}
|
||||
|
||||
double slf4jLoggerLoop() {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < RUN_LENGTH; i++) {
|
||||
slf4jLogger.info("slf4j");
|
||||
double julLoggerLoop() {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < RUN_LENGTH; i++) {
|
||||
julLogger.info("jul");
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start) * 1.0 / RUN_LENGTH;
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start) * 1.0 / RUN_LENGTH;
|
||||
}
|
||||
|
||||
public void testPerf() {
|
||||
SLF4JBridgeHandler.install();
|
||||
|
||||
if(disabledLogger) {
|
||||
log4jRoot.setLevel(org.apache.log4j.Level.ERROR);
|
||||
double slf4jLoggerLoop() {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < RUN_LENGTH; i++) {
|
||||
slf4jLogger.info("slf4j");
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start) * 1.0 / RUN_LENGTH;
|
||||
}
|
||||
julLoggerLoop();
|
||||
double julAvg=julLoggerLoop();
|
||||
System.out.println("Average cost per call (JUL->SLF4J->log4j): "+julAvg +" nanos");
|
||||
|
||||
slf4jLoggerLoop();
|
||||
double slf4jAvg=slf4jLoggerLoop();
|
||||
System.out.println("Average cost per call (SLF4J->log4j): "+slf4jAvg +" nanos");
|
||||
System.out.println("Ratio "+(julAvg/slf4jAvg));
|
||||
}
|
||||
public void testPerf() {
|
||||
SLF4JBridgeHandler.install();
|
||||
|
||||
if (disabledLogger) {
|
||||
log4jRoot.setLevel(org.apache.log4j.Level.ERROR);
|
||||
}
|
||||
julLoggerLoop();
|
||||
double julAvg = julLoggerLoop();
|
||||
System.out.println("Average cost per call (JUL->SLF4J->log4j): " + julAvg + " nanos");
|
||||
|
||||
slf4jLoggerLoop();
|
||||
double slf4jAvg = slf4jLoggerLoop();
|
||||
System.out.println("Average cost per call (SLF4J->log4j): " + slf4jAvg + " nanos");
|
||||
System.out.println("Ratio " + (julAvg / slf4jAvg));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,152 +35,147 @@ import org.apache.log4j.spi.LoggingEvent;
|
|||
|
||||
public class SLF4JBridgeHandlerTest extends TestCase {
|
||||
|
||||
static String LOGGER_NAME = "yay";
|
||||
static String LOGGER_NAME = "yay";
|
||||
|
||||
ListAppender listAppender = new ListAppender();
|
||||
org.apache.log4j.Logger log4jRoot;
|
||||
java.util.logging.Logger julLogger = java.util.logging.Logger
|
||||
.getLogger("yay");
|
||||
ListAppender listAppender = new ListAppender();
|
||||
org.apache.log4j.Logger log4jRoot;
|
||||
java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("yay");
|
||||
|
||||
public SLF4JBridgeHandlerTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
public SLF4JBridgeHandlerTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
listAppender.extractLocationInfo = true;
|
||||
log4jRoot = org.apache.log4j.Logger.getRootLogger();
|
||||
log4jRoot.addAppender(listAppender);
|
||||
log4jRoot.setLevel(org.apache.log4j.Level.TRACE);
|
||||
}
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
listAppender.extractLocationInfo = true;
|
||||
log4jRoot = org.apache.log4j.Logger.getRootLogger();
|
||||
log4jRoot.addAppender(listAppender);
|
||||
log4jRoot.setLevel(org.apache.log4j.Level.TRACE);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
SLF4JBridgeHandler.uninstall();
|
||||
log4jRoot.getLoggerRepository().resetConfiguration();
|
||||
}
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
SLF4JBridgeHandler.uninstall();
|
||||
log4jRoot.getLoggerRepository().resetConfiguration();
|
||||
}
|
||||
|
||||
public void testSmoke() {
|
||||
SLF4JBridgeHandler.install();
|
||||
String msg = "msg";
|
||||
julLogger.info(msg);
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(msg, le.getMessage());
|
||||
public void testSmoke() {
|
||||
SLF4JBridgeHandler.install();
|
||||
String msg = "msg";
|
||||
julLogger.info(msg);
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(msg, le.getMessage());
|
||||
|
||||
// get the location info in the event.
|
||||
// Note that this must have been computed previously
|
||||
// within an appender for the following assertion to
|
||||
// work properly
|
||||
LocationInfo li = le.getLocationInformation();
|
||||
System.out.println(li.fullInfo);
|
||||
assertEquals("SLF4JBridgeHandlerTest.java", li.getFileName());
|
||||
assertEquals("testSmoke", li.getMethodName());
|
||||
}
|
||||
// get the location info in the event.
|
||||
// Note that this must have been computed previously
|
||||
// within an appender for the following assertion to
|
||||
// work properly
|
||||
LocationInfo li = le.getLocationInformation();
|
||||
System.out.println(li.fullInfo);
|
||||
assertEquals("SLF4JBridgeHandlerTest.java", li.getFileName());
|
||||
assertEquals("testSmoke", li.getMethodName());
|
||||
}
|
||||
|
||||
public void testLevels() {
|
||||
SLF4JBridgeHandler.install();
|
||||
String msg = "msg";
|
||||
julLogger.setLevel(Level.ALL);
|
||||
public void testLevels() {
|
||||
SLF4JBridgeHandler.install();
|
||||
String msg = "msg";
|
||||
julLogger.setLevel(Level.ALL);
|
||||
|
||||
julLogger.finest(msg);
|
||||
julLogger.finer(msg);
|
||||
julLogger.fine(msg);
|
||||
julLogger.info(msg);
|
||||
julLogger.warning(msg);
|
||||
julLogger.severe(msg);
|
||||
julLogger.finest(msg);
|
||||
julLogger.finer(msg);
|
||||
julLogger.fine(msg);
|
||||
julLogger.info(msg);
|
||||
julLogger.warning(msg);
|
||||
julLogger.severe(msg);
|
||||
|
||||
assertEquals(6, listAppender.list.size());
|
||||
int i = 0;
|
||||
assertLevel(i++, org.apache.log4j.Level.TRACE);
|
||||
assertLevel(i++, org.apache.log4j.Level.DEBUG);
|
||||
assertLevel(i++, org.apache.log4j.Level.DEBUG);
|
||||
assertLevel(i++, org.apache.log4j.Level.INFO);
|
||||
assertLevel(i++, org.apache.log4j.Level.WARN);
|
||||
assertLevel(i++, org.apache.log4j.Level.ERROR);
|
||||
}
|
||||
assertEquals(6, listAppender.list.size());
|
||||
int i = 0;
|
||||
assertLevel(i++, org.apache.log4j.Level.TRACE);
|
||||
assertLevel(i++, org.apache.log4j.Level.DEBUG);
|
||||
assertLevel(i++, org.apache.log4j.Level.DEBUG);
|
||||
assertLevel(i++, org.apache.log4j.Level.INFO);
|
||||
assertLevel(i++, org.apache.log4j.Level.WARN);
|
||||
assertLevel(i++, org.apache.log4j.Level.ERROR);
|
||||
}
|
||||
|
||||
public void testLogWithResourceBundle() {
|
||||
SLF4JBridgeHandler.install();
|
||||
public void testLogWithResourceBundle() {
|
||||
SLF4JBridgeHandler.install();
|
||||
|
||||
String resourceBundleName = "org.slf4j.bridge.testLogStrings";
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName);
|
||||
String resourceKey = "resource_key";
|
||||
String expectedMsg = bundle.getString(resourceKey);
|
||||
String msg = resourceKey;
|
||||
String resourceBundleName = "org.slf4j.bridge.testLogStrings";
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName);
|
||||
String resourceKey = "resource_key";
|
||||
String expectedMsg = bundle.getString(resourceKey);
|
||||
String msg = resourceKey;
|
||||
|
||||
java.util.logging.Logger julResourceBundleLogger = java.util.logging.Logger
|
||||
.getLogger("yay", resourceBundleName);
|
||||
java.util.logging.Logger julResourceBundleLogger = java.util.logging.Logger.getLogger("yay", resourceBundleName);
|
||||
|
||||
julResourceBundleLogger.info(msg);
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(expectedMsg, le.getMessage());
|
||||
}
|
||||
julResourceBundleLogger.info(msg);
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(expectedMsg, le.getMessage());
|
||||
}
|
||||
|
||||
public void testLogWithResourceBundleWithParameters() {
|
||||
SLF4JBridgeHandler.install();
|
||||
public void testLogWithResourceBundleWithParameters() {
|
||||
SLF4JBridgeHandler.install();
|
||||
|
||||
String resourceBundleName = "org.slf4j.bridge.testLogStrings";
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName);
|
||||
String resourceBundleName = "org.slf4j.bridge.testLogStrings";
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName);
|
||||
|
||||
java.util.logging.Logger julResourceBundleLogger = java.util.logging.Logger
|
||||
.getLogger("foo", resourceBundleName);
|
||||
java.util.logging.Logger julResourceBundleLogger = java.util.logging.Logger.getLogger("foo", resourceBundleName);
|
||||
|
||||
String resourceKey1 = "resource_key_1";
|
||||
String expectedMsg1 = bundle.getString(resourceKey1);
|
||||
julResourceBundleLogger.info(resourceKey1); // 1st log
|
||||
String resourceKey1 = "resource_key_1";
|
||||
String expectedMsg1 = bundle.getString(resourceKey1);
|
||||
julResourceBundleLogger.info(resourceKey1); // 1st log
|
||||
|
||||
String resourceKey2 = "resource_key_2";
|
||||
Object[] params2 = new Object[] { "foo", "bar" };
|
||||
String expectedMsg2 = MessageFormat.format(bundle.getString(resourceKey2),
|
||||
params2);
|
||||
julResourceBundleLogger.log(Level.INFO, resourceKey2, params2); // 2nd log
|
||||
String resourceKey2 = "resource_key_2";
|
||||
Object[] params2 = new Object[] { "foo", "bar" };
|
||||
String expectedMsg2 = MessageFormat.format(bundle.getString(resourceKey2), params2);
|
||||
julResourceBundleLogger.log(Level.INFO, resourceKey2, params2); // 2nd log
|
||||
|
||||
String resourceKey3 = "invalidKey {0}";
|
||||
Object[] params3 = new Object[] { "John" };
|
||||
String expectedMsg3 = MessageFormat.format(resourceKey3, params3);
|
||||
julResourceBundleLogger.log(Level.INFO, resourceKey3, params3); // 3rd log
|
||||
|
||||
String resourceKey3 = "invalidKey {0}";
|
||||
Object[] params3 = new Object[] { "John" };
|
||||
String expectedMsg3 = MessageFormat.format(resourceKey3, params3);
|
||||
julResourceBundleLogger.log(Level.INFO, resourceKey3, params3); // 3rd log
|
||||
julLogger.log(Level.INFO, resourceKey3, params3); // 4th log
|
||||
|
||||
julLogger.log(Level.INFO, resourceKey3, params3); // 4th log
|
||||
assertEquals(4, listAppender.list.size());
|
||||
|
||||
assertEquals(4, listAppender.list.size());
|
||||
LoggingEvent le = null;
|
||||
|
||||
LoggingEvent le = null;
|
||||
le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg1, le.getMessage());
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg1, le.getMessage());
|
||||
le = (LoggingEvent) listAppender.list.get(1);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg2, le.getMessage());
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(1);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg2, le.getMessage());
|
||||
le = (LoggingEvent) listAppender.list.get(2);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg3, le.getMessage());
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(2);
|
||||
assertEquals("foo", le.getLoggerName());
|
||||
assertEquals(expectedMsg3, le.getMessage());
|
||||
le = (LoggingEvent) listAppender.list.get(3);
|
||||
assertEquals("yay", le.getLoggerName());
|
||||
assertEquals(expectedMsg3, le.getMessage());
|
||||
}
|
||||
|
||||
le = (LoggingEvent) listAppender.list.get(3);
|
||||
assertEquals("yay", le.getLoggerName());
|
||||
assertEquals(expectedMsg3, le.getMessage());
|
||||
}
|
||||
public void testLogWithPlaceholderNoParameters() {
|
||||
SLF4JBridgeHandler.install();
|
||||
String msg = "msg {non-number-string}";
|
||||
julLogger.logp(Level.INFO, "SLF4JBridgeHandlerTest", "testLogWithPlaceholderNoParameters", msg, new Object[0]);
|
||||
|
||||
public void testLogWithPlaceholderNoParameters() {
|
||||
SLF4JBridgeHandler.install();
|
||||
String msg = "msg {non-number-string}";
|
||||
julLogger.logp(Level.INFO, "SLF4JBridgeHandlerTest", "testLogWithPlaceholderNoParameters", msg, new Object[0]);
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(msg, le.getMessage());
|
||||
}
|
||||
|
||||
assertEquals(1, listAppender.list.size());
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
|
||||
assertEquals(LOGGER_NAME, le.getLoggerName());
|
||||
assertEquals(msg, le.getMessage());
|
||||
}
|
||||
|
||||
void assertLevel(int index, org.apache.log4j.Level expectedLevel) {
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(index);
|
||||
assertEquals(expectedLevel, le.getLevel());
|
||||
}
|
||||
void assertLevel(int index, org.apache.log4j.Level expectedLevel) {
|
||||
LoggingEvent le = (LoggingEvent) listAppender.list.get(index);
|
||||
assertEquals(expectedLevel, le.getLevel());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,106 +29,103 @@ import org.apache.log4j.spi.LoggingEvent;
|
|||
*/
|
||||
public interface Appender {
|
||||
|
||||
/**
|
||||
* Add a filter to the end of the filter list.
|
||||
*
|
||||
* @since 0.9.0
|
||||
*/
|
||||
void addFilter(Filter newFilter);
|
||||
/**
|
||||
* Add a filter to the end of the filter list.
|
||||
*
|
||||
* @since 0.9.0
|
||||
*/
|
||||
void addFilter(Filter newFilter);
|
||||
|
||||
/**
|
||||
* Returns the head Filter. The Filters are organized in a linked list
|
||||
* and so all Filters on this Appender are available through the result.
|
||||
*
|
||||
* @return the head Filter or null, if no Filters are present
|
||||
* @since 1.1
|
||||
*/
|
||||
public Filter getFilter();
|
||||
/**
|
||||
* Returns the head Filter. The Filters are organized in a linked list
|
||||
* and so all Filters on this Appender are available through the result.
|
||||
*
|
||||
* @return the head Filter or null, if no Filters are present
|
||||
* @since 1.1
|
||||
*/
|
||||
public Filter getFilter();
|
||||
|
||||
/**
|
||||
* Clear the list of filters by removing all the filters in it.
|
||||
*
|
||||
* @since 0.9.0
|
||||
*/
|
||||
public void clearFilters();
|
||||
/**
|
||||
* Clear the list of filters by removing all the filters in it.
|
||||
*
|
||||
* @since 0.9.0
|
||||
*/
|
||||
public void clearFilters();
|
||||
|
||||
/**
|
||||
* Release any resources allocated within the appender such as file
|
||||
* handles, network connections, etc.
|
||||
* <p/>
|
||||
* <p>It is a programming error to append to a closed appender.
|
||||
*
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public void close();
|
||||
/**
|
||||
* Release any resources allocated within the appender such as file
|
||||
* handles, network connections, etc.
|
||||
* <p/>
|
||||
* <p>It is a programming error to append to a closed appender.
|
||||
*
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public void close();
|
||||
|
||||
/**
|
||||
* Log in <code>Appender</code> specific way. When appropriate,
|
||||
* Loggers will call the <code>doAppend</code> method of appender
|
||||
* implementations in order to log.
|
||||
*/
|
||||
public void doAppend(LoggingEvent event);
|
||||
/**
|
||||
* Log in <code>Appender</code> specific way. When appropriate,
|
||||
* Loggers will call the <code>doAppend</code> method of appender
|
||||
* implementations in order to log.
|
||||
*/
|
||||
public void doAppend(LoggingEvent event);
|
||||
|
||||
/**
|
||||
* Get the name of this appender. The name uniquely identifies the
|
||||
* appender.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Get the name of this appender. The name uniquely identifies the
|
||||
* appender.
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* Set the {@link ErrorHandler} for this appender.
|
||||
*
|
||||
* @since 0.9.0
|
||||
*/
|
||||
public void setErrorHandler(ErrorHandler errorHandler);
|
||||
|
||||
/**
|
||||
* Returns the {@link ErrorHandler} for this appender.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public ErrorHandler getErrorHandler();
|
||||
|
||||
/**
|
||||
* Set the {@link ErrorHandler} for this appender.
|
||||
*
|
||||
* @since 0.9.0
|
||||
*/
|
||||
public void setErrorHandler(ErrorHandler errorHandler);
|
||||
/**
|
||||
* Set the {@link Layout} for this appender.
|
||||
*
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public void setLayout(Layout layout);
|
||||
|
||||
/**
|
||||
* Returns the {@link ErrorHandler} for this appender.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public ErrorHandler getErrorHandler();
|
||||
/**
|
||||
* Returns this appenders layout.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public Layout getLayout();
|
||||
|
||||
/**
|
||||
* Set the {@link Layout} for this appender.
|
||||
*
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public void setLayout(Layout layout);
|
||||
/**
|
||||
* Set the name of this appender. The name is used by other
|
||||
* components to identify this appender.
|
||||
*
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public void setName(String name);
|
||||
|
||||
/**
|
||||
* Returns this appenders layout.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public Layout getLayout();
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of this appender. The name is used by other
|
||||
* components to identify this appender.
|
||||
*
|
||||
* @since 0.8.1
|
||||
*/
|
||||
public void setName(String name);
|
||||
|
||||
/**
|
||||
* Configurators call this method to determine if the appender
|
||||
* requires a layout. If this method returns <code>true</code>,
|
||||
* meaning that layout is required, then the configurator will
|
||||
* configure an layout using the configuration information at its
|
||||
* disposal. If this method returns <code>false</code>, meaning that
|
||||
* a layout is not required, then layout configuration will be
|
||||
* skipped even if there is available layout configuration
|
||||
* information at the disposal of the configurator..
|
||||
* <p/>
|
||||
* <p>In the rather exceptional case, where the appender
|
||||
* implementation admits a layout but can also work without it, then
|
||||
* the appender should return <code>true</code>.
|
||||
*
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public boolean requiresLayout();
|
||||
/**
|
||||
* Configurators call this method to determine if the appender
|
||||
* requires a layout. If this method returns <code>true</code>,
|
||||
* meaning that layout is required, then the configurator will
|
||||
* configure an layout using the configuration information at its
|
||||
* disposal. If this method returns <code>false</code>, meaning that
|
||||
* a layout is not required, then layout configuration will be
|
||||
* skipped even if there is available layout configuration
|
||||
* information at the disposal of the configurator..
|
||||
* <p/>
|
||||
* <p>In the rather exceptional case, where the appender
|
||||
* implementation admits a layout but can also work without it, then
|
||||
* the appender should return <code>true</code>.
|
||||
*
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public boolean requiresLayout();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,15 @@ import org.apache.log4j.spi.OptionHandler;
|
|||
|
||||
public class AppenderSkeleton implements OptionHandler {
|
||||
|
||||
public void setLayout(Layout layout) {
|
||||
}
|
||||
public void setLayout(Layout layout) {
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
}
|
||||
public void setName(String name) {
|
||||
}
|
||||
|
||||
public void activateOptions() {
|
||||
}
|
||||
public void activateOptions() {
|
||||
}
|
||||
|
||||
public void setThreshold(Priority threshold) {
|
||||
}
|
||||
public void setThreshold(Priority threshold) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ package org.apache.log4j;
|
|||
* A minimal (nop) implementation of BasicConfigurator.
|
||||
*/
|
||||
public class BasicConfigurator {
|
||||
public static void configure() {
|
||||
}
|
||||
public static void configure() {
|
||||
}
|
||||
|
||||
public static void configure(Appender appender) {
|
||||
}
|
||||
public static void configure(Appender appender) {
|
||||
}
|
||||
|
||||
public static void resetConfiguration() {
|
||||
}
|
||||
public static void resetConfiguration() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,314 +43,304 @@ import java.util.Enumeration;
|
|||
@SuppressWarnings("rawtypes")
|
||||
public class Category {
|
||||
|
||||
private static final String CATEGORY_FQCN = Category.class.getName();
|
||||
private static final String CATEGORY_FQCN = Category.class.getName();
|
||||
|
||||
private String name;
|
||||
private String name;
|
||||
|
||||
protected org.slf4j.Logger slf4jLogger;
|
||||
private org.slf4j.spi.LocationAwareLogger locationAwareLogger;
|
||||
protected org.slf4j.Logger slf4jLogger;
|
||||
private org.slf4j.spi.LocationAwareLogger locationAwareLogger;
|
||||
|
||||
private static Marker FATAL_MARKER = MarkerFactory.getMarker("FATAL");
|
||||
private static Marker FATAL_MARKER = MarkerFactory.getMarker("FATAL");
|
||||
|
||||
Category(String name) {
|
||||
this.name = name;
|
||||
slf4jLogger = LoggerFactory.getLogger(name);
|
||||
if (slf4jLogger instanceof LocationAwareLogger) {
|
||||
locationAwareLogger = (LocationAwareLogger) slf4jLogger;
|
||||
Category(String name) {
|
||||
this.name = name;
|
||||
slf4jLogger = LoggerFactory.getLogger(name);
|
||||
if (slf4jLogger instanceof LocationAwareLogger) {
|
||||
locationAwareLogger = (LocationAwareLogger) slf4jLogger;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Category getInstance(Class clazz) {
|
||||
return Log4jLoggerFactory.getLogger(clazz.getName());
|
||||
}
|
||||
|
||||
public static Category getInstance(String name) {
|
||||
return Log4jLoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
public final Category getParent() { return null; }
|
||||
|
||||
/**
|
||||
* Returns the obvious.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public Enumeration getAllAppenders() {
|
||||
return NullEnumeration.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the level in effect for this category/logger.
|
||||
*
|
||||
* <p>
|
||||
* The result is computed by simulation.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Level getEffectiveLevel() {
|
||||
if (slf4jLogger.isTraceEnabled()) {
|
||||
return Level.TRACE;
|
||||
public static Category getInstance(Class clazz) {
|
||||
return Log4jLoggerFactory.getLogger(clazz.getName());
|
||||
}
|
||||
if (slf4jLogger.isDebugEnabled()) {
|
||||
return Level.DEBUG;
|
||||
|
||||
public static Category getInstance(String name) {
|
||||
return Log4jLoggerFactory.getLogger(name);
|
||||
}
|
||||
if (slf4jLogger.isInfoEnabled()) {
|
||||
return Level.INFO;
|
||||
|
||||
public final Category getParent() {
|
||||
return null;
|
||||
}
|
||||
if (slf4jLogger.isWarnEnabled()) {
|
||||
return Level.WARN;
|
||||
|
||||
/**
|
||||
* Returns the obvious.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
return Level.ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assigned {@link Level}, if any, for this Category. This
|
||||
* implementation always returns null.
|
||||
*
|
||||
* @return Level - the assigned Level, can be <code>null</code>.
|
||||
*/
|
||||
final public Level getLevel() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use {@link #getLevel} instead.
|
||||
*/
|
||||
final public Level getPriority() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isDebugEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isDebugEnabled() {
|
||||
return slf4jLogger.isDebugEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isInfoEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isInfoEnabled() {
|
||||
return slf4jLogger.isInfoEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates tob {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isWarnEnabled() {
|
||||
return slf4jLogger.isWarnEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isErrorEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isErrorEnabled() {
|
||||
return slf4jLogger.isErrorEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the priority passed as parameter is enabled in the
|
||||
* underlying SLF4J logger. Each log4j priority is mapped directly to its
|
||||
* SLF4J equivalent, except for FATAL which is mapped as ERROR.
|
||||
*
|
||||
* @param p
|
||||
* the priority to check against
|
||||
* @return true if this logger is enabled for the given level, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isEnabledFor(Priority p) {
|
||||
switch (p.level) {
|
||||
case Level.TRACE_INT:
|
||||
return slf4jLogger.isTraceEnabled();
|
||||
case Level.DEBUG_INT:
|
||||
return slf4jLogger.isDebugEnabled();
|
||||
case Level.INFO_INT:
|
||||
return slf4jLogger.isInfoEnabled();
|
||||
case Level.WARN_INT:
|
||||
return slf4jLogger.isWarnEnabled();
|
||||
case Level.ERROR_INT:
|
||||
return slf4jLogger.isErrorEnabled();
|
||||
case Priority.FATAL_INT:
|
||||
return slf4jLogger.isErrorEnabled();
|
||||
public Enumeration getAllAppenders() {
|
||||
return NullEnumeration.getInstance();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void differentiatedLog(Marker marker, String fqcn, int level, Object message,
|
||||
Throwable t) {
|
||||
|
||||
String m = convertToString(message);
|
||||
if (locationAwareLogger != null) {
|
||||
locationAwareLogger.log(marker, fqcn, level, m, null, t);
|
||||
} else {
|
||||
switch (level) {
|
||||
case LocationAwareLogger.TRACE_INT:
|
||||
slf4jLogger.trace(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.DEBUG_INT:
|
||||
slf4jLogger.debug(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.INFO_INT:
|
||||
slf4jLogger.info(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.WARN_INT:
|
||||
slf4jLogger.warn(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.ERROR_INT:
|
||||
slf4jLogger.error(marker, m);
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* Return the level in effect for this category/logger.
|
||||
*
|
||||
* <p>
|
||||
* The result is computed by simulation.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Level getEffectiveLevel() {
|
||||
if (slf4jLogger.isTraceEnabled()) {
|
||||
return Level.TRACE;
|
||||
}
|
||||
if (slf4jLogger.isDebugEnabled()) {
|
||||
return Level.DEBUG;
|
||||
}
|
||||
if (slf4jLogger.isInfoEnabled()) {
|
||||
return Level.INFO;
|
||||
}
|
||||
if (slf4jLogger.isWarnEnabled()) {
|
||||
return Level.WARN;
|
||||
}
|
||||
return Level.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#debug(String)} method of SLF4J.
|
||||
*/
|
||||
public void debug(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void debug(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#info(String)} method in SLF4J.
|
||||
*/
|
||||
public void info(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#info(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void info(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#warn(String)} method in SLF4J.
|
||||
*/
|
||||
public void warn(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#warn(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void warn(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J.
|
||||
*/
|
||||
public void error(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void error(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J.
|
||||
*/
|
||||
public void fatal(Object message) {
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN,
|
||||
LocationAwareLogger.ERROR_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in
|
||||
* SLF4J. In addition, the call is marked with a marker named "FATAL".
|
||||
*/
|
||||
public void fatal(Object message, Throwable t) {
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN,
|
||||
LocationAwareLogger.ERROR_INT, message, t);
|
||||
}
|
||||
|
||||
protected void forcedLog(String FQCN, Priority p, Object msg, Throwable t) {
|
||||
log(FQCN, p, msg, t);
|
||||
}
|
||||
|
||||
// See also http://bugzilla.slf4j.org/show_bug.cgi?id=168
|
||||
public void log(String FQCN, Priority p, Object msg, Throwable t) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, FQCN, levelInt, msg, t);
|
||||
}
|
||||
|
||||
public void log(Priority p, Object message, Throwable t) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, CATEGORY_FQCN, levelInt, message, t);
|
||||
}
|
||||
|
||||
public void log(Priority p, Object message) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, CATEGORY_FQCN, levelInt, message, null);
|
||||
}
|
||||
|
||||
private int priorityToLevelInt(Priority p) {
|
||||
switch (p.level) {
|
||||
case Level.TRACE_INT:
|
||||
case Level.X_TRACE_INT:
|
||||
return LocationAwareLogger.TRACE_INT;
|
||||
case Priority.DEBUG_INT:
|
||||
return LocationAwareLogger.DEBUG_INT;
|
||||
case Priority.INFO_INT:
|
||||
return LocationAwareLogger.INFO_INT;
|
||||
case Priority.WARN_INT:
|
||||
return LocationAwareLogger.WARN_INT;
|
||||
case Priority.ERROR_INT:
|
||||
return LocationAwareLogger.ERROR_INT;
|
||||
case Priority.FATAL_INT:
|
||||
return LocationAwareLogger.ERROR_INT;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown Priority " + p);
|
||||
/**
|
||||
* Returns the assigned {@link Level}, if any, for this Category. This
|
||||
* implementation always returns null.
|
||||
*
|
||||
* @return Level - the assigned Level, can be <code>null</code>.
|
||||
*/
|
||||
final public Level getLevel() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected final String convertToString(Object message) {
|
||||
if (message == null) {
|
||||
return (String) message;
|
||||
} else {
|
||||
return message.toString();
|
||||
/**
|
||||
* @deprecated Please use {@link #getLevel} instead.
|
||||
*/
|
||||
final public Level getPriority() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAdditivity(boolean additive) {
|
||||
// nothing to do
|
||||
}
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isDebugEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isDebugEnabled() {
|
||||
return slf4jLogger.isDebugEnabled();
|
||||
}
|
||||
|
||||
public void addAppender(Appender newAppender) {
|
||||
// nothing to do
|
||||
}
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isInfoEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isInfoEnabled() {
|
||||
return slf4jLogger.isInfoEnabled();
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
// nothing to do
|
||||
}
|
||||
/**
|
||||
* Delegates tob {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isWarnEnabled() {
|
||||
return slf4jLogger.isWarnEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isErrorEnabled} method in SLF4J
|
||||
*/
|
||||
public boolean isErrorEnabled() {
|
||||
return slf4jLogger.isErrorEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the priority passed as parameter is enabled in the
|
||||
* underlying SLF4J logger. Each log4j priority is mapped directly to its
|
||||
* SLF4J equivalent, except for FATAL which is mapped as ERROR.
|
||||
*
|
||||
* @param p
|
||||
* the priority to check against
|
||||
* @return true if this logger is enabled for the given level, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isEnabledFor(Priority p) {
|
||||
switch (p.level) {
|
||||
case Level.TRACE_INT:
|
||||
return slf4jLogger.isTraceEnabled();
|
||||
case Level.DEBUG_INT:
|
||||
return slf4jLogger.isDebugEnabled();
|
||||
case Level.INFO_INT:
|
||||
return slf4jLogger.isInfoEnabled();
|
||||
case Level.WARN_INT:
|
||||
return slf4jLogger.isWarnEnabled();
|
||||
case Level.ERROR_INT:
|
||||
return slf4jLogger.isErrorEnabled();
|
||||
case Priority.FATAL_INT:
|
||||
return slf4jLogger.isErrorEnabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void differentiatedLog(Marker marker, String fqcn, int level, Object message, Throwable t) {
|
||||
|
||||
String m = convertToString(message);
|
||||
if (locationAwareLogger != null) {
|
||||
locationAwareLogger.log(marker, fqcn, level, m, null, t);
|
||||
} else {
|
||||
switch (level) {
|
||||
case LocationAwareLogger.TRACE_INT:
|
||||
slf4jLogger.trace(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.DEBUG_INT:
|
||||
slf4jLogger.debug(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.INFO_INT:
|
||||
slf4jLogger.info(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.WARN_INT:
|
||||
slf4jLogger.warn(marker, m);
|
||||
break;
|
||||
case LocationAwareLogger.ERROR_INT:
|
||||
slf4jLogger.error(marker, m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#debug(String)} method of SLF4J.
|
||||
*/
|
||||
public void debug(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void debug(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#info(String)} method in SLF4J.
|
||||
*/
|
||||
public void info(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#info(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void info(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#warn(String)} method in SLF4J.
|
||||
*/
|
||||
public void warn(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#warn(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void warn(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J.
|
||||
*/
|
||||
public void error(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in
|
||||
* SLF4J.
|
||||
*/
|
||||
public void error(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J.
|
||||
*/
|
||||
public void fatal(Object message) {
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method in
|
||||
* SLF4J. In addition, the call is marked with a marker named "FATAL".
|
||||
*/
|
||||
public void fatal(Object message, Throwable t) {
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t);
|
||||
}
|
||||
|
||||
protected void forcedLog(String FQCN, Priority p, Object msg, Throwable t) {
|
||||
log(FQCN, p, msg, t);
|
||||
}
|
||||
|
||||
// See also http://bugzilla.slf4j.org/show_bug.cgi?id=168
|
||||
public void log(String FQCN, Priority p, Object msg, Throwable t) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, FQCN, levelInt, msg, t);
|
||||
}
|
||||
|
||||
public void log(Priority p, Object message, Throwable t) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, CATEGORY_FQCN, levelInt, message, t);
|
||||
}
|
||||
|
||||
public void log(Priority p, Object message) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, CATEGORY_FQCN, levelInt, message, null);
|
||||
}
|
||||
|
||||
private int priorityToLevelInt(Priority p) {
|
||||
switch (p.level) {
|
||||
case Level.TRACE_INT:
|
||||
case Level.X_TRACE_INT:
|
||||
return LocationAwareLogger.TRACE_INT;
|
||||
case Priority.DEBUG_INT:
|
||||
return LocationAwareLogger.DEBUG_INT;
|
||||
case Priority.INFO_INT:
|
||||
return LocationAwareLogger.INFO_INT;
|
||||
case Priority.WARN_INT:
|
||||
return LocationAwareLogger.WARN_INT;
|
||||
case Priority.ERROR_INT:
|
||||
return LocationAwareLogger.ERROR_INT;
|
||||
case Priority.FATAL_INT:
|
||||
return LocationAwareLogger.ERROR_INT;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown Priority " + p);
|
||||
}
|
||||
}
|
||||
|
||||
protected final String convertToString(Object message) {
|
||||
if (message == null) {
|
||||
return (String) message;
|
||||
} else {
|
||||
return message.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAdditivity(boolean additive) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void addAppender(Appender newAppender) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void setLevel(Level level) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,15 @@ package org.apache.log4j;
|
|||
|
||||
public class FileAppender extends WriterAppender {
|
||||
|
||||
public FileAppender() {
|
||||
}
|
||||
public FileAppender() {
|
||||
}
|
||||
|
||||
public FileAppender(Layout layout, String filename) {
|
||||
}
|
||||
public FileAppender(Layout layout, String filename) {
|
||||
}
|
||||
|
||||
public FileAppender(Layout layout, String filename, boolean append) {
|
||||
}
|
||||
public FileAppender(Layout layout, String filename, boolean append) {
|
||||
}
|
||||
|
||||
public FileAppender(Layout layout, String filename, boolean append, boolean bufferedIO, int bufferSize) {
|
||||
}
|
||||
public FileAppender(Layout layout, String filename, boolean append, boolean bufferedIO, int bufferSize) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
// Nicholas Wolff
|
||||
|
||||
package org.apache.log4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
|
@ -38,139 +39,145 @@ import java.io.Serializable;
|
|||
*/
|
||||
public class Level extends Priority implements Serializable {
|
||||
|
||||
/**
|
||||
* TRACE level integer value.
|
||||
* @since 1.2.12
|
||||
/**
|
||||
* TRACE level integer value.
|
||||
* @since 1.2.12
|
||||
*/
|
||||
public static final int TRACE_INT = 5000;
|
||||
|
||||
// match jboss' xlevel
|
||||
public static final int X_TRACE_INT = DEBUG_INT - 100;
|
||||
|
||||
/**
|
||||
The <code>OFF</code> has the highest possible rank and is
|
||||
intended to turn off logging. */
|
||||
final static public Level OFF = new Level(OFF_INT, "OFF", 0);
|
||||
|
||||
/**
|
||||
The <code>FATAL</code> level designates very severe error
|
||||
events that will presumably lead the application to abort.
|
||||
*/
|
||||
final static public Level FATAL = new Level(FATAL_INT, "FATAL", 0);
|
||||
|
||||
/**
|
||||
The <code>ERROR</code> level designates error events that
|
||||
might still allow the application to continue running. */
|
||||
final static public Level ERROR = new Level(ERROR_INT, "ERROR", 3);
|
||||
|
||||
/**
|
||||
The <code>WARN</code> level designates potentially harmful situations.
|
||||
*/
|
||||
public static final int TRACE_INT = 5000;
|
||||
final static public Level WARN = new Level(WARN_INT, "WARN", 4);
|
||||
|
||||
// match jboss' xlevel
|
||||
public static final int X_TRACE_INT = DEBUG_INT - 100;
|
||||
/**
|
||||
The <code>INFO</code> level designates informational messages
|
||||
that highlight the progress of the application at coarse-grained
|
||||
level. */
|
||||
final static public Level INFO = new Level(INFO_INT, "INFO", 6);
|
||||
|
||||
/**
|
||||
The <code>OFF</code> has the highest possible rank and is
|
||||
intended to turn off logging. */
|
||||
final static public Level OFF = new Level(OFF_INT, "OFF", 0);
|
||||
/**
|
||||
The <code>DEBUG</code> Level designates fine-grained
|
||||
informational events that are most useful to debug an
|
||||
application. */
|
||||
final static public Level DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
|
||||
|
||||
/**
|
||||
The <code>FATAL</code> level designates very severe error
|
||||
events that will presumably lead the application to abort.
|
||||
*/
|
||||
final static public Level FATAL = new Level(FATAL_INT, "FATAL", 0);
|
||||
/**
|
||||
* The <code>TRACE</code> Level designates finer-grained
|
||||
* informational events than the <code>DEBUG</code level.
|
||||
* @since 1.2.12
|
||||
*/
|
||||
public static final Level TRACE = new Level(TRACE_INT, "TRACE", 7);
|
||||
|
||||
/**
|
||||
The <code>ERROR</code> level designates error events that
|
||||
might still allow the application to continue running. */
|
||||
final static public Level ERROR = new Level(ERROR_INT, "ERROR", 3);
|
||||
/**
|
||||
The <code>ALL</code> has the lowest possible rank and is intended to
|
||||
turn on all logging. */
|
||||
final static public Level ALL = new Level(ALL_INT, "ALL", 7);
|
||||
|
||||
/**
|
||||
The <code>WARN</code> level designates potentially harmful situations.
|
||||
*/
|
||||
final static public Level WARN = new Level(WARN_INT, "WARN", 4);
|
||||
/**
|
||||
* Serialization version id.
|
||||
*/
|
||||
static final long serialVersionUID = 3491141966387921974L;
|
||||
|
||||
/**
|
||||
The <code>INFO</code> level designates informational messages
|
||||
that highlight the progress of the application at coarse-grained
|
||||
level. */
|
||||
final static public Level INFO = new Level(INFO_INT, "INFO", 6);
|
||||
|
||||
/**
|
||||
The <code>DEBUG</code> Level designates fine-grained
|
||||
informational events that are most useful to debug an
|
||||
application. */
|
||||
final static public Level DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
|
||||
|
||||
/**
|
||||
* The <code>TRACE</code> Level designates finer-grained
|
||||
* informational events than the <code>DEBUG</code level.
|
||||
* @since 1.2.12
|
||||
*/
|
||||
public static final Level TRACE = new Level(TRACE_INT, "TRACE", 7);
|
||||
|
||||
|
||||
/**
|
||||
The <code>ALL</code> has the lowest possible rank and is intended to
|
||||
turn on all logging. */
|
||||
final static public Level ALL = new Level(ALL_INT, "ALL", 7);
|
||||
|
||||
/**
|
||||
* Serialization version id.
|
||||
*/
|
||||
static final long serialVersionUID = 3491141966387921974L;
|
||||
|
||||
/**
|
||||
Instantiate a Level object.
|
||||
*/
|
||||
protected
|
||||
Level(int level, String levelStr, int syslogEquivalent) {
|
||||
super(level, levelStr, syslogEquivalent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Convert the string passed as argument to a level. If the
|
||||
conversion fails, then this method returns {@link #DEBUG}.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Level toLevel(String sArg) {
|
||||
return (Level) toLevel(sArg, Level.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
Convert an integer passed as argument to a level. If the
|
||||
conversion fails, then this method returns {@link #DEBUG}.
|
||||
|
||||
*/
|
||||
public
|
||||
static
|
||||
Level toLevel(int val) {
|
||||
return (Level) toLevel(val, Level.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
Convert an integer passed as argument to a level. If the
|
||||
conversion fails, then this method returns the specified default.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Level toLevel(int val, Level defaultLevel) {
|
||||
switch(val) {
|
||||
case ALL_INT: return ALL;
|
||||
case DEBUG_INT: return Level.DEBUG;
|
||||
case INFO_INT: return Level.INFO;
|
||||
case WARN_INT: return Level.WARN;
|
||||
case ERROR_INT: return Level.ERROR;
|
||||
case FATAL_INT: return Level.FATAL;
|
||||
case OFF_INT: return OFF;
|
||||
case TRACE_INT: return Level.TRACE;
|
||||
default: return defaultLevel;
|
||||
/**
|
||||
Instantiate a Level object.
|
||||
*/
|
||||
protected Level(int level, String levelStr, int syslogEquivalent) {
|
||||
super(level, levelStr, syslogEquivalent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Convert the string passed as argument to a level. If the
|
||||
conversion fails, then this method returns the value of
|
||||
<code>defaultLevel</code>.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Level toLevel(String sArg, Level defaultLevel) {
|
||||
if(sArg == null)
|
||||
return defaultLevel;
|
||||
/**
|
||||
Convert the string passed as argument to a level. If the
|
||||
conversion fails, then this method returns {@link #DEBUG}.
|
||||
*/
|
||||
public static Level toLevel(String sArg) {
|
||||
return (Level) toLevel(sArg, Level.DEBUG);
|
||||
}
|
||||
|
||||
String s = sArg.toUpperCase();
|
||||
/**
|
||||
Convert an integer passed as argument to a level. If the
|
||||
conversion fails, then this method returns {@link #DEBUG}.
|
||||
|
||||
if(s.equals("ALL")) return Level.ALL;
|
||||
if(s.equals("DEBUG")) return Level.DEBUG;
|
||||
if(s.equals("INFO")) return Level.INFO;
|
||||
if(s.equals("WARN")) return Level.WARN;
|
||||
if(s.equals("ERROR")) return Level.ERROR;
|
||||
if(s.equals("FATAL")) return Level.FATAL;
|
||||
if(s.equals("OFF")) return Level.OFF;
|
||||
if(s.equals("TRACE")) return Level.TRACE;
|
||||
return defaultLevel;
|
||||
}
|
||||
*/
|
||||
public static Level toLevel(int val) {
|
||||
return (Level) toLevel(val, Level.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
Convert an integer passed as argument to a level. If the
|
||||
conversion fails, then this method returns the specified default.
|
||||
*/
|
||||
public static Level toLevel(int val, Level defaultLevel) {
|
||||
switch (val) {
|
||||
case ALL_INT:
|
||||
return ALL;
|
||||
case DEBUG_INT:
|
||||
return Level.DEBUG;
|
||||
case INFO_INT:
|
||||
return Level.INFO;
|
||||
case WARN_INT:
|
||||
return Level.WARN;
|
||||
case ERROR_INT:
|
||||
return Level.ERROR;
|
||||
case FATAL_INT:
|
||||
return Level.FATAL;
|
||||
case OFF_INT:
|
||||
return OFF;
|
||||
case TRACE_INT:
|
||||
return Level.TRACE;
|
||||
default:
|
||||
return defaultLevel;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Convert the string passed as argument to a level. If the
|
||||
conversion fails, then this method returns the value of
|
||||
<code>defaultLevel</code>.
|
||||
*/
|
||||
public static Level toLevel(String sArg, Level defaultLevel) {
|
||||
if (sArg == null)
|
||||
return defaultLevel;
|
||||
|
||||
String s = sArg.toUpperCase();
|
||||
|
||||
if (s.equals("ALL"))
|
||||
return Level.ALL;
|
||||
if (s.equals("DEBUG"))
|
||||
return Level.DEBUG;
|
||||
if (s.equals("INFO"))
|
||||
return Level.INFO;
|
||||
if (s.equals("WARN"))
|
||||
return Level.WARN;
|
||||
if (s.equals("ERROR"))
|
||||
return Level.ERROR;
|
||||
if (s.equals("FATAL"))
|
||||
return Level.FATAL;
|
||||
if (s.equals("OFF"))
|
||||
return Level.OFF;
|
||||
if (s.equals("TRACE"))
|
||||
return Level.TRACE;
|
||||
return defaultLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom deserialization of Level.
|
||||
|
|
@ -179,13 +186,13 @@ public class Level extends Priority implements Serializable {
|
|||
* @throws ClassNotFoundException if class not found.
|
||||
*/
|
||||
private void readObject(final ObjectInputStream s) throws IOException, ClassNotFoundException {
|
||||
s.defaultReadObject();
|
||||
level = s.readInt();
|
||||
syslogEquivalent = s.readInt();
|
||||
levelStr = s.readUTF();
|
||||
if (levelStr == null) {
|
||||
levelStr = "";
|
||||
}
|
||||
s.defaultReadObject();
|
||||
level = s.readInt();
|
||||
syslogEquivalent = s.readInt();
|
||||
levelStr = s.readUTF();
|
||||
if (levelStr == null) {
|
||||
levelStr = "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -208,13 +215,13 @@ public class Level extends Priority implements Serializable {
|
|||
*/
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
//
|
||||
// if the deserizalized object is exactly an instance of Level
|
||||
// if the deserizalized object is exactly an instance of Level
|
||||
//
|
||||
if (getClass() == Level.class) {
|
||||
return toLevel(level);
|
||||
}
|
||||
//
|
||||
// extension of Level can't substitute stock item
|
||||
// extension of Level can't substitute stock item
|
||||
//
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,46 +33,45 @@ import java.util.concurrent.ConcurrentMap;
|
|||
*/
|
||||
class Log4jLoggerFactory {
|
||||
|
||||
// String, Logger
|
||||
private static ConcurrentMap<String, Logger> log4jLoggers = new ConcurrentHashMap<String, Logger>();
|
||||
// String, Logger
|
||||
private static ConcurrentMap<String, Logger> log4jLoggers = new ConcurrentHashMap<String, Logger>();
|
||||
|
||||
private static final String LOG4J_DELEGATION_LOOP_URL = "http://www.slf4j.org/codes.html#log4jDelegationLoop";
|
||||
private static final String LOG4J_DELEGATION_LOOP_URL = "http://www.slf4j.org/codes.html#log4jDelegationLoop";
|
||||
|
||||
// check for delegation loops
|
||||
static {
|
||||
try {
|
||||
Class.forName("org.slf4j.impl.Log4jLoggerFactory");
|
||||
String part1 = "Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. ";
|
||||
String part2 = "See also " + LOG4J_DELEGATION_LOOP_URL
|
||||
+ " for more details.";
|
||||
// check for delegation loops
|
||||
static {
|
||||
try {
|
||||
Class.forName("org.slf4j.impl.Log4jLoggerFactory");
|
||||
String part1 = "Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. ";
|
||||
String part2 = "See also " + LOG4J_DELEGATION_LOOP_URL + " for more details.";
|
||||
|
||||
Util.report(part1);
|
||||
Util.report(part2);
|
||||
throw new IllegalStateException(part1 + part2);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// this is the good case
|
||||
Util.report(part1);
|
||||
Util.report(part2);
|
||||
throw new IllegalStateException(part1 + part2);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// this is the good case
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Logger getLogger(String name) {
|
||||
org.apache.log4j.Logger instance = log4jLoggers.get(name);
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
} else {
|
||||
Logger newInstance = new Logger(name);
|
||||
Logger oldInstance = log4jLoggers.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
public static Logger getLogger(String name) {
|
||||
org.apache.log4j.Logger instance = log4jLoggers.get(name);
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
} else {
|
||||
Logger newInstance = new Logger(name);
|
||||
Logger oldInstance = log4jLoggers.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Logger getLogger(String name, LoggerFactory loggerFactory) {
|
||||
org.apache.log4j.Logger instance = log4jLoggers.get(name);
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
} else {
|
||||
Logger newInstance = loggerFactory.makeNewLoggerInstance(name);
|
||||
Logger oldInstance = log4jLoggers.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
public static Logger getLogger(String name, LoggerFactory loggerFactory) {
|
||||
org.apache.log4j.Logger instance = log4jLoggers.get(name);
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
} else {
|
||||
Logger newInstance = loggerFactory.makeNewLoggerInstance(name);
|
||||
Logger oldInstance = log4jLoggers.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,51 +37,51 @@ import java.util.Vector;
|
|||
@SuppressWarnings("rawtypes")
|
||||
public class LogManager {
|
||||
|
||||
public static Logger getRootLogger() {
|
||||
return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||
}
|
||||
public static Logger getRootLogger() {
|
||||
return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||
}
|
||||
|
||||
public static Logger getLogger(final String name) {
|
||||
return Log4jLoggerFactory.getLogger(name);
|
||||
}
|
||||
public static Logger getLogger(final String name) {
|
||||
return Log4jLoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
public static Logger getLogger(final Class clazz) {
|
||||
return Log4jLoggerFactory.getLogger(clazz.getName());
|
||||
}
|
||||
public static Logger getLogger(final Class clazz) {
|
||||
return Log4jLoggerFactory.getLogger(clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a logger instance created by loggerFactory. This method was requested in
|
||||
* <a href="http://bugzilla.slf4j.org/show_bug.cgi?id=234">bug #234</a>. Note that
|
||||
* log4j-over-slf4j does not ship with a LoggerFactory implementation. If this
|
||||
* method is called, the caller must provide his/her own implementation.
|
||||
*
|
||||
* @param name the name of the desired logger
|
||||
* @param loggerFactory an instance of {@link LoggerFactory}
|
||||
* @return returns a logger instance created by loggerFactory
|
||||
* @since 1.6.6
|
||||
*/
|
||||
public static Logger getLogger(String name, LoggerFactory loggerFactory) {
|
||||
return loggerFactory.makeNewLoggerInstance(name);
|
||||
}
|
||||
/**
|
||||
* Returns a logger instance created by loggerFactory. This method was requested in
|
||||
* <a href="http://bugzilla.slf4j.org/show_bug.cgi?id=234">bug #234</a>. Note that
|
||||
* log4j-over-slf4j does not ship with a LoggerFactory implementation. If this
|
||||
* method is called, the caller must provide his/her own implementation.
|
||||
*
|
||||
* @param name the name of the desired logger
|
||||
* @param loggerFactory an instance of {@link LoggerFactory}
|
||||
* @return returns a logger instance created by loggerFactory
|
||||
* @since 1.6.6
|
||||
*/
|
||||
public static Logger getLogger(String name, LoggerFactory loggerFactory) {
|
||||
return loggerFactory.makeNewLoggerInstance(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* This bogus implementation returns an empty enumeration.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Enumeration getCurrentLoggers() {
|
||||
return new Vector().elements();
|
||||
}
|
||||
/**
|
||||
* This bogus implementation returns an empty enumeration.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Enumeration getCurrentLoggers() {
|
||||
return new Vector().elements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented as NOP.
|
||||
*/
|
||||
public static void shutdown() {
|
||||
}
|
||||
/**
|
||||
* Implemented as NOP.
|
||||
*/
|
||||
public static void shutdown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implemented as NOP.
|
||||
*/
|
||||
public static void resetConfiguration() {
|
||||
}
|
||||
/**
|
||||
* Implemented as NOP.
|
||||
*/
|
||||
public static void resetConfiguration() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,55 +31,54 @@ import org.slf4j.spi.LocationAwareLogger;
|
|||
@SuppressWarnings("rawtypes")
|
||||
public class Logger extends Category {
|
||||
|
||||
private static final String LOGGER_FQCN = Logger.class.getName();
|
||||
private static final String LOGGER_FQCN = Logger.class.getName();
|
||||
|
||||
protected Logger(String name) {
|
||||
super(name);
|
||||
}
|
||||
protected Logger(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public static Logger getLogger(String name) {
|
||||
return Log4jLoggerFactory.getLogger(name);
|
||||
}
|
||||
public static Logger getLogger(String name) {
|
||||
return Log4jLoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
public static Logger getLogger(String name, LoggerFactory loggerFactory) {
|
||||
return Log4jLoggerFactory.getLogger(name,loggerFactory);
|
||||
}
|
||||
public static Logger getLogger(String name, LoggerFactory loggerFactory) {
|
||||
return Log4jLoggerFactory.getLogger(name, loggerFactory);
|
||||
}
|
||||
|
||||
public static Logger getLogger(Class clazz) {
|
||||
return getLogger(clazz.getName());
|
||||
}
|
||||
public static Logger getLogger(Class clazz) {
|
||||
return getLogger(clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the obvious.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Logger getRootLogger() {
|
||||
return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||
}
|
||||
/**
|
||||
* Does the obvious.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Logger getRootLogger() {
|
||||
return Log4jLoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isTraceEnabled}
|
||||
* method of SLF4J.
|
||||
*/
|
||||
public boolean isTraceEnabled() {
|
||||
return slf4jLogger.isTraceEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#isTraceEnabled}
|
||||
* method of SLF4J.
|
||||
*/
|
||||
public boolean isTraceEnabled() {
|
||||
return slf4jLogger.isTraceEnabled();
|
||||
}
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#trace(String)} method in SLF4J.
|
||||
*/
|
||||
public void trace(Object message) {
|
||||
differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#trace(String)} method in SLF4J.
|
||||
*/
|
||||
public void trace(Object message) {
|
||||
differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#trace(String,Throwable)}
|
||||
* method in SLF4J.
|
||||
*/
|
||||
public void trace(Object message, Throwable t) {
|
||||
differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
|
||||
}
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#trace(String,Throwable)}
|
||||
* method in SLF4J.
|
||||
*/
|
||||
public void trace(Object message, Throwable t) {
|
||||
differentiatedLog(null, LOGGER_FQCN, LocationAwareLogger.TRACE_INT, message, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,45 +21,44 @@ import java.util.Map;
|
|||
|
||||
public class MDC {
|
||||
|
||||
public static void put(String key, String value) {
|
||||
org.slf4j.MDC.put(key, value);
|
||||
}
|
||||
|
||||
public static void put(String key, Object value) {
|
||||
if (value != null) {
|
||||
put(key, value.toString());
|
||||
} else {
|
||||
put(key, null);
|
||||
public static void put(String key, String value) {
|
||||
org.slf4j.MDC.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Object get(String key) {
|
||||
return org.slf4j.MDC.get(key);
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
org.slf4j.MDC.remove(key);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
org.slf4j.MDC.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not part of the Log4J public API. However it
|
||||
* has been called by other projects. This method is here temporarily
|
||||
* until projects who are depending on this method release fixes.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Deprecated
|
||||
public static Hashtable getContext() {
|
||||
Map map = org.slf4j.MDC.getCopyOfContextMap();
|
||||
|
||||
if (map != null) {
|
||||
return new Hashtable(map);
|
||||
public static void put(String key, Object value) {
|
||||
if (value != null) {
|
||||
put(key, value.toString());
|
||||
} else {
|
||||
put(key, null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return new Hashtable();
|
||||
|
||||
public static Object get(String key) {
|
||||
return org.slf4j.MDC.get(key);
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
org.slf4j.MDC.remove(key);
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
org.slf4j.MDC.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not part of the Log4J public API. However it
|
||||
* has been called by other projects. This method is here temporarily
|
||||
* until projects who are depending on this method release fixes.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Deprecated
|
||||
public static Hashtable getContext() {
|
||||
Map map = org.slf4j.MDC.getCopyOfContextMap();
|
||||
|
||||
if (map != null) {
|
||||
return new Hashtable(map);
|
||||
} else {
|
||||
return new Hashtable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,75 +28,75 @@ import java.util.Stack;
|
|||
|
||||
public class NDC {
|
||||
|
||||
public final static String PREFIX = "NDC";
|
||||
public final static String PREFIX = "NDC";
|
||||
|
||||
public static void clear() {
|
||||
int depth = getDepth();
|
||||
for (int i = 0; i < depth; i++) {
|
||||
String key = PREFIX + i;
|
||||
MDC.remove(key);
|
||||
public static void clear() {
|
||||
int depth = getDepth();
|
||||
for (int i = 0; i < depth; i++) {
|
||||
String key = PREFIX + i;
|
||||
MDC.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Stack cloneStack() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void inherit(Stack stack) {
|
||||
}
|
||||
|
||||
static public String get() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getDepth() {
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String val = MDC.get(PREFIX + i);
|
||||
if (val != null) {
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Stack cloneStack() {
|
||||
return null;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static String pop() {
|
||||
int next = getDepth();
|
||||
if (next == 0) {
|
||||
return "";
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static void inherit(Stack stack) {
|
||||
}
|
||||
int last = next - 1;
|
||||
String key = PREFIX + last;
|
||||
String val = MDC.get(key);
|
||||
MDC.remove(key);
|
||||
return val;
|
||||
}
|
||||
|
||||
public static String peek() {
|
||||
int next = getDepth();
|
||||
if (next == 0) {
|
||||
return "";
|
||||
static public String get() {
|
||||
return null;
|
||||
}
|
||||
int last = next - 1;
|
||||
String key = PREFIX + last;
|
||||
String val = MDC.get(key);
|
||||
return val;
|
||||
}
|
||||
|
||||
public static void push(String message) {
|
||||
int next = getDepth();
|
||||
MDC.put(PREFIX + next, message);
|
||||
}
|
||||
public static int getDepth() {
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String val = MDC.get(PREFIX + i);
|
||||
if (val != null) {
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static public void remove() {
|
||||
clear();
|
||||
}
|
||||
public static String pop() {
|
||||
int next = getDepth();
|
||||
if (next == 0) {
|
||||
return "";
|
||||
}
|
||||
int last = next - 1;
|
||||
String key = PREFIX + last;
|
||||
String val = MDC.get(key);
|
||||
MDC.remove(key);
|
||||
return val;
|
||||
}
|
||||
|
||||
static public void setMaxDepth(int maxDepth) {
|
||||
}
|
||||
public static String peek() {
|
||||
int next = getDepth();
|
||||
if (next == 0) {
|
||||
return "";
|
||||
}
|
||||
int last = next - 1;
|
||||
String key = PREFIX + last;
|
||||
String val = MDC.get(key);
|
||||
return val;
|
||||
}
|
||||
|
||||
public static void push(String message) {
|
||||
int next = getDepth();
|
||||
MDC.put(PREFIX + next, message);
|
||||
}
|
||||
|
||||
static public void remove() {
|
||||
clear();
|
||||
}
|
||||
|
||||
static public void setMaxDepth(int maxDepth) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ package org.apache.log4j;
|
|||
* */
|
||||
public class PatternLayout extends Layout {
|
||||
|
||||
public PatternLayout() {
|
||||
super();
|
||||
}
|
||||
public PatternLayout() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PatternLayout(String pattern) {
|
||||
super();
|
||||
}
|
||||
public PatternLayout(String pattern) {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,168 +27,144 @@ package org.apache.log4j;
|
|||
@author Ceki Gülcü */
|
||||
public class Priority {
|
||||
|
||||
transient int level;
|
||||
transient String levelStr;
|
||||
transient int syslogEquivalent;
|
||||
transient int level;
|
||||
transient String levelStr;
|
||||
transient int syslogEquivalent;
|
||||
|
||||
public final static int OFF_INT = Integer.MAX_VALUE;
|
||||
public final static int FATAL_INT = 50000;
|
||||
public final static int ERROR_INT = 40000;
|
||||
public final static int WARN_INT = 30000;
|
||||
public final static int INFO_INT = 20000;
|
||||
public final static int DEBUG_INT = 10000;
|
||||
//public final static int FINE_INT = DEBUG_INT;
|
||||
public final static int ALL_INT = Integer.MIN_VALUE;
|
||||
public final static int OFF_INT = Integer.MAX_VALUE;
|
||||
public final static int FATAL_INT = 50000;
|
||||
public final static int ERROR_INT = 40000;
|
||||
public final static int WARN_INT = 30000;
|
||||
public final static int INFO_INT = 20000;
|
||||
public final static int DEBUG_INT = 10000;
|
||||
// public final static int FINE_INT = DEBUG_INT;
|
||||
public final static int ALL_INT = Integer.MIN_VALUE;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Level#FATAL} instead.
|
||||
*/
|
||||
final static public Priority FATAL = new Level(FATAL_INT, "FATAL", 0);
|
||||
/**
|
||||
* @deprecated Use {@link Level#FATAL} instead.
|
||||
*/
|
||||
final static public Priority FATAL = new Level(FATAL_INT, "FATAL", 0);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Level#ERROR} instead.
|
||||
*/
|
||||
final static public Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
|
||||
/**
|
||||
* @deprecated Use {@link Level#ERROR} instead.
|
||||
*/
|
||||
final static public Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Level#WARN} instead.
|
||||
*/
|
||||
final static public Priority WARN = new Level(WARN_INT, "WARN", 4);
|
||||
/**
|
||||
* @deprecated Use {@link Level#WARN} instead.
|
||||
*/
|
||||
final static public Priority WARN = new Level(WARN_INT, "WARN", 4);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Level#INFO} instead.
|
||||
*/
|
||||
final static public Priority INFO = new Level(INFO_INT, "INFO", 6);
|
||||
/**
|
||||
* @deprecated Use {@link Level#INFO} instead.
|
||||
*/
|
||||
final static public Priority INFO = new Level(INFO_INT, "INFO", 6);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Level#DEBUG} instead.
|
||||
*/
|
||||
final static public Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
|
||||
/**
|
||||
* @deprecated Use {@link Level#DEBUG} instead.
|
||||
*/
|
||||
final static public Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor for deserialization.
|
||||
*/
|
||||
protected Priority() {
|
||||
level = DEBUG_INT;
|
||||
levelStr = "DEBUG";
|
||||
syslogEquivalent = 7;
|
||||
}
|
||||
|
||||
/**
|
||||
Instantiate a level object.
|
||||
*/
|
||||
protected
|
||||
Priority(int level, String levelStr, int syslogEquivalent) {
|
||||
this.level = level;
|
||||
this.levelStr = levelStr;
|
||||
this.syslogEquivalent = syslogEquivalent;
|
||||
}
|
||||
|
||||
/**
|
||||
Two priorities are equal if their level fields are equal.
|
||||
@since 1.2
|
||||
*/
|
||||
public
|
||||
boolean equals(Object o) {
|
||||
if(o instanceof Priority) {
|
||||
Priority r = (Priority) o;
|
||||
return (this.level == r.level);
|
||||
} else {
|
||||
return false;
|
||||
/**
|
||||
* Default constructor for deserialization.
|
||||
*/
|
||||
protected Priority() {
|
||||
level = DEBUG_INT;
|
||||
levelStr = "DEBUG";
|
||||
syslogEquivalent = 7;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Return the syslog equivalent of this priority as an integer.
|
||||
*/
|
||||
public
|
||||
final
|
||||
int getSyslogEquivalent() {
|
||||
return syslogEquivalent;
|
||||
}
|
||||
/**
|
||||
Instantiate a level object.
|
||||
*/
|
||||
protected Priority(int level, String levelStr, int syslogEquivalent) {
|
||||
this.level = level;
|
||||
this.levelStr = levelStr;
|
||||
this.syslogEquivalent = syslogEquivalent;
|
||||
}
|
||||
|
||||
/**
|
||||
Two priorities are equal if their level fields are equal.
|
||||
@since 1.2
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Priority) {
|
||||
Priority r = (Priority) o;
|
||||
return (this.level == r.level);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Return the syslog equivalent of this priority as an integer.
|
||||
*/
|
||||
public final int getSyslogEquivalent() {
|
||||
return syslogEquivalent;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns <code>true</code> if this level has a higher or equal
|
||||
level than the level passed as argument, <code>false</code>
|
||||
otherwise.
|
||||
/**
|
||||
Returns <code>true</code> if this level has a higher or equal
|
||||
level than the level passed as argument, <code>false</code>
|
||||
otherwise.
|
||||
|
||||
<p>You should think twice before overriding the default
|
||||
implementation of <code>isGreaterOrEqual</code> method.
|
||||
<p>You should think twice before overriding the default
|
||||
implementation of <code>isGreaterOrEqual</code> method.
|
||||
|
||||
*/
|
||||
public
|
||||
boolean isGreaterOrEqual(Priority r) {
|
||||
return level >= r.level;
|
||||
}
|
||||
*/
|
||||
public boolean isGreaterOrEqual(Priority r) {
|
||||
return level >= r.level;
|
||||
}
|
||||
|
||||
/**
|
||||
Return all possible priorities as an array of Level objects in
|
||||
descending order.
|
||||
/**
|
||||
Return all possible priorities as an array of Level objects in
|
||||
descending order.
|
||||
|
||||
@deprecated This method will be removed with no replacement.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Priority[] getAllPossiblePriorities() {
|
||||
return new Priority[] {Priority.FATAL, Priority.ERROR, Level.WARN,
|
||||
Priority.INFO, Priority.DEBUG};
|
||||
}
|
||||
@deprecated This method will be removed with no replacement.
|
||||
*/
|
||||
public static Priority[] getAllPossiblePriorities() {
|
||||
return new Priority[] { Priority.FATAL, Priority.ERROR, Level.WARN, Priority.INFO, Priority.DEBUG };
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the string representation of this priority.
|
||||
*/
|
||||
final public String toString() {
|
||||
return levelStr;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the string representation of this priority.
|
||||
*/
|
||||
final
|
||||
public
|
||||
String toString() {
|
||||
return levelStr;
|
||||
}
|
||||
/**
|
||||
Returns the integer representation of this level.
|
||||
*/
|
||||
public final int toInt() {
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the integer representation of this level.
|
||||
*/
|
||||
public
|
||||
final
|
||||
int toInt() {
|
||||
return level;
|
||||
}
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(String)} method instead.
|
||||
*/
|
||||
public static Priority toPriority(String sArg) {
|
||||
return Level.toLevel(sArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(String)} method instead.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Priority toPriority(String sArg) {
|
||||
return Level.toLevel(sArg);
|
||||
}
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(int)} method instead.
|
||||
*/
|
||||
public static Priority toPriority(int val) {
|
||||
return toPriority(val, Priority.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(int)} method instead.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Priority toPriority(int val) {
|
||||
return toPriority(val, Priority.DEBUG);
|
||||
}
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(int, Level)} method instead.
|
||||
*/
|
||||
public static Priority toPriority(int val, Priority defaultPriority) {
|
||||
return Level.toLevel(val, (Level) defaultPriority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(int, Level)} method instead.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Priority toPriority(int val, Priority defaultPriority) {
|
||||
return Level.toLevel(val, (Level) defaultPriority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(String, Level)} method instead.
|
||||
*/
|
||||
public
|
||||
static
|
||||
Priority toPriority(String sArg, Priority defaultPriority) {
|
||||
return Level.toLevel(sArg, (Level) defaultPriority);
|
||||
}
|
||||
/**
|
||||
* @deprecated Please use the {@link Level#toLevel(String, Level)} method instead.
|
||||
*/
|
||||
public static Priority toPriority(String sArg, Priority defaultPriority) {
|
||||
return Level.toLevel(sArg, (Level) defaultPriority);
|
||||
}
|
||||
}
|
||||
|
|
@ -26,27 +26,27 @@ import org.apache.log4j.spi.LoggerRepository;
|
|||
* An nop implementation of PropertyConfigurator.
|
||||
*/
|
||||
public class PropertyConfigurator implements Configurator {
|
||||
public static void configure(Properties properties) {
|
||||
}
|
||||
public static void configure(Properties properties) {
|
||||
}
|
||||
|
||||
public static void configure(String configFilename) {
|
||||
}
|
||||
public static void configure(String configFilename) {
|
||||
}
|
||||
|
||||
public static void configure(java.net.URL configURL) {
|
||||
}
|
||||
public static void configure(java.net.URL configURL) {
|
||||
}
|
||||
|
||||
public static void configureAndWatch(String configFilename) {
|
||||
}
|
||||
public static void configureAndWatch(String configFilename) {
|
||||
}
|
||||
|
||||
public static void configureAndWatch(String configFilename, long delay) {
|
||||
}
|
||||
public static void configureAndWatch(String configFilename, long delay) {
|
||||
}
|
||||
|
||||
public void doConfigure(Properties properties, LoggerRepository hierarchy) {
|
||||
}
|
||||
public void doConfigure(Properties properties, LoggerRepository hierarchy) {
|
||||
}
|
||||
|
||||
public void doConfigure(String configFileName, LoggerRepository hierarchy) {
|
||||
}
|
||||
public void doConfigure(String configFileName, LoggerRepository hierarchy) {
|
||||
}
|
||||
|
||||
public void doConfigure(URL configURL, LoggerRepository hierarchy) {
|
||||
}
|
||||
public void doConfigure(URL configURL, LoggerRepository hierarchy) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,25 +26,24 @@ import java.io.IOException;
|
|||
* */
|
||||
public class RollingFileAppender {
|
||||
|
||||
public RollingFileAppender() {
|
||||
super();
|
||||
}
|
||||
public RollingFileAppender() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RollingFileAppender(Layout layout, String filename) throws IOException {
|
||||
super();
|
||||
}
|
||||
public RollingFileAppender(Layout layout, String filename) throws IOException {
|
||||
super();
|
||||
}
|
||||
|
||||
public RollingFileAppender(Layout layout, String filename, boolean append)
|
||||
throws IOException {
|
||||
super();
|
||||
}
|
||||
public RollingFileAppender(Layout layout, String filename, boolean append) throws IOException {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setMaxBackupIndex(int maxBackups) {
|
||||
// nothing to do
|
||||
}
|
||||
public void setMaxBackupIndex(int maxBackups) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void setMaximumFileSize(long maxFileSize) {
|
||||
// nothing to do
|
||||
}
|
||||
public void setMaximumFileSize(long maxFileSize) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,146 +34,128 @@ package org.apache.log4j.helpers;
|
|||
*/
|
||||
public class LogLog {
|
||||
|
||||
/**
|
||||
Defining this value makes log4j print log4j-internal debug
|
||||
statements to <code>System.out</code>.
|
||||
/**
|
||||
Defining this value makes log4j print log4j-internal debug
|
||||
statements to <code>System.out</code>.
|
||||
|
||||
<p> The value of this string is <b>log4j.debug</b>.
|
||||
<p> The value of this string is <b>log4j.debug</b>.
|
||||
|
||||
<p>Note that the search for all option names is case sensitive. */
|
||||
public static final String DEBUG_KEY="log4j.debug";
|
||||
<p>Note that the search for all option names is case sensitive. */
|
||||
public static final String DEBUG_KEY = "log4j.debug";
|
||||
|
||||
/**
|
||||
Defining this value makes log4j components print log4j-internal
|
||||
debug statements to <code>System.out</code>.
|
||||
|
||||
/**
|
||||
Defining this value makes log4j components print log4j-internal
|
||||
debug statements to <code>System.out</code>.
|
||||
<p> The value of this string is <b>log4j.configDebug</b>.
|
||||
|
||||
<p> The value of this string is <b>log4j.configDebug</b>.
|
||||
<p>Note that the search for all option names is case sensitive.
|
||||
|
||||
<p>Note that the search for all option names is case sensitive.
|
||||
@deprecated Use {@link #DEBUG_KEY} instead.
|
||||
*/
|
||||
public static final String CONFIG_DEBUG_KEY = "log4j.configDebug";
|
||||
|
||||
@deprecated Use {@link #DEBUG_KEY} instead.
|
||||
*/
|
||||
public static final String CONFIG_DEBUG_KEY="log4j.configDebug";
|
||||
protected static boolean debugEnabled = false;
|
||||
|
||||
protected static boolean debugEnabled = false;
|
||||
/**
|
||||
In quietMode not even errors generate any output.
|
||||
*/
|
||||
private static boolean quietMode = false;
|
||||
|
||||
/**
|
||||
In quietMode not even errors generate any output.
|
||||
*/
|
||||
private static boolean quietMode = false;
|
||||
private static final String PREFIX = "log4j: ";
|
||||
private static final String ERR_PREFIX = "log4j:ERROR ";
|
||||
private static final String WARN_PREFIX = "log4j:WARN ";
|
||||
|
||||
private static final String PREFIX = "log4j: ";
|
||||
private static final String ERR_PREFIX = "log4j:ERROR ";
|
||||
private static final String WARN_PREFIX = "log4j:WARN ";
|
||||
|
||||
static {
|
||||
}
|
||||
|
||||
/**
|
||||
Allows to enable/disable log4j internal logging.
|
||||
*/
|
||||
static
|
||||
public
|
||||
void setInternalDebugging(boolean enabled) {
|
||||
debugEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal debug
|
||||
statements. Output goes to <code>System.out</code>.
|
||||
*/
|
||||
public
|
||||
static
|
||||
void debug(String msg) {
|
||||
if(debugEnabled && !quietMode) {
|
||||
System.out.println(PREFIX+msg);
|
||||
static {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal debug
|
||||
statements. Output goes to <code>System.out</code>.
|
||||
*/
|
||||
public
|
||||
static
|
||||
void debug(String msg, Throwable t) {
|
||||
if(debugEnabled && !quietMode) {
|
||||
System.out.println(PREFIX+msg);
|
||||
if(t != null)
|
||||
t.printStackTrace(System.out);
|
||||
/**
|
||||
Allows to enable/disable log4j internal logging.
|
||||
*/
|
||||
static public void setInternalDebugging(boolean enabled) {
|
||||
debugEnabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal error
|
||||
statements. There is no way to disable error statements.
|
||||
Output goes to <code>System.err</code>.
|
||||
*/
|
||||
public
|
||||
static
|
||||
void error(String msg) {
|
||||
if(quietMode)
|
||||
return;
|
||||
System.err.println(ERR_PREFIX+msg);
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal error
|
||||
statements. There is no way to disable error statements.
|
||||
Output goes to <code>System.err</code>.
|
||||
*/
|
||||
public
|
||||
static
|
||||
void error(String msg, Throwable t) {
|
||||
if(quietMode)
|
||||
return;
|
||||
|
||||
System.err.println(ERR_PREFIX+msg);
|
||||
if(t != null) {
|
||||
t.printStackTrace();
|
||||
/**
|
||||
This method is used to output log4j internal debug
|
||||
statements. Output goes to <code>System.out</code>.
|
||||
*/
|
||||
public static void debug(String msg) {
|
||||
if (debugEnabled && !quietMode) {
|
||||
System.out.println(PREFIX + msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
In quite mode no LogLog generates strictly no output, not even
|
||||
for errors.
|
||||
|
||||
@param quietMode A true for not
|
||||
*/
|
||||
public
|
||||
static
|
||||
void setQuietMode(boolean quietMode) {
|
||||
LogLog.quietMode = quietMode;
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal warning
|
||||
statements. There is no way to disable warning statements.
|
||||
Output goes to <code>System.err</code>. */
|
||||
public
|
||||
static
|
||||
void warn(String msg) {
|
||||
if(quietMode)
|
||||
return;
|
||||
|
||||
System.err.println(WARN_PREFIX+msg);
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal warnings. There is
|
||||
no way to disable warning statements. Output goes to
|
||||
<code>System.err</code>. */
|
||||
public
|
||||
static
|
||||
void warn(String msg, Throwable t) {
|
||||
if(quietMode)
|
||||
return;
|
||||
|
||||
System.err.println(WARN_PREFIX+msg);
|
||||
if(t != null) {
|
||||
t.printStackTrace();
|
||||
/**
|
||||
This method is used to output log4j internal debug
|
||||
statements. Output goes to <code>System.out</code>.
|
||||
*/
|
||||
public static void debug(String msg, Throwable t) {
|
||||
if (debugEnabled && !quietMode) {
|
||||
System.out.println(PREFIX + msg);
|
||||
if (t != null)
|
||||
t.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal error
|
||||
statements. There is no way to disable error statements.
|
||||
Output goes to <code>System.err</code>.
|
||||
*/
|
||||
public static void error(String msg) {
|
||||
if (quietMode)
|
||||
return;
|
||||
System.err.println(ERR_PREFIX + msg);
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal error
|
||||
statements. There is no way to disable error statements.
|
||||
Output goes to <code>System.err</code>.
|
||||
*/
|
||||
public static void error(String msg, Throwable t) {
|
||||
if (quietMode)
|
||||
return;
|
||||
|
||||
System.err.println(ERR_PREFIX + msg);
|
||||
if (t != null) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
In quite mode no LogLog generates strictly no output, not even
|
||||
for errors.
|
||||
|
||||
@param quietMode A true for not
|
||||
*/
|
||||
public static void setQuietMode(boolean quietMode) {
|
||||
LogLog.quietMode = quietMode;
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal warning
|
||||
statements. There is no way to disable warning statements.
|
||||
Output goes to <code>System.err</code>. */
|
||||
public static void warn(String msg) {
|
||||
if (quietMode)
|
||||
return;
|
||||
|
||||
System.err.println(WARN_PREFIX + msg);
|
||||
}
|
||||
|
||||
/**
|
||||
This method is used to output log4j internal warnings. There is
|
||||
no way to disable warning statements. Output goes to
|
||||
<code>System.err</code>. */
|
||||
public static void warn(String msg, Throwable t) {
|
||||
if (quietMode)
|
||||
return;
|
||||
|
||||
System.err.println(WARN_PREFIX + msg);
|
||||
if (t != null) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,20 +28,20 @@ import java.util.NoSuchElementException;
|
|||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class NullEnumeration implements Enumeration {
|
||||
private static final NullEnumeration instance = new NullEnumeration();
|
||||
private static final NullEnumeration instance = new NullEnumeration();
|
||||
|
||||
private NullEnumeration() {
|
||||
}
|
||||
private NullEnumeration() {
|
||||
}
|
||||
|
||||
public static NullEnumeration getInstance() {
|
||||
return instance;
|
||||
}
|
||||
public static NullEnumeration getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return false;
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
public Object nextElement() {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.apache.log4j.spi;
|
||||
|
||||
|
||||
import org.apache.log4j.spi.LoggerRepository;
|
||||
import java.net.URL;
|
||||
|
||||
|
|
@ -28,28 +27,26 @@ import java.net.URL;
|
|||
*/
|
||||
public interface Configurator {
|
||||
|
||||
/**
|
||||
Special level value signifying inherited behaviour. The current
|
||||
value of this string constant is <b>inherited</b>. {@link #NULL}
|
||||
is a synonym. */
|
||||
public static final String INHERITED = "inherited";
|
||||
/**
|
||||
Special level value signifying inherited behaviour. The current
|
||||
value of this string constant is <b>inherited</b>. {@link #NULL}
|
||||
is a synonym. */
|
||||
public static final String INHERITED = "inherited";
|
||||
|
||||
/**
|
||||
Special level signifying inherited behaviour, same as {@link
|
||||
#INHERITED}. The current value of this string constant is
|
||||
<b>null</b>. */
|
||||
public static final String NULL = "null";
|
||||
/**
|
||||
Special level signifying inherited behaviour, same as {@link
|
||||
#INHERITED}. The current value of this string constant is
|
||||
<b>null</b>. */
|
||||
public static final String NULL = "null";
|
||||
|
||||
/**
|
||||
Interpret a resource pointed by a URL and set up log4j accordingly.
|
||||
|
||||
The configuration is done relative to the <code>hierarchy</code>
|
||||
parameter.
|
||||
|
||||
/**
|
||||
Interpret a resource pointed by a URL and set up log4j accordingly.
|
||||
|
||||
The configuration is done relative to the <code>hierarchy</code>
|
||||
parameter.
|
||||
|
||||
@param url The URL to parse
|
||||
@param repository The hierarchy to operation upon.
|
||||
*/
|
||||
void doConfigure(URL url, LoggerRepository repository);
|
||||
@param url The URL to parse
|
||||
@param repository The hierarchy to operation upon.
|
||||
*/
|
||||
void doConfigure(URL url, LoggerRepository repository);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,16 +28,11 @@ import org.apache.log4j.*;
|
|||
*/
|
||||
public interface HierarchyEventListener {
|
||||
|
||||
// public
|
||||
// void categoryCreationEvent(Category cat);
|
||||
|
||||
//public
|
||||
//void categoryCreationEvent(Category cat);
|
||||
|
||||
|
||||
public
|
||||
void addAppenderEvent(Category cat, Appender appender);
|
||||
|
||||
public
|
||||
void removeAppenderEvent(Category cat, Appender appender);
|
||||
public void addAppenderEvent(Category cat, Appender appender);
|
||||
|
||||
public void removeAppenderEvent(Category cat, Appender appender);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import org.apache.log4j.Logger;
|
|||
*/
|
||||
public interface LoggerFactory {
|
||||
|
||||
public
|
||||
Logger makeNewLoggerInstance(String name);
|
||||
public Logger makeNewLoggerInstance(String name);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,11 +75,9 @@ public interface LoggerRepository {
|
|||
|
||||
public Logger getRootLogger();
|
||||
|
||||
public
|
||||
abstract Logger exists(String name);
|
||||
public abstract Logger exists(String name);
|
||||
|
||||
public
|
||||
abstract void shutdown();
|
||||
public abstract void shutdown();
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getCurrentLoggers();
|
||||
|
|
@ -90,11 +88,8 @@ public interface LoggerRepository {
|
|||
@SuppressWarnings("rawtypes")
|
||||
public Enumeration getCurrentCategories();
|
||||
|
||||
public abstract void fireAddAppenderEvent(Category logger, Appender appender);
|
||||
|
||||
public
|
||||
abstract void fireAddAppenderEvent(Category logger, Appender appender);
|
||||
|
||||
public
|
||||
abstract void resetConfiguration();
|
||||
public abstract void resetConfiguration();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ package org.apache.log4j.spi;
|
|||
|
||||
public interface OptionHandler {
|
||||
|
||||
void activateOptions();
|
||||
void activateOptions();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,43 +25,42 @@ import java.io.Reader;
|
|||
import java.net.URL;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class DOMConfigurator implements Configurator {
|
||||
|
||||
public static void configure(Element element) {
|
||||
}
|
||||
public static void configure(Element element) {
|
||||
}
|
||||
|
||||
public static void configure(String filename) throws FactoryConfigurationError {
|
||||
}
|
||||
public static void configure(String filename) throws FactoryConfigurationError {
|
||||
}
|
||||
|
||||
static public void configure(URL url) throws FactoryConfigurationError {
|
||||
}
|
||||
static public void configure(URL url) throws FactoryConfigurationError {
|
||||
}
|
||||
|
||||
static public void configureAndWatch(String configFilename) {
|
||||
}
|
||||
static public void configureAndWatch(String configFilename) {
|
||||
}
|
||||
|
||||
public static void configureAndWatch(String configFilename, long delay) {
|
||||
}
|
||||
public static void configureAndWatch(String configFilename, long delay) {
|
||||
}
|
||||
|
||||
public void doConfigure(Element element, LoggerRepository repository) {
|
||||
}
|
||||
public void doConfigure(Element element, LoggerRepository repository) {
|
||||
}
|
||||
|
||||
public void doConfigure(InputStream inputStream, LoggerRepository repository) throws FactoryConfigurationError {
|
||||
}
|
||||
public void doConfigure(InputStream inputStream, LoggerRepository repository) throws FactoryConfigurationError {
|
||||
}
|
||||
|
||||
public void doConfigure(Reader reader, LoggerRepository repository) throws FactoryConfigurationError {
|
||||
}
|
||||
public void doConfigure(Reader reader, LoggerRepository repository) throws FactoryConfigurationError {
|
||||
}
|
||||
|
||||
public void doConfigure(String filename, LoggerRepository repository) {
|
||||
}
|
||||
public void doConfigure(String filename, LoggerRepository repository) {
|
||||
}
|
||||
|
||||
public void doConfigure(URL url, LoggerRepository repository) {
|
||||
}
|
||||
public void doConfigure(URL url, LoggerRepository repository) {
|
||||
}
|
||||
|
||||
public static String subst(String value, Properties props) {
|
||||
return value;
|
||||
}
|
||||
public static String subst(String value, Properties props) {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,31 +31,30 @@ import junit.framework.TestCase;
|
|||
*/
|
||||
public class NDCTest extends TestCase {
|
||||
|
||||
public void setUp() {
|
||||
assertEquals(0, NDC.getDepth());
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
assertEquals(0, NDC.getDepth());
|
||||
}
|
||||
public void tearDown() {
|
||||
NDC.clear();
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
NDC.clear();
|
||||
}
|
||||
public void testSmoke() {
|
||||
NDC.push("a");
|
||||
String back = NDC.pop();
|
||||
assertEquals("a", back);
|
||||
}
|
||||
|
||||
public void testSmoke() {
|
||||
NDC.push("a");
|
||||
String back = NDC.pop();
|
||||
assertEquals("a", back);
|
||||
}
|
||||
public void testPop() {
|
||||
NDC.push("peek");
|
||||
String back = NDC.peek();
|
||||
assertEquals("peek", back);
|
||||
}
|
||||
|
||||
public void testPop() {
|
||||
NDC.push("peek");
|
||||
String back = NDC.peek();
|
||||
assertEquals("peek", back);
|
||||
}
|
||||
|
||||
public void testClear() {
|
||||
NDC.push("clear");
|
||||
NDC.clear();
|
||||
assertEquals(0, NDC.getDepth());
|
||||
}
|
||||
public void testClear() {
|
||||
NDC.push("clear");
|
||||
NDC.clear();
|
||||
assertEquals(0, NDC.getDepth());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,22 +30,22 @@ import junit.framework.TestCase;
|
|||
|
||||
public class Trivial extends TestCase {
|
||||
|
||||
public void testSmoke() {
|
||||
Logger l = Logger.getLogger("a");
|
||||
l.trace("t");
|
||||
l.debug("d");
|
||||
l.info("i");
|
||||
l.warn("w");
|
||||
l.error("e");
|
||||
l.fatal("f");
|
||||
public void testSmoke() {
|
||||
Logger l = Logger.getLogger("a");
|
||||
l.trace("t");
|
||||
l.debug("d");
|
||||
l.info("i");
|
||||
l.warn("w");
|
||||
l.error("e");
|
||||
l.fatal("f");
|
||||
|
||||
Exception e = new Exception("testing");
|
||||
l.trace("t", e);
|
||||
l.debug("d", e);
|
||||
l.info("i", e);
|
||||
l.warn("w", e);
|
||||
l.error("e", e);
|
||||
l.fatal("f", e);
|
||||
}
|
||||
Exception e = new Exception("testing");
|
||||
l.trace("t", e);
|
||||
l.debug("d", e);
|
||||
l.info("i", e);
|
||||
l.warn("w", e);
|
||||
l.error("e", e);
|
||||
l.fatal("f", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,35 +34,35 @@ import org.apache.log4j.Logger;
|
|||
|
||||
public class Bug131 extends TestCase {
|
||||
|
||||
public void testBug131() {
|
||||
public void testBug131() {
|
||||
|
||||
ListHandler listHandler = new ListHandler();
|
||||
java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
|
||||
root.addHandler(listHandler);
|
||||
root.setLevel(Level.FINEST);
|
||||
Logger log4jLogger = Logger.getLogger("a");
|
||||
Category log4jCategory = Logger.getLogger("b");
|
||||
ListHandler listHandler = new ListHandler();
|
||||
java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
|
||||
root.addHandler(listHandler);
|
||||
root.setLevel(Level.FINEST);
|
||||
Logger log4jLogger = Logger.getLogger("a");
|
||||
Category log4jCategory = Logger.getLogger("b");
|
||||
|
||||
int n = 0;
|
||||
int n = 0;
|
||||
|
||||
log4jLogger.trace("msg" +(n++));
|
||||
log4jLogger.debug("msg" +(n++));
|
||||
log4jLogger.info("msg" +(n++));
|
||||
log4jLogger.warn("msg" +(n++));
|
||||
log4jLogger.error("msg" +(n++));
|
||||
log4jLogger.fatal("msg" +(n++));
|
||||
log4jLogger.trace("msg" + (n++));
|
||||
log4jLogger.debug("msg" + (n++));
|
||||
log4jLogger.info("msg" + (n++));
|
||||
log4jLogger.warn("msg" + (n++));
|
||||
log4jLogger.error("msg" + (n++));
|
||||
log4jLogger.fatal("msg" + (n++));
|
||||
|
||||
log4jCategory.debug("msg" +(n++));
|
||||
log4jCategory.info("msg" +(n++));
|
||||
log4jCategory.warn("msg" +(n++));
|
||||
log4jCategory.error("msg" +(n++));
|
||||
log4jCategory.fatal("msg" +(n++));
|
||||
log4jCategory.debug("msg" + (n++));
|
||||
log4jCategory.info("msg" + (n++));
|
||||
log4jCategory.warn("msg" + (n++));
|
||||
log4jCategory.error("msg" + (n++));
|
||||
log4jCategory.fatal("msg" + (n++));
|
||||
|
||||
assertEquals(n, listHandler.list.size());
|
||||
assertEquals(n, listHandler.list.size());
|
||||
|
||||
for(int i = 0; i < n; i++) {
|
||||
LogRecord logRecord = (LogRecord) listHandler.list.get(i);
|
||||
assertEquals("testBug131", logRecord.getSourceMethodName());
|
||||
for (int i = 0; i < n; i++) {
|
||||
LogRecord logRecord = (LogRecord) listHandler.list.get(i);
|
||||
assertEquals("testBug131", logRecord.getSourceMethodName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,24 +34,24 @@ import org.apache.log4j.Logger;
|
|||
|
||||
public class Bug139 extends TestCase {
|
||||
|
||||
public void test() {
|
||||
ListHandler listHandler = new ListHandler();
|
||||
java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
|
||||
root.addHandler(listHandler);
|
||||
root.setLevel(Level.FINEST);
|
||||
Logger log4jLogger = Logger.getLogger("a");
|
||||
Category log4jCategory = Logger.getLogger("b");
|
||||
public void test() {
|
||||
ListHandler listHandler = new ListHandler();
|
||||
java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
|
||||
root.addHandler(listHandler);
|
||||
root.setLevel(Level.FINEST);
|
||||
Logger log4jLogger = Logger.getLogger("a");
|
||||
Category log4jCategory = Logger.getLogger("b");
|
||||
|
||||
int n = 0;
|
||||
int n = 0;
|
||||
|
||||
log4jLogger.log(org.apache.log4j.Level.DEBUG, "hello"+(++n));
|
||||
log4jCategory.log(org.apache.log4j.Level.DEBUG, "world"+(++n));
|
||||
log4jLogger.log(org.apache.log4j.Level.DEBUG, "hello" + (++n));
|
||||
log4jCategory.log(org.apache.log4j.Level.DEBUG, "world" + (++n));
|
||||
|
||||
assertEquals(n, listHandler.list.size());
|
||||
assertEquals(n, listHandler.list.size());
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
LogRecord logRecord = (LogRecord) listHandler.list.get(i);
|
||||
assertEquals("test", logRecord.getSourceMethodName());
|
||||
for (int i = 0; i < n; i++) {
|
||||
LogRecord logRecord = (LogRecord) listHandler.list.get(i);
|
||||
assertEquals("test", logRecord.getSourceMethodName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,19 +31,19 @@ import java.util.logging.LogRecord;
|
|||
|
||||
public class ListHandler extends Handler {
|
||||
|
||||
List<LogRecord> list = new ArrayList<LogRecord>();
|
||||
List<LogRecord> list = new ArrayList<LogRecord>();
|
||||
|
||||
public void close() throws SecurityException {
|
||||
public void close() throws SecurityException {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void publish(LogRecord logRecord) {
|
||||
logRecord.getSourceClassName();
|
||||
list.add(logRecord);
|
||||
}
|
||||
public void publish(LogRecord logRecord) {
|
||||
logRecord.getSourceClassName();
|
||||
list.add(logRecord);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ import org.osgi.service.log.LogService;
|
|||
public class Activator implements BundleActivator {
|
||||
/**
|
||||
*
|
||||
* Implements <code>BundleActivator.start()</code> to register a
|
||||
* Implements <code>BundleActivator.start()</code> to register a
|
||||
* LogServiceFactory.
|
||||
*
|
||||
* @param bundleContext the framework context for the bundle
|
||||
|
|
|
|||
|
|
@ -43,18 +43,23 @@ import org.osgi.framework.ServiceRegistration;
|
|||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class LogServiceFactory implements ServiceFactory {
|
||||
/* (non-Javadoc)
|
||||
* @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle,
|
||||
* org.osgi.framework.ServiceRegistration)
|
||||
*/
|
||||
public Object getService(Bundle bundle, ServiceRegistration arg1) {
|
||||
return new LogServiceImpl(bundle);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle,
|
||||
* org.osgi.framework.ServiceRegistration, java.lang.Object)
|
||||
*/
|
||||
public void ungetService(Bundle bundle, ServiceRegistration arg1, Object arg2) {
|
||||
//nothing to do.
|
||||
// nothing to do.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,162 +48,159 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public class LogServiceImpl implements LogService {
|
||||
|
||||
private static final String UNKNOWN = "[Unknown]";
|
||||
private static final String UNKNOWN = "[Unknown]";
|
||||
|
||||
private final Logger delegate;
|
||||
private final Logger delegate;
|
||||
|
||||
/**
|
||||
* Creates a new instance of LogServiceImpl.
|
||||
*
|
||||
* @param bundle The bundle to create a new LogService for.
|
||||
*/
|
||||
public LogServiceImpl(Bundle bundle) {
|
||||
|
||||
/**
|
||||
* Creates a new instance of LogServiceImpl.
|
||||
*
|
||||
* @param bundle The bundle to create a new LogService for.
|
||||
*/
|
||||
public LogServiceImpl(Bundle bundle) {
|
||||
String name = bundle.getSymbolicName();
|
||||
Version version = bundle.getVersion();
|
||||
if (version == null) {
|
||||
version = Version.emptyVersion;
|
||||
}
|
||||
delegate = LoggerFactory.getLogger(name + '.' + version);
|
||||
}
|
||||
|
||||
String name = bundle.getSymbolicName();
|
||||
Version version = bundle.getVersion();
|
||||
if (version == null) {
|
||||
version = Version.emptyVersion;
|
||||
}
|
||||
delegate = LoggerFactory.getLogger(name + '.' + version);
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(int, java.lang.String)
|
||||
*/
|
||||
public void log(int level, String message) {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(int, java.lang.String)
|
||||
*/
|
||||
public void log(int level, String message) {
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
delegate.debug(message);
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
delegate.error(message);
|
||||
break;
|
||||
case LOG_INFO:
|
||||
delegate.info(message);
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
delegate.warn(message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
delegate.debug(message);
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
delegate.error(message);
|
||||
break;
|
||||
case LOG_INFO:
|
||||
delegate.info(message);
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
delegate.warn(message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(int, java.lang.String, java.lang.Throwable)
|
||||
*/
|
||||
public void log(int level, String message, Throwable exception) {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(int, java.lang.String,
|
||||
* java.lang.Throwable)
|
||||
*/
|
||||
public void log(int level, String message, Throwable exception) {
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
delegate.debug(message, exception);
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
delegate.error(message, exception);
|
||||
break;
|
||||
case LOG_INFO:
|
||||
delegate.info(message, exception);
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
delegate.warn(message, exception);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
delegate.debug(message, exception);
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
delegate.error(message, exception);
|
||||
break;
|
||||
case LOG_INFO:
|
||||
delegate.info(message, exception);
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
delegate.warn(message, exception);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(org.osgi.framework.ServiceReference, int, java.lang.String)
|
||||
*/
|
||||
public void log(ServiceReference sr, int level, String message) {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(org.osgi.framework.ServiceReference,
|
||||
* int, java.lang.String)
|
||||
*/
|
||||
public void log(ServiceReference sr, int level, String message) {
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
if (delegate.isDebugEnabled()) {
|
||||
delegate.debug(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
if (delegate.isErrorEnabled()) {
|
||||
delegate.error(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
case LOG_INFO:
|
||||
if (delegate.isInfoEnabled()) {
|
||||
delegate.info(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
if (delegate.isWarnEnabled()) {
|
||||
delegate.warn(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
if(delegate.isDebugEnabled()){
|
||||
delegate.debug(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
if(delegate.isErrorEnabled()){
|
||||
delegate.error(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
case LOG_INFO:
|
||||
if(delegate.isInfoEnabled()){
|
||||
delegate.info(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
if(delegate.isWarnEnabled()){
|
||||
delegate.warn(createMessage(sr, message));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Formats the log message to indicate the service sending it, if known.
|
||||
*
|
||||
* @param sr the ServiceReference sending the message.
|
||||
* @param message The message to log.
|
||||
* @return The formatted log message.
|
||||
*/
|
||||
private String createMessage(ServiceReference sr, String message) {
|
||||
|
||||
/**
|
||||
* Formats the log message to indicate the service sending it, if known.
|
||||
*
|
||||
* @param sr the ServiceReference sending the message.
|
||||
* @param message The message to log.
|
||||
* @return The formatted log message.
|
||||
*/
|
||||
private String createMessage(ServiceReference sr, String message) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
if (sr != null) {
|
||||
output.append('[').append(sr.toString()).append(']');
|
||||
} else {
|
||||
output.append(UNKNOWN);
|
||||
}
|
||||
output.append(message);
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
if (sr != null) {
|
||||
output.append('[').append(sr.toString()).append(']');
|
||||
} else {
|
||||
output.append(UNKNOWN);
|
||||
}
|
||||
output.append(message);
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(org.osgi.framework.ServiceReference, int, java.lang.String,
|
||||
* java.lang.Throwable)
|
||||
*/
|
||||
public void log(ServiceReference sr, int level, String message, Throwable exception) {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.osgi.service.log.LogService#log(org.osgi.framework.ServiceReference,
|
||||
* int, java.lang.String, java.lang.Throwable)
|
||||
*/
|
||||
public void log(ServiceReference sr, int level, String message, Throwable exception) {
|
||||
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
if(delegate.isDebugEnabled()){
|
||||
delegate.debug(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
if(delegate.isErrorEnabled()){
|
||||
delegate.error(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
case LOG_INFO:
|
||||
if(delegate.isInfoEnabled()){
|
||||
delegate.info(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
if(delegate.isWarnEnabled()){
|
||||
delegate.warn(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (level) {
|
||||
case LOG_DEBUG:
|
||||
if (delegate.isDebugEnabled()) {
|
||||
delegate.debug(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
if (delegate.isErrorEnabled()) {
|
||||
delegate.error(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
case LOG_INFO:
|
||||
if (delegate.isInfoEnabled()) {
|
||||
delegate.info(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
case LOG_WARNING:
|
||||
if (delegate.isWarnEnabled()) {
|
||||
delegate.warn(createMessage(sr, message), exception);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,21 +37,21 @@ package org.slf4j;
|
|||
*/
|
||||
public interface ILoggerFactory {
|
||||
|
||||
/**
|
||||
* Return an appropriate {@link Logger} instance as specified by the
|
||||
* <code>name</code> parameter.
|
||||
*
|
||||
* <p>If the name parameter is equal to {@link Logger#ROOT_LOGGER_NAME}, that is
|
||||
* the string value "ROOT" (case insensitive), then the root logger of the
|
||||
* underlying logging system is returned.
|
||||
*
|
||||
* <p>Null-valued name arguments are considered invalid.
|
||||
*
|
||||
* <p>Certain extremely simple logging systems, e.g. NOP, may always
|
||||
* return the same logger instance regardless of the requested name.
|
||||
*
|
||||
* @param name the name of the Logger to return
|
||||
* @return a Logger instance
|
||||
*/
|
||||
public Logger getLogger(String name);
|
||||
/**
|
||||
* Return an appropriate {@link Logger} instance as specified by the
|
||||
* <code>name</code> parameter.
|
||||
*
|
||||
* <p>If the name parameter is equal to {@link Logger#ROOT_LOGGER_NAME}, that is
|
||||
* the string value "ROOT" (case insensitive), then the root logger of the
|
||||
* underlying logging system is returned.
|
||||
*
|
||||
* <p>Null-valued name arguments are considered invalid.
|
||||
*
|
||||
* <p>Certain extremely simple logging systems, e.g. NOP, may always
|
||||
* return the same logger instance regardless of the requested name.
|
||||
*
|
||||
* @param name the name of the Logger to return
|
||||
* @return a Logger instance
|
||||
*/
|
||||
public Logger getLogger(String name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
*/
|
||||
package org.slf4j;
|
||||
|
||||
|
||||
/**
|
||||
* Implementations of this interface are used to manufacture {@link Marker}
|
||||
* instances.
|
||||
|
|
@ -37,47 +36,46 @@ package org.slf4j;
|
|||
*/
|
||||
public interface IMarkerFactory {
|
||||
|
||||
/**
|
||||
* Manufacture a {@link Marker} instance by name. If the instance has been
|
||||
* created earlier, return the previously created instance.
|
||||
*
|
||||
* <p>Null name values are not allowed.
|
||||
*
|
||||
* @param name the name of the marker to be created, null value is
|
||||
* not allowed.
|
||||
*
|
||||
* @return a Marker instance
|
||||
*/
|
||||
Marker getMarker(String name);
|
||||
/**
|
||||
* Manufacture a {@link Marker} instance by name. If the instance has been
|
||||
* created earlier, return the previously created instance.
|
||||
*
|
||||
* <p>Null name values are not allowed.
|
||||
*
|
||||
* @param name the name of the marker to be created, null value is
|
||||
* not allowed.
|
||||
*
|
||||
* @return a Marker instance
|
||||
*/
|
||||
Marker getMarker(String name);
|
||||
|
||||
/**
|
||||
* Checks if the marker with the name already exists. If name is null, then false
|
||||
* is returned.
|
||||
*
|
||||
* @param name logger name to check for
|
||||
* @return true id the marker exists, false otherwise.
|
||||
*/
|
||||
boolean exists(String name);
|
||||
/**
|
||||
* Checks if the marker with the name already exists. If name is null, then false
|
||||
* is returned.
|
||||
*
|
||||
* @param name logger name to check for
|
||||
* @return true id the marker exists, false otherwise.
|
||||
*/
|
||||
boolean exists(String name);
|
||||
|
||||
/**
|
||||
* Detach an existing marker.
|
||||
* <p>
|
||||
* Note that after a marker is detached, there might still be "dangling" references
|
||||
* to the detached marker.
|
||||
*
|
||||
*
|
||||
* @param name The name of the marker to detach
|
||||
* @return whether the marker could be detached or not
|
||||
*/
|
||||
boolean detachMarker(String name);
|
||||
/**
|
||||
* Detach an existing marker.
|
||||
* <p>
|
||||
* Note that after a marker is detached, there might still be "dangling" references
|
||||
* to the detached marker.
|
||||
*
|
||||
*
|
||||
* @param name The name of the marker to detach
|
||||
* @return whether the marker could be detached or not
|
||||
*/
|
||||
boolean detachMarker(String name);
|
||||
|
||||
|
||||
/**
|
||||
* Create a marker which is detached (even at birth) from this IMarkerFactory.
|
||||
*
|
||||
* @param name marker name
|
||||
* @return a dangling marker
|
||||
* @since 1.5.1
|
||||
*/
|
||||
Marker getDetachedMarker(String name);
|
||||
/**
|
||||
* Create a marker which is detached (even at birth) from this IMarkerFactory.
|
||||
*
|
||||
* @param name marker name
|
||||
* @return a dangling marker
|
||||
* @since 1.5.1
|
||||
*/
|
||||
Marker getDetachedMarker(String name);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -61,288 +61,287 @@ import org.slf4j.impl.StaticLoggerBinder;
|
|||
*/
|
||||
public final class LoggerFactory {
|
||||
|
||||
static final String CODES_PREFIX = "http://www.slf4j.org/codes.html";
|
||||
static final String CODES_PREFIX = "http://www.slf4j.org/codes.html";
|
||||
|
||||
static final String NO_STATICLOGGERBINDER_URL = CODES_PREFIX + "#StaticLoggerBinder";
|
||||
static final String MULTIPLE_BINDINGS_URL = CODES_PREFIX + "#multiple_bindings";
|
||||
static final String NULL_LF_URL = CODES_PREFIX + "#null_LF";
|
||||
static final String VERSION_MISMATCH = CODES_PREFIX + "#version_mismatch";
|
||||
static final String SUBSTITUTE_LOGGER_URL = CODES_PREFIX + "#substituteLogger";
|
||||
static final String LOGGER_NAME_MISMATCH_URL = CODES_PREFIX + "#loggerNameMismatch";
|
||||
static final String NO_STATICLOGGERBINDER_URL = CODES_PREFIX + "#StaticLoggerBinder";
|
||||
static final String MULTIPLE_BINDINGS_URL = CODES_PREFIX + "#multiple_bindings";
|
||||
static final String NULL_LF_URL = CODES_PREFIX + "#null_LF";
|
||||
static final String VERSION_MISMATCH = CODES_PREFIX + "#version_mismatch";
|
||||
static final String SUBSTITUTE_LOGGER_URL = CODES_PREFIX + "#substituteLogger";
|
||||
static final String LOGGER_NAME_MISMATCH_URL = CODES_PREFIX + "#loggerNameMismatch";
|
||||
|
||||
static final String UNSUCCESSFUL_INIT_URL = CODES_PREFIX + "#unsuccessfulInit";
|
||||
static final String UNSUCCESSFUL_INIT_MSG = "org.slf4j.LoggerFactory could not be successfully initialized. See also "
|
||||
+ UNSUCCESSFUL_INIT_URL;
|
||||
static final String UNSUCCESSFUL_INIT_URL = CODES_PREFIX + "#unsuccessfulInit";
|
||||
static final String UNSUCCESSFUL_INIT_MSG = "org.slf4j.LoggerFactory could not be successfully initialized. See also " + UNSUCCESSFUL_INIT_URL;
|
||||
|
||||
static final int UNINITIALIZED = 0;
|
||||
static final int ONGOING_INITIALIZATION = 1;
|
||||
static final int FAILED_INITIALIZATION = 2;
|
||||
static final int SUCCESSFUL_INITIALIZATION = 3;
|
||||
static final int NOP_FALLBACK_INITIALIZATION = 4;
|
||||
static final int UNINITIALIZED = 0;
|
||||
static final int ONGOING_INITIALIZATION = 1;
|
||||
static final int FAILED_INITIALIZATION = 2;
|
||||
static final int SUCCESSFUL_INITIALIZATION = 3;
|
||||
static final int NOP_FALLBACK_INITIALIZATION = 4;
|
||||
|
||||
static int INITIALIZATION_STATE = UNINITIALIZED;
|
||||
static SubstituteLoggerFactory TEMP_FACTORY = new SubstituteLoggerFactory();
|
||||
static NOPLoggerFactory NOP_FALLBACK_FACTORY = new NOPLoggerFactory();
|
||||
static int INITIALIZATION_STATE = UNINITIALIZED;
|
||||
static SubstituteLoggerFactory TEMP_FACTORY = new SubstituteLoggerFactory();
|
||||
static NOPLoggerFactory NOP_FALLBACK_FACTORY = new NOPLoggerFactory();
|
||||
|
||||
// Support for detecting mismatched logger names.
|
||||
static final String DETECT_LOGGER_NAME_MISMATCH_PROPERTY = "slf4j.detectLoggerNameMismatch";
|
||||
static boolean DETECT_LOGGER_NAME_MISMATCH = Boolean.getBoolean(DETECT_LOGGER_NAME_MISMATCH_PROPERTY);
|
||||
// Support for detecting mismatched logger names.
|
||||
static final String DETECT_LOGGER_NAME_MISMATCH_PROPERTY = "slf4j.detectLoggerNameMismatch";
|
||||
static boolean DETECT_LOGGER_NAME_MISMATCH = Boolean.getBoolean(DETECT_LOGGER_NAME_MISMATCH_PROPERTY);
|
||||
|
||||
/**
|
||||
* It is LoggerFactory's responsibility to track version changes and manage
|
||||
* the compatibility list.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* It is assumed that all versions in the 1.6 are mutually compatible.
|
||||
*/
|
||||
static private final String[] API_COMPATIBILITY_LIST = new String[] { "1.6", "1.7" };
|
||||
/**
|
||||
* It is LoggerFactory's responsibility to track version changes and manage
|
||||
* the compatibility list.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* It is assumed that all versions in the 1.6 are mutually compatible.
|
||||
*/
|
||||
static private final String[] API_COMPATIBILITY_LIST = new String[] { "1.6", "1.7" };
|
||||
|
||||
// private constructor prevents instantiation
|
||||
private LoggerFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Force LoggerFactory to consider itself uninitialized.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* This method is intended to be called by classes (in the same package) for
|
||||
* testing purposes. This method is internal. It can be modified, renamed or
|
||||
* removed at any time without notice.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* You are strongly discouraged from calling this method in production code.
|
||||
*/
|
||||
static void reset() {
|
||||
INITIALIZATION_STATE = UNINITIALIZED;
|
||||
TEMP_FACTORY = new SubstituteLoggerFactory();
|
||||
}
|
||||
|
||||
private final static void performInitialization() {
|
||||
bind();
|
||||
if (INITIALIZATION_STATE == SUCCESSFUL_INITIALIZATION) {
|
||||
versionSanityCheck();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean messageContainsOrgSlf4jImplStaticLoggerBinder(String msg) {
|
||||
if (msg == null)
|
||||
return false;
|
||||
if (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1)
|
||||
return true;
|
||||
if (msg.indexOf("org.slf4j.impl.StaticLoggerBinder") != -1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private final static void bind() {
|
||||
try {
|
||||
Set<URL> staticLoggerBinderPathSet = findPossibleStaticLoggerBinderPathSet();
|
||||
reportMultipleBindingAmbiguity(staticLoggerBinderPathSet);
|
||||
// the next line does the binding
|
||||
StaticLoggerBinder.getSingleton();
|
||||
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
|
||||
reportActualBinding(staticLoggerBinderPathSet);
|
||||
fixSubstitutedLoggers();
|
||||
} catch (NoClassDefFoundError ncde) {
|
||||
String msg = ncde.getMessage();
|
||||
if (messageContainsOrgSlf4jImplStaticLoggerBinder(msg)) {
|
||||
INITIALIZATION_STATE = NOP_FALLBACK_INITIALIZATION;
|
||||
Util.report("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
|
||||
Util.report("Defaulting to no-operation (NOP) logger implementation");
|
||||
Util.report("See " + NO_STATICLOGGERBINDER_URL + " for further details.");
|
||||
} else {
|
||||
failedBinding(ncde);
|
||||
throw ncde;
|
||||
}
|
||||
} catch (java.lang.NoSuchMethodError nsme) {
|
||||
String msg = nsme.getMessage();
|
||||
if (msg != null && msg.indexOf("org.slf4j.impl.StaticLoggerBinder.getSingleton()") != -1) {
|
||||
INITIALIZATION_STATE = FAILED_INITIALIZATION;
|
||||
Util.report("slf4j-api 1.6.x (or later) is incompatible with this binding.");
|
||||
Util.report("Your binding is version 1.5.5 or earlier.");
|
||||
Util.report("Upgrade your binding to version 1.6.x.");
|
||||
}
|
||||
throw nsme;
|
||||
} catch (Exception e) {
|
||||
failedBinding(e);
|
||||
throw new IllegalStateException("Unexpected initialization failure", e);
|
||||
}
|
||||
}
|
||||
|
||||
static void failedBinding(Throwable t) {
|
||||
INITIALIZATION_STATE = FAILED_INITIALIZATION;
|
||||
Util.report("Failed to instantiate SLF4J LoggerFactory", t);
|
||||
}
|
||||
|
||||
private final static void fixSubstitutedLoggers() {
|
||||
List<SubstituteLogger> loggers = TEMP_FACTORY.getLoggers();
|
||||
|
||||
if (loggers.isEmpty()) {
|
||||
return;
|
||||
// private constructor prevents instantiation
|
||||
private LoggerFactory() {
|
||||
}
|
||||
|
||||
Util.report("The following set of substitute loggers may have been accessed");
|
||||
Util.report("during the initialization phase. Logging calls during this");
|
||||
Util.report("phase were not honored. However, subsequent logging calls to these");
|
||||
Util.report("loggers will work as normally expected.");
|
||||
Util.report("See also " + SUBSTITUTE_LOGGER_URL);
|
||||
for (SubstituteLogger subLogger : loggers) {
|
||||
subLogger.setDelegate(getLogger(subLogger.getName()));
|
||||
Util.report(subLogger.getName());
|
||||
/**
|
||||
* Force LoggerFactory to consider itself uninitialized.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* This method is intended to be called by classes (in the same package) for
|
||||
* testing purposes. This method is internal. It can be modified, renamed or
|
||||
* removed at any time without notice.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* You are strongly discouraged from calling this method in production code.
|
||||
*/
|
||||
static void reset() {
|
||||
INITIALIZATION_STATE = UNINITIALIZED;
|
||||
TEMP_FACTORY = new SubstituteLoggerFactory();
|
||||
}
|
||||
|
||||
TEMP_FACTORY.clear();
|
||||
}
|
||||
|
||||
private final static void versionSanityCheck() {
|
||||
try {
|
||||
String requested = StaticLoggerBinder.REQUESTED_API_VERSION;
|
||||
|
||||
boolean match = false;
|
||||
for (int i = 0; i < API_COMPATIBILITY_LIST.length; i++) {
|
||||
if (requested.startsWith(API_COMPATIBILITY_LIST[i])) {
|
||||
match = true;
|
||||
private final static void performInitialization() {
|
||||
bind();
|
||||
if (INITIALIZATION_STATE == SUCCESSFUL_INITIALIZATION) {
|
||||
versionSanityCheck();
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
Util.report("The requested version " + requested + " by your slf4j binding is not compatible with "
|
||||
+ Arrays.asList(API_COMPATIBILITY_LIST).toString());
|
||||
Util.report("See " + VERSION_MISMATCH + " for further details.");
|
||||
}
|
||||
} catch (java.lang.NoSuchFieldError nsfe) {
|
||||
// given our large user base and SLF4J's commitment to backward
|
||||
// compatibility, we cannot cry here. Only for implementations
|
||||
// which willingly declare a REQUESTED_API_VERSION field do we
|
||||
// emit compatibility warnings.
|
||||
} catch (Throwable e) {
|
||||
// we should never reach here
|
||||
Util.report("Unexpected problem occured during version sanity check", e);
|
||||
}
|
||||
}
|
||||
|
||||
// We need to use the name of the StaticLoggerBinder class, but we can't reference
|
||||
// the class itself.
|
||||
private static String STATIC_LOGGER_BINDER_PATH = "org/slf4j/impl/StaticLoggerBinder.class";
|
||||
|
||||
private static Set<URL> findPossibleStaticLoggerBinderPathSet() {
|
||||
// use Set instead of list in order to deal with bug #138
|
||||
// LinkedHashSet appropriate here because it preserves insertion order during iteration
|
||||
Set<URL> staticLoggerBinderPathSet = new LinkedHashSet<URL>();
|
||||
try {
|
||||
ClassLoader loggerFactoryClassLoader = LoggerFactory.class.getClassLoader();
|
||||
Enumeration<URL> paths;
|
||||
if (loggerFactoryClassLoader == null) {
|
||||
paths = ClassLoader.getSystemResources(STATIC_LOGGER_BINDER_PATH);
|
||||
} else {
|
||||
paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH);
|
||||
}
|
||||
while (paths.hasMoreElements()) {
|
||||
URL path = (URL) paths.nextElement();
|
||||
staticLoggerBinderPathSet.add(path);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
Util.report("Error getting resources from path", ioe);
|
||||
private static boolean messageContainsOrgSlf4jImplStaticLoggerBinder(String msg) {
|
||||
if (msg == null)
|
||||
return false;
|
||||
if (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1)
|
||||
return true;
|
||||
if (msg.indexOf("org.slf4j.impl.StaticLoggerBinder") != -1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return staticLoggerBinderPathSet;
|
||||
}
|
||||
|
||||
private static boolean isAmbiguousStaticLoggerBinderPathSet(Set<URL> staticLoggerBinderPathSet) {
|
||||
return staticLoggerBinderPathSet.size() > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning message on the console if multiple bindings were found on the class path.
|
||||
* No reporting is done otherwise.
|
||||
*
|
||||
*/
|
||||
private static void reportMultipleBindingAmbiguity(Set<URL> staticLoggerBinderPathSet) {
|
||||
if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
|
||||
Util.report("Class path contains multiple SLF4J bindings.");
|
||||
Iterator<URL> iterator = staticLoggerBinderPathSet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
URL path = (URL) iterator.next();
|
||||
Util.report("Found binding in [" + path + "]");
|
||||
}
|
||||
Util.report("See " + MULTIPLE_BINDINGS_URL + " for an explanation.");
|
||||
private final static void bind() {
|
||||
try {
|
||||
Set<URL> staticLoggerBinderPathSet = findPossibleStaticLoggerBinderPathSet();
|
||||
reportMultipleBindingAmbiguity(staticLoggerBinderPathSet);
|
||||
// the next line does the binding
|
||||
StaticLoggerBinder.getSingleton();
|
||||
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
|
||||
reportActualBinding(staticLoggerBinderPathSet);
|
||||
fixSubstitutedLoggers();
|
||||
} catch (NoClassDefFoundError ncde) {
|
||||
String msg = ncde.getMessage();
|
||||
if (messageContainsOrgSlf4jImplStaticLoggerBinder(msg)) {
|
||||
INITIALIZATION_STATE = NOP_FALLBACK_INITIALIZATION;
|
||||
Util.report("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
|
||||
Util.report("Defaulting to no-operation (NOP) logger implementation");
|
||||
Util.report("See " + NO_STATICLOGGERBINDER_URL + " for further details.");
|
||||
} else {
|
||||
failedBinding(ncde);
|
||||
throw ncde;
|
||||
}
|
||||
} catch (java.lang.NoSuchMethodError nsme) {
|
||||
String msg = nsme.getMessage();
|
||||
if (msg != null && msg.indexOf("org.slf4j.impl.StaticLoggerBinder.getSingleton()") != -1) {
|
||||
INITIALIZATION_STATE = FAILED_INITIALIZATION;
|
||||
Util.report("slf4j-api 1.6.x (or later) is incompatible with this binding.");
|
||||
Util.report("Your binding is version 1.5.5 or earlier.");
|
||||
Util.report("Upgrade your binding to version 1.6.x.");
|
||||
}
|
||||
throw nsme;
|
||||
} catch (Exception e) {
|
||||
failedBinding(e);
|
||||
throw new IllegalStateException("Unexpected initialization failure", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void reportActualBinding(Set<URL> staticLoggerBinderPathSet) {
|
||||
if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
|
||||
Util.report("Actual binding is of type [" + StaticLoggerBinder.getSingleton().getLoggerFactoryClassStr() + "]");
|
||||
static void failedBinding(Throwable t) {
|
||||
INITIALIZATION_STATE = FAILED_INITIALIZATION;
|
||||
Util.report("Failed to instantiate SLF4J LoggerFactory", t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a logger named according to the name parameter using the statically
|
||||
* bound {@link ILoggerFactory} instance.
|
||||
*
|
||||
* @param name The name of the logger.
|
||||
* @return logger
|
||||
*/
|
||||
public static Logger getLogger(String name) {
|
||||
ILoggerFactory iLoggerFactory = getILoggerFactory();
|
||||
return iLoggerFactory.getLogger(name);
|
||||
}
|
||||
private final static void fixSubstitutedLoggers() {
|
||||
List<SubstituteLogger> loggers = TEMP_FACTORY.getLoggers();
|
||||
|
||||
/**
|
||||
* Return a logger named corresponding to the class passed as parameter, using
|
||||
* the statically bound {@link ILoggerFactory} instance.
|
||||
*
|
||||
* <p>In case the the <code>clazz</code> parameter differs from the name of
|
||||
* the caller as computed internally by SLF4J, a logger name mismatch warning will be
|
||||
* printed but only if the <code>slf4j.detectLoggerNameMismatch</code> system property is
|
||||
* set to true. By default, this property is not set and no warnings will be printed
|
||||
* even in case of a logger name mismatch.
|
||||
*
|
||||
* @param clazz the returned logger will be named after clazz
|
||||
* @return logger
|
||||
*
|
||||
*
|
||||
* @see <a href="http://www.slf4j.org/codes.html#loggerNameMismatch">Detected logger name mismatch</a>
|
||||
*/
|
||||
public static Logger getLogger(Class<?> clazz) {
|
||||
Logger logger = getLogger(clazz.getName());
|
||||
if (DETECT_LOGGER_NAME_MISMATCH) {
|
||||
Class<?> autoComputedCallingClass = Util.getCallingClass();
|
||||
if (nonMatchingClasses(clazz, autoComputedCallingClass)) {
|
||||
Util.report(String.format("Detected logger name mismatch. Given name: \"%s\"; computed name: \"%s\".",
|
||||
logger.getName(), autoComputedCallingClass.getName()));
|
||||
Util.report("See " + LOGGER_NAME_MISMATCH_URL + " for an explanation");
|
||||
}
|
||||
if (loggers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Util.report("The following set of substitute loggers may have been accessed");
|
||||
Util.report("during the initialization phase. Logging calls during this");
|
||||
Util.report("phase were not honored. However, subsequent logging calls to these");
|
||||
Util.report("loggers will work as normally expected.");
|
||||
Util.report("See also " + SUBSTITUTE_LOGGER_URL);
|
||||
for (SubstituteLogger subLogger : loggers) {
|
||||
subLogger.setDelegate(getLogger(subLogger.getName()));
|
||||
Util.report(subLogger.getName());
|
||||
}
|
||||
|
||||
TEMP_FACTORY.clear();
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
private static boolean nonMatchingClasses(Class<?> clazz, Class<?> autoComputedCallingClass) {
|
||||
return !autoComputedCallingClass.isAssignableFrom(clazz);
|
||||
}
|
||||
private final static void versionSanityCheck() {
|
||||
try {
|
||||
String requested = StaticLoggerBinder.REQUESTED_API_VERSION;
|
||||
|
||||
/**
|
||||
* Return the {@link ILoggerFactory} instance in use.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* ILoggerFactory instance is bound with this class at compile time.
|
||||
*
|
||||
* @return the ILoggerFactory instance in use
|
||||
*/
|
||||
public static ILoggerFactory getILoggerFactory() {
|
||||
if (INITIALIZATION_STATE == UNINITIALIZED) {
|
||||
INITIALIZATION_STATE = ONGOING_INITIALIZATION;
|
||||
performInitialization();
|
||||
boolean match = false;
|
||||
for (int i = 0; i < API_COMPATIBILITY_LIST.length; i++) {
|
||||
if (requested.startsWith(API_COMPATIBILITY_LIST[i])) {
|
||||
match = true;
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
Util.report("The requested version " + requested + " by your slf4j binding is not compatible with "
|
||||
+ Arrays.asList(API_COMPATIBILITY_LIST).toString());
|
||||
Util.report("See " + VERSION_MISMATCH + " for further details.");
|
||||
}
|
||||
} catch (java.lang.NoSuchFieldError nsfe) {
|
||||
// given our large user base and SLF4J's commitment to backward
|
||||
// compatibility, we cannot cry here. Only for implementations
|
||||
// which willingly declare a REQUESTED_API_VERSION field do we
|
||||
// emit compatibility warnings.
|
||||
} catch (Throwable e) {
|
||||
// we should never reach here
|
||||
Util.report("Unexpected problem occured during version sanity check", e);
|
||||
}
|
||||
}
|
||||
switch (INITIALIZATION_STATE) {
|
||||
case SUCCESSFUL_INITIALIZATION:
|
||||
return StaticLoggerBinder.getSingleton().getLoggerFactory();
|
||||
case NOP_FALLBACK_INITIALIZATION:
|
||||
return NOP_FALLBACK_FACTORY;
|
||||
case FAILED_INITIALIZATION:
|
||||
throw new IllegalStateException(UNSUCCESSFUL_INIT_MSG);
|
||||
case ONGOING_INITIALIZATION:
|
||||
// support re-entrant behavior.
|
||||
// See also http://bugzilla.slf4j.org/show_bug.cgi?id=106
|
||||
return TEMP_FACTORY;
|
||||
|
||||
// We need to use the name of the StaticLoggerBinder class, but we can't reference
|
||||
// the class itself.
|
||||
private static String STATIC_LOGGER_BINDER_PATH = "org/slf4j/impl/StaticLoggerBinder.class";
|
||||
|
||||
private static Set<URL> findPossibleStaticLoggerBinderPathSet() {
|
||||
// use Set instead of list in order to deal with bug #138
|
||||
// LinkedHashSet appropriate here because it preserves insertion order during iteration
|
||||
Set<URL> staticLoggerBinderPathSet = new LinkedHashSet<URL>();
|
||||
try {
|
||||
ClassLoader loggerFactoryClassLoader = LoggerFactory.class.getClassLoader();
|
||||
Enumeration<URL> paths;
|
||||
if (loggerFactoryClassLoader == null) {
|
||||
paths = ClassLoader.getSystemResources(STATIC_LOGGER_BINDER_PATH);
|
||||
} else {
|
||||
paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH);
|
||||
}
|
||||
while (paths.hasMoreElements()) {
|
||||
URL path = (URL) paths.nextElement();
|
||||
staticLoggerBinderPathSet.add(path);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
Util.report("Error getting resources from path", ioe);
|
||||
}
|
||||
return staticLoggerBinderPathSet;
|
||||
}
|
||||
|
||||
private static boolean isAmbiguousStaticLoggerBinderPathSet(Set<URL> staticLoggerBinderPathSet) {
|
||||
return staticLoggerBinderPathSet.size() > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning message on the console if multiple bindings were found on the class path.
|
||||
* No reporting is done otherwise.
|
||||
*
|
||||
*/
|
||||
private static void reportMultipleBindingAmbiguity(Set<URL> staticLoggerBinderPathSet) {
|
||||
if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
|
||||
Util.report("Class path contains multiple SLF4J bindings.");
|
||||
Iterator<URL> iterator = staticLoggerBinderPathSet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
URL path = (URL) iterator.next();
|
||||
Util.report("Found binding in [" + path + "]");
|
||||
}
|
||||
Util.report("See " + MULTIPLE_BINDINGS_URL + " for an explanation.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void reportActualBinding(Set<URL> staticLoggerBinderPathSet) {
|
||||
if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
|
||||
Util.report("Actual binding is of type [" + StaticLoggerBinder.getSingleton().getLoggerFactoryClassStr() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a logger named according to the name parameter using the statically
|
||||
* bound {@link ILoggerFactory} instance.
|
||||
*
|
||||
* @param name The name of the logger.
|
||||
* @return logger
|
||||
*/
|
||||
public static Logger getLogger(String name) {
|
||||
ILoggerFactory iLoggerFactory = getILoggerFactory();
|
||||
return iLoggerFactory.getLogger(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a logger named corresponding to the class passed as parameter, using
|
||||
* the statically bound {@link ILoggerFactory} instance.
|
||||
*
|
||||
* <p>In case the the <code>clazz</code> parameter differs from the name of
|
||||
* the caller as computed internally by SLF4J, a logger name mismatch warning will be
|
||||
* printed but only if the <code>slf4j.detectLoggerNameMismatch</code> system property is
|
||||
* set to true. By default, this property is not set and no warnings will be printed
|
||||
* even in case of a logger name mismatch.
|
||||
*
|
||||
* @param clazz the returned logger will be named after clazz
|
||||
* @return logger
|
||||
*
|
||||
*
|
||||
* @see <a href="http://www.slf4j.org/codes.html#loggerNameMismatch">Detected logger name mismatch</a>
|
||||
*/
|
||||
public static Logger getLogger(Class<?> clazz) {
|
||||
Logger logger = getLogger(clazz.getName());
|
||||
if (DETECT_LOGGER_NAME_MISMATCH) {
|
||||
Class<?> autoComputedCallingClass = Util.getCallingClass();
|
||||
if (nonMatchingClasses(clazz, autoComputedCallingClass)) {
|
||||
Util.report(String.format("Detected logger name mismatch. Given name: \"%s\"; computed name: \"%s\".", logger.getName(),
|
||||
autoComputedCallingClass.getName()));
|
||||
Util.report("See " + LOGGER_NAME_MISMATCH_URL + " for an explanation");
|
||||
}
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
private static boolean nonMatchingClasses(Class<?> clazz, Class<?> autoComputedCallingClass) {
|
||||
return !autoComputedCallingClass.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link ILoggerFactory} instance in use.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* ILoggerFactory instance is bound with this class at compile time.
|
||||
*
|
||||
* @return the ILoggerFactory instance in use
|
||||
*/
|
||||
public static ILoggerFactory getILoggerFactory() {
|
||||
if (INITIALIZATION_STATE == UNINITIALIZED) {
|
||||
INITIALIZATION_STATE = ONGOING_INITIALIZATION;
|
||||
performInitialization();
|
||||
}
|
||||
switch (INITIALIZATION_STATE) {
|
||||
case SUCCESSFUL_INITIALIZATION:
|
||||
return StaticLoggerBinder.getSingleton().getLoggerFactory();
|
||||
case NOP_FALLBACK_INITIALIZATION:
|
||||
return NOP_FALLBACK_FACTORY;
|
||||
case FAILED_INITIALIZATION:
|
||||
throw new IllegalStateException(UNSUCCESSFUL_INIT_MSG);
|
||||
case ONGOING_INITIALIZATION:
|
||||
// support re-entrant behavior.
|
||||
// See also http://bugzilla.slf4j.org/show_bug.cgi?id=106
|
||||
return TEMP_FACTORY;
|
||||
}
|
||||
throw new IllegalStateException("Unreachable code");
|
||||
}
|
||||
throw new IllegalStateException("Unreachable code");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,205 +63,197 @@ import org.slf4j.spi.MDCAdapter;
|
|||
*/
|
||||
public class MDC {
|
||||
|
||||
static final String NULL_MDCA_URL = "http://www.slf4j.org/codes.html#null_MDCA";
|
||||
static final String NO_STATIC_MDC_BINDER_URL = "http://www.slf4j.org/codes.html#no_static_mdc_binder";
|
||||
static MDCAdapter mdcAdapter;
|
||||
static final String NULL_MDCA_URL = "http://www.slf4j.org/codes.html#null_MDCA";
|
||||
static final String NO_STATIC_MDC_BINDER_URL = "http://www.slf4j.org/codes.html#no_static_mdc_binder";
|
||||
static MDCAdapter mdcAdapter;
|
||||
|
||||
/**
|
||||
* An adapter to remove the key when done.
|
||||
*/
|
||||
public static class MDCCloseable implements Closeable {
|
||||
private final String key;
|
||||
/**
|
||||
* An adapter to remove the key when done.
|
||||
*/
|
||||
public static class MDCCloseable implements Closeable {
|
||||
private final String key;
|
||||
|
||||
private MDCCloseable(String key) {
|
||||
this.key = key;
|
||||
private MDCCloseable(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
MDC.remove(this.key);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
MDC.remove(this.key);
|
||||
}
|
||||
}
|
||||
|
||||
private MDC() {
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
mdcAdapter = StaticMDCBinder.SINGLETON.getMDCA();
|
||||
} catch (NoClassDefFoundError ncde) {
|
||||
mdcAdapter = new NOPMDCAdapter();
|
||||
String msg = ncde.getMessage();
|
||||
if (msg != null && msg.indexOf("StaticMDCBinder") != -1) {
|
||||
Util.report("Failed to load class \"org.slf4j.impl.StaticMDCBinder\".");
|
||||
Util.report("Defaulting to no-operation MDCAdapter implementation.");
|
||||
Util.report("See " + NO_STATIC_MDC_BINDER_URL + " for further details.");
|
||||
} else {
|
||||
throw ncde;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// we should never get here
|
||||
Util.report("MDC binding unsuccessful.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a diagnostic context value (the <code>val</code> parameter) as identified with the
|
||||
* <code>key</code> parameter into the current thread's diagnostic context map. The
|
||||
* <code>key</code> parameter cannot be null. The <code>val</code> parameter
|
||||
* can be null only if the underlying implementation supports it.
|
||||
*
|
||||
* <p>
|
||||
* This method delegates all work to the MDC of the underlying logging system.
|
||||
*
|
||||
* @param key non-null key
|
||||
* @param val value to put in the map
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static void put(String key, String val)
|
||||
throws IllegalArgumentException {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
}
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also "
|
||||
+ NULL_MDCA_URL);
|
||||
}
|
||||
mdcAdapter.put(key, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a diagnostic context value (the <code>val</code> parameter) as identified with the
|
||||
* <code>key</code> parameter into the current thread's diagnostic context map. The
|
||||
* <code>key</code> parameter cannot be null. The <code>val</code> parameter
|
||||
* can be null only if the underlying implementation supports it.
|
||||
*
|
||||
* <p>
|
||||
* This method delegates all work to the MDC of the underlying logging system.
|
||||
* <p>
|
||||
* This method return a <code>Closeable</code> object who can remove <code>key</code> when
|
||||
* <code>close</code> is called.
|
||||
*
|
||||
* <p>
|
||||
* Useful with Java 7 for example :
|
||||
* <code>
|
||||
* try(MDC.MDCCloseable closeable = MDC.putCloseable(key, value)) {
|
||||
* ....
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @param key non-null key
|
||||
* @param val value to put in the map
|
||||
* @return a <code>Closeable</code> who can remove <code>key</code> when <code>close</code>
|
||||
* is called.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static MDCCloseable putCloseable(String key, String val)
|
||||
throws IllegalArgumentException {
|
||||
put(key, val);
|
||||
return new MDCCloseable(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the diagnostic context identified by the <code>key</code> parameter. The
|
||||
* <code>key</code> parameter cannot be null.
|
||||
*
|
||||
* <p>
|
||||
* This method delegates all work to the MDC of the underlying logging system.
|
||||
*
|
||||
* @param key
|
||||
* @return the string value identified by the <code>key</code> parameter.
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static String get(String key) throws IllegalArgumentException {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
private MDC() {
|
||||
}
|
||||
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also "
|
||||
+ NULL_MDCA_URL);
|
||||
}
|
||||
return mdcAdapter.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the diagnostic context identified by the <code>key</code> parameter using
|
||||
* the underlying system's MDC implementation. The <code>key</code> parameter
|
||||
* cannot be null. This method does nothing if there is no previous value
|
||||
* associated with <code>key</code>.
|
||||
*
|
||||
* @param key
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static void remove(String key) throws IllegalArgumentException {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
static {
|
||||
try {
|
||||
mdcAdapter = StaticMDCBinder.SINGLETON.getMDCA();
|
||||
} catch (NoClassDefFoundError ncde) {
|
||||
mdcAdapter = new NOPMDCAdapter();
|
||||
String msg = ncde.getMessage();
|
||||
if (msg != null && msg.indexOf("StaticMDCBinder") != -1) {
|
||||
Util.report("Failed to load class \"org.slf4j.impl.StaticMDCBinder\".");
|
||||
Util.report("Defaulting to no-operation MDCAdapter implementation.");
|
||||
Util.report("See " + NO_STATIC_MDC_BINDER_URL + " for further details.");
|
||||
} else {
|
||||
throw ncde;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// we should never get here
|
||||
Util.report("MDC binding unsuccessful.", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also "
|
||||
+ NULL_MDCA_URL);
|
||||
/**
|
||||
* Put a diagnostic context value (the <code>val</code> parameter) as identified with the
|
||||
* <code>key</code> parameter into the current thread's diagnostic context map. The
|
||||
* <code>key</code> parameter cannot be null. The <code>val</code> parameter
|
||||
* can be null only if the underlying implementation supports it.
|
||||
*
|
||||
* <p>
|
||||
* This method delegates all work to the MDC of the underlying logging system.
|
||||
*
|
||||
* @param key non-null key
|
||||
* @param val value to put in the map
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static void put(String key, String val) throws IllegalArgumentException {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
}
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
|
||||
}
|
||||
mdcAdapter.put(key, val);
|
||||
}
|
||||
mdcAdapter.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all entries in the MDC of the underlying implementation.
|
||||
*/
|
||||
public static void clear() {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also "
|
||||
+ NULL_MDCA_URL);
|
||||
/**
|
||||
* Put a diagnostic context value (the <code>val</code> parameter) as identified with the
|
||||
* <code>key</code> parameter into the current thread's diagnostic context map. The
|
||||
* <code>key</code> parameter cannot be null. The <code>val</code> parameter
|
||||
* can be null only if the underlying implementation supports it.
|
||||
*
|
||||
* <p>
|
||||
* This method delegates all work to the MDC of the underlying logging system.
|
||||
* <p>
|
||||
* This method return a <code>Closeable</code> object who can remove <code>key</code> when
|
||||
* <code>close</code> is called.
|
||||
*
|
||||
* <p>
|
||||
* Useful with Java 7 for example :
|
||||
* <code>
|
||||
* try(MDC.MDCCloseable closeable = MDC.putCloseable(key, value)) {
|
||||
* ....
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @param key non-null key
|
||||
* @param val value to put in the map
|
||||
* @return a <code>Closeable</code> who can remove <code>key</code> when <code>close</code>
|
||||
* is called.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static MDCCloseable putCloseable(String key, String val) throws IllegalArgumentException {
|
||||
put(key, val);
|
||||
return new MDCCloseable(key);
|
||||
}
|
||||
mdcAdapter.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of the current thread's context map, with keys and values of
|
||||
* type String. Returned value may be null.
|
||||
*
|
||||
* @return A copy of the current thread's context map. May be null.
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public static Map<String, String> getCopyOfContextMap() {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also "
|
||||
+ NULL_MDCA_URL);
|
||||
/**
|
||||
* Get the diagnostic context identified by the <code>key</code> parameter. The
|
||||
* <code>key</code> parameter cannot be null.
|
||||
*
|
||||
* <p>
|
||||
* This method delegates all work to the MDC of the underlying logging system.
|
||||
*
|
||||
* @param key
|
||||
* @return the string value identified by the <code>key</code> parameter.
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static String get(String key) throws IllegalArgumentException {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
}
|
||||
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
|
||||
}
|
||||
return mdcAdapter.get(key);
|
||||
}
|
||||
return mdcAdapter.getCopyOfContextMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current thread's context map by first clearing any existing map and
|
||||
* then copying the map passed as parameter. The context map passed as
|
||||
* parameter must only contain keys and values of type String.
|
||||
*
|
||||
* @param contextMap
|
||||
* must contain only keys and values of type String
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public static void setContextMap(Map<String, String> contextMap) {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also "
|
||||
+ NULL_MDCA_URL);
|
||||
/**
|
||||
* Remove the diagnostic context identified by the <code>key</code> parameter using
|
||||
* the underlying system's MDC implementation. The <code>key</code> parameter
|
||||
* cannot be null. This method does nothing if there is no previous value
|
||||
* associated with <code>key</code>.
|
||||
*
|
||||
* @param key
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public static void remove(String key) throws IllegalArgumentException {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
}
|
||||
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
|
||||
}
|
||||
mdcAdapter.remove(key);
|
||||
}
|
||||
mdcAdapter.setContextMap(contextMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MDCAdapter instance currently in use.
|
||||
*
|
||||
* @return the MDcAdapter instance currently in use.
|
||||
* @since 1.4.2
|
||||
*/
|
||||
public static MDCAdapter getMDCAdapter() {
|
||||
return mdcAdapter;
|
||||
}
|
||||
/**
|
||||
* Clear all entries in the MDC of the underlying implementation.
|
||||
*/
|
||||
public static void clear() {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
|
||||
}
|
||||
mdcAdapter.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of the current thread's context map, with keys and values of
|
||||
* type String. Returned value may be null.
|
||||
*
|
||||
* @return A copy of the current thread's context map. May be null.
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public static Map<String, String> getCopyOfContextMap() {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
|
||||
}
|
||||
return mdcAdapter.getCopyOfContextMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current thread's context map by first clearing any existing map and
|
||||
* then copying the map passed as parameter. The context map passed as
|
||||
* parameter must only contain keys and values of type String.
|
||||
*
|
||||
* @param contextMap
|
||||
* must contain only keys and values of type String
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public static void setContextMap(Map<String, String> contextMap) {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException("MDCAdapter cannot be null. See also " + NULL_MDCA_URL);
|
||||
}
|
||||
mdcAdapter.setContextMap(contextMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MDCAdapter instance currently in use.
|
||||
*
|
||||
* @return the MDcAdapter instance currently in use.
|
||||
* @since 1.4.2
|
||||
*/
|
||||
public static MDCAdapter getMDCAdapter() {
|
||||
return mdcAdapter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,102 +41,102 @@ import java.util.Iterator;
|
|||
*/
|
||||
public interface Marker extends Serializable {
|
||||
|
||||
/**
|
||||
* This constant represents any marker, including a null marker.
|
||||
*/
|
||||
public final String ANY_MARKER = "*";
|
||||
/**
|
||||
* This constant represents any marker, including a null marker.
|
||||
*/
|
||||
public final String ANY_MARKER = "*";
|
||||
|
||||
/**
|
||||
* This constant represents any non-null marker.
|
||||
*/
|
||||
public final String ANY_NON_NULL_MARKER = "+";
|
||||
/**
|
||||
* This constant represents any non-null marker.
|
||||
*/
|
||||
public final String ANY_NON_NULL_MARKER = "+";
|
||||
|
||||
/**
|
||||
* Get the name of this Marker.
|
||||
*
|
||||
* @return name of marker
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* Get the name of this Marker.
|
||||
*
|
||||
* @return name of marker
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* Add a reference to another Marker.
|
||||
*
|
||||
* @param reference
|
||||
* a reference to another marker
|
||||
* @throws IllegalArgumentException
|
||||
* if 'reference' is null
|
||||
*/
|
||||
public void add(Marker reference);
|
||||
/**
|
||||
* Add a reference to another Marker.
|
||||
*
|
||||
* @param reference
|
||||
* a reference to another marker
|
||||
* @throws IllegalArgumentException
|
||||
* if 'reference' is null
|
||||
*/
|
||||
public void add(Marker reference);
|
||||
|
||||
/**
|
||||
* Remove a marker reference.
|
||||
*
|
||||
* @param reference
|
||||
* the marker reference to remove
|
||||
* @return true if reference could be found and removed, false otherwise.
|
||||
*/
|
||||
public boolean remove(Marker reference);
|
||||
/**
|
||||
* Remove a marker reference.
|
||||
*
|
||||
* @param reference
|
||||
* the marker reference to remove
|
||||
* @return true if reference could be found and removed, false otherwise.
|
||||
*/
|
||||
public boolean remove(Marker reference);
|
||||
|
||||
/**
|
||||
* @deprecated Replaced by {@link #hasReferences()}.
|
||||
*/
|
||||
public boolean hasChildren();
|
||||
/**
|
||||
* @deprecated Replaced by {@link #hasReferences()}.
|
||||
*/
|
||||
public boolean hasChildren();
|
||||
|
||||
/**
|
||||
* Does this marker have any references?
|
||||
*
|
||||
* @return true if this marker has one or more references, false otherwise.
|
||||
*/
|
||||
public boolean hasReferences();
|
||||
/**
|
||||
* Does this marker have any references?
|
||||
*
|
||||
* @return true if this marker has one or more references, false otherwise.
|
||||
*/
|
||||
public boolean hasReferences();
|
||||
|
||||
/**
|
||||
* Returns an Iterator which can be used to iterate over the references of this
|
||||
* marker. An empty iterator is returned when this marker has no references.
|
||||
*
|
||||
* @return Iterator over the references of this marker
|
||||
*/
|
||||
public Iterator<Marker> iterator();
|
||||
/**
|
||||
* Returns an Iterator which can be used to iterate over the references of this
|
||||
* marker. An empty iterator is returned when this marker has no references.
|
||||
*
|
||||
* @return Iterator over the references of this marker
|
||||
*/
|
||||
public Iterator<Marker> iterator();
|
||||
|
||||
/**
|
||||
* Does this marker contain a reference to the 'other' marker? Marker A is defined
|
||||
* to contain marker B, if A == B or if B is referenced by A, or if B is referenced
|
||||
* by any one of A's references (recursively).
|
||||
*
|
||||
* @param other
|
||||
* The marker to test for inclusion.
|
||||
* @throws IllegalArgumentException
|
||||
* if 'other' is null
|
||||
* @return Whether this marker contains the other marker.
|
||||
*/
|
||||
public boolean contains(Marker other);
|
||||
/**
|
||||
* Does this marker contain a reference to the 'other' marker? Marker A is defined
|
||||
* to contain marker B, if A == B or if B is referenced by A, or if B is referenced
|
||||
* by any one of A's references (recursively).
|
||||
*
|
||||
* @param other
|
||||
* The marker to test for inclusion.
|
||||
* @throws IllegalArgumentException
|
||||
* if 'other' is null
|
||||
* @return Whether this marker contains the other marker.
|
||||
*/
|
||||
public boolean contains(Marker other);
|
||||
|
||||
/**
|
||||
* Does this marker contain the marker named 'name'?
|
||||
*
|
||||
* If 'name' is null the returned value is always false.
|
||||
*
|
||||
* @param name The marker name to test for inclusion.
|
||||
* @return Whether this marker contains the other marker.
|
||||
*/
|
||||
public boolean contains(String name);
|
||||
/**
|
||||
* Does this marker contain the marker named 'name'?
|
||||
*
|
||||
* If 'name' is null the returned value is always false.
|
||||
*
|
||||
* @param name The marker name to test for inclusion.
|
||||
* @return Whether this marker contains the other marker.
|
||||
*/
|
||||
public boolean contains(String name);
|
||||
|
||||
/**
|
||||
* Markers are considered equal if they have the same name.
|
||||
*
|
||||
* @param o
|
||||
* @return true, if this.name equals o.name
|
||||
*
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public boolean equals(Object o);
|
||||
/**
|
||||
* Markers are considered equal if they have the same name.
|
||||
*
|
||||
* @param o
|
||||
* @return true, if this.name equals o.name
|
||||
*
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public boolean equals(Object o);
|
||||
|
||||
/**
|
||||
* Compute the hash code based on the name of this marker.
|
||||
* Note that markers are considered equal if they have the same name.
|
||||
*
|
||||
* @return the computed hashCode
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public int hashCode();
|
||||
/**
|
||||
* Compute the hash code based on the name of this marker.
|
||||
* Note that markers are considered equal if they have the same name.
|
||||
*
|
||||
* @return the computed hashCode
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public int hashCode();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,55 +42,55 @@ import org.slf4j.impl.StaticMarkerBinder;
|
|||
* @author Ceki Gülcü
|
||||
*/
|
||||
public class MarkerFactory {
|
||||
static IMarkerFactory markerFactory;
|
||||
static IMarkerFactory markerFactory;
|
||||
|
||||
private MarkerFactory() {
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
markerFactory = StaticMarkerBinder.SINGLETON.getMarkerFactory();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
|
||||
} catch (Exception e) {
|
||||
// we should never get here
|
||||
Util.report("Unexpected failure while binding MarkerFactory", e);
|
||||
private MarkerFactory() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Marker instance as specified by the name parameter using the
|
||||
* previously bound {@link IMarkerFactory}instance.
|
||||
*
|
||||
* @param name
|
||||
* The name of the {@link Marker} object to return.
|
||||
* @return marker
|
||||
*/
|
||||
public static Marker getMarker(String name) {
|
||||
return markerFactory.getMarker(name);
|
||||
}
|
||||
static {
|
||||
try {
|
||||
markerFactory = StaticMarkerBinder.SINGLETON.getMarkerFactory();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
|
||||
/**
|
||||
* Create a marker which is detached (even at birth) from the MarkerFactory.
|
||||
*
|
||||
* @param name the name of the marker
|
||||
* @return a dangling marker
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public static Marker getDetachedMarker(String name) {
|
||||
return markerFactory.getDetachedMarker(name);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// we should never get here
|
||||
Util.report("Unexpected failure while binding MarkerFactory", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link IMarkerFactory}instance in use.
|
||||
*
|
||||
* <p>The IMarkerFactory instance is usually bound with this class at
|
||||
* compile time.
|
||||
*
|
||||
* @return the IMarkerFactory instance in use
|
||||
*/
|
||||
public static IMarkerFactory getIMarkerFactory() {
|
||||
return markerFactory;
|
||||
}
|
||||
/**
|
||||
* Return a Marker instance as specified by the name parameter using the
|
||||
* previously bound {@link IMarkerFactory}instance.
|
||||
*
|
||||
* @param name
|
||||
* The name of the {@link Marker} object to return.
|
||||
* @return marker
|
||||
*/
|
||||
public static Marker getMarker(String name) {
|
||||
return markerFactory.getMarker(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a marker which is detached (even at birth) from the MarkerFactory.
|
||||
*
|
||||
* @param name the name of the marker
|
||||
* @return a dangling marker
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public static Marker getDetachedMarker(String name) {
|
||||
return markerFactory.getDetachedMarker(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link IMarkerFactory}instance in use.
|
||||
*
|
||||
* <p>The IMarkerFactory instance is usually bound with this class at
|
||||
* compile time.
|
||||
*
|
||||
* @return the IMarkerFactory instance in use
|
||||
*/
|
||||
public static IMarkerFactory getIMarkerFactory() {
|
||||
return markerFactory;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,120 +43,119 @@ import java.util.Map;
|
|||
*/
|
||||
public class BasicMDCAdapter implements MDCAdapter {
|
||||
|
||||
private InheritableThreadLocal<Map<String, String>> inheritableThreadLocal
|
||||
= new InheritableThreadLocal<Map<String, String>>();
|
||||
private InheritableThreadLocal<Map<String, String>> inheritableThreadLocal = new InheritableThreadLocal<Map<String, String>>();
|
||||
|
||||
static boolean isJDK14() {
|
||||
try {
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
return javaVersion.startsWith("1.4");
|
||||
} catch(SecurityException se) {
|
||||
// punt and assume JDK 1.5 or later
|
||||
return false;
|
||||
static boolean isJDK14() {
|
||||
try {
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
return javaVersion.startsWith("1.4");
|
||||
} catch (SecurityException se) {
|
||||
// punt and assume JDK 1.5 or later
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean IS_JDK14 = isJDK14();
|
||||
static boolean IS_JDK14 = isJDK14();
|
||||
|
||||
|
||||
/**
|
||||
* Put a context value (the <code>val</code> parameter) as identified with
|
||||
* the <code>key</code> parameter into the current thread's context map.
|
||||
* Note that contrary to log4j, the <code>val</code> parameter can be null.
|
||||
*
|
||||
* <p>
|
||||
* If the current thread does not have a context map it is created as a side
|
||||
* effect of this call.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public void put(String key, String val) {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key cannot be null");
|
||||
/**
|
||||
* Put a context value (the <code>val</code> parameter) as identified with
|
||||
* the <code>key</code> parameter into the current thread's context map.
|
||||
* Note that contrary to log4j, the <code>val</code> parameter can be null.
|
||||
*
|
||||
* <p>
|
||||
* If the current thread does not have a context map it is created as a side
|
||||
* effect of this call.
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* in case the "key" parameter is null
|
||||
*/
|
||||
public void put(String key, String val) {
|
||||
if (key == null) {
|
||||
throw new IllegalArgumentException("key cannot be null");
|
||||
}
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map == null) {
|
||||
map = Collections.<String, String> synchronizedMap(new HashMap<String, String>());
|
||||
inheritableThreadLocal.set(map);
|
||||
}
|
||||
map.put(key, val);
|
||||
}
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map == null) {
|
||||
map = Collections.<String, String>synchronizedMap(new HashMap<String, String>());
|
||||
inheritableThreadLocal.set(map);
|
||||
}
|
||||
map.put(key, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context identified by the <code>key</code> parameter.
|
||||
*/
|
||||
public String get(String key) {
|
||||
Map<String, String> Map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if ((Map != null) && (key != null)) {
|
||||
return (String) Map.get(key);
|
||||
} else {
|
||||
return null;
|
||||
/**
|
||||
* Get the context identified by the <code>key</code> parameter.
|
||||
*/
|
||||
public String get(String key) {
|
||||
Map<String, String> Map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if ((Map != null) && (key != null)) {
|
||||
return (String) Map.get(key);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the the context identified by the <code>key</code> parameter.
|
||||
*/
|
||||
public void remove(String key) {
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map != null) {
|
||||
map.remove(key);
|
||||
/**
|
||||
* Remove the the context identified by the <code>key</code> parameter.
|
||||
*/
|
||||
public void remove(String key) {
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map != null) {
|
||||
map.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all entries in the MDC.
|
||||
*/
|
||||
public void clear() {
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map != null) {
|
||||
map.clear();
|
||||
// the InheritableThreadLocal.remove method was introduced in JDK 1.5
|
||||
// Thus, invoking clear() on previous JDK 1.4 will fail
|
||||
if(isJDK14()) {
|
||||
inheritableThreadLocal.set(null);
|
||||
} else {
|
||||
inheritableThreadLocal.remove();
|
||||
}
|
||||
/**
|
||||
* Clear all entries in the MDC.
|
||||
*/
|
||||
public void clear() {
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map != null) {
|
||||
map.clear();
|
||||
// the InheritableThreadLocal.remove method was introduced in JDK 1.5
|
||||
// Thus, invoking clear() on previous JDK 1.4 will fail
|
||||
if (isJDK14()) {
|
||||
inheritableThreadLocal.set(null);
|
||||
} else {
|
||||
inheritableThreadLocal.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keys in the MDC as a {@link Set} of {@link String}s The
|
||||
* returned value can be null.
|
||||
*
|
||||
* @return the keys in the MDC
|
||||
*/
|
||||
public Set<String> getKeys() {
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map != null) {
|
||||
return map.keySet();
|
||||
} else {
|
||||
return null;
|
||||
/**
|
||||
* Returns the keys in the MDC as a {@link Set} of {@link String}s The
|
||||
* returned value can be null.
|
||||
*
|
||||
* @return the keys in the MDC
|
||||
*/
|
||||
public Set<String> getKeys() {
|
||||
Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (map != null) {
|
||||
return map.keySet();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return a copy of the current thread's context map.
|
||||
* Returned value may be null.
|
||||
*
|
||||
*/
|
||||
public Map<String, String> getCopyOfContextMap() {
|
||||
Map<String, String> oldMap = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (oldMap != null) {
|
||||
Map<String, String> newMap = Collections.<String, String>synchronizedMap(new HashMap<String, String>());
|
||||
synchronized (oldMap) {
|
||||
newMap.putAll(oldMap);
|
||||
}
|
||||
return newMap;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setContextMap(Map<String, String> contextMap) {
|
||||
Map<String, String> map = Collections.<String, String>synchronizedMap(new HashMap<String, String>(contextMap));
|
||||
inheritableThreadLocal.set(map);
|
||||
}
|
||||
/**
|
||||
* Return a copy of the current thread's context map.
|
||||
* Returned value may be null.
|
||||
*
|
||||
*/
|
||||
public Map<String, String> getCopyOfContextMap() {
|
||||
Map<String, String> oldMap = (Map<String, String>) inheritableThreadLocal.get();
|
||||
if (oldMap != null) {
|
||||
Map<String, String> newMap = Collections.<String, String> synchronizedMap(new HashMap<String, String>());
|
||||
synchronized (oldMap) {
|
||||
newMap.putAll(oldMap);
|
||||
}
|
||||
return newMap;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setContextMap(Map<String, String> contextMap) {
|
||||
Map<String, String> map = Collections.<String, String> synchronizedMap(new HashMap<String, String>(contextMap));
|
||||
inheritableThreadLocal.set(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,159 +39,157 @@ import org.slf4j.Marker;
|
|||
*/
|
||||
public class BasicMarker implements Marker {
|
||||
|
||||
private static final long serialVersionUID = 1803952589649545191L;
|
||||
private static final long serialVersionUID = 1803952589649545191L;
|
||||
|
||||
private final String name;
|
||||
private List<Marker> referenceList;
|
||||
private final String name;
|
||||
private List<Marker> referenceList;
|
||||
|
||||
BasicMarker(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("A marker name cannot be null");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public synchronized void add(Marker reference) {
|
||||
if (reference == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"A null value cannot be added to a Marker as reference.");
|
||||
}
|
||||
|
||||
// no point in adding the reference multiple times
|
||||
if (this.contains(reference)) {
|
||||
return;
|
||||
|
||||
} else if (reference.contains(this)) { // avoid recursion
|
||||
// a potential reference should not its future "parent" as a reference
|
||||
return;
|
||||
} else {
|
||||
// let's add the reference
|
||||
if (referenceList == null) {
|
||||
referenceList = new Vector<Marker>();
|
||||
}
|
||||
referenceList.add(reference);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized boolean hasReferences() {
|
||||
return ((referenceList != null) && (referenceList.size() > 0));
|
||||
}
|
||||
|
||||
public boolean hasChildren() {
|
||||
return hasReferences();
|
||||
}
|
||||
|
||||
public synchronized Iterator<Marker> iterator() {
|
||||
if (referenceList != null) {
|
||||
return referenceList.iterator();
|
||||
} else {
|
||||
List<Marker> emptyList = Collections.emptyList();
|
||||
return emptyList.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean remove(Marker referenceToRemove) {
|
||||
if (referenceList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int size = referenceList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Marker m = (Marker) referenceList.get(i);
|
||||
if (referenceToRemove.equals(m)) {
|
||||
referenceList.remove(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(Marker other) {
|
||||
if (other == null) {
|
||||
throw new IllegalArgumentException("Other cannot be null");
|
||||
}
|
||||
|
||||
if (this.equals(other)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasReferences()) {
|
||||
for (int i = 0; i < referenceList.size(); i++) {
|
||||
Marker ref = (Marker) referenceList.get(i);
|
||||
if (ref.contains(other)) {
|
||||
return true;
|
||||
BasicMarker(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("A marker name cannot be null");
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is mainly used with Expression Evaluators.
|
||||
*/
|
||||
public boolean contains(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Other cannot be null");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
if (this.name.equals(name)) {
|
||||
return true;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
if (hasReferences()) {
|
||||
for (int i = 0; i < referenceList.size(); i++) {
|
||||
Marker ref = (Marker) referenceList.get(i);
|
||||
if (ref.contains(name)) {
|
||||
return true;
|
||||
public synchronized void add(Marker reference) {
|
||||
if (reference == null) {
|
||||
throw new IllegalArgumentException("A null value cannot be added to a Marker as reference.");
|
||||
}
|
||||
}
|
||||
|
||||
// no point in adding the reference multiple times
|
||||
if (this.contains(reference)) {
|
||||
return;
|
||||
|
||||
} else if (reference.contains(this)) { // avoid recursion
|
||||
// a potential reference should not its future "parent" as a reference
|
||||
return;
|
||||
} else {
|
||||
// let's add the reference
|
||||
if (referenceList == null) {
|
||||
referenceList = new Vector<Marker>();
|
||||
}
|
||||
referenceList.add(reference);
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String OPEN = "[ ";
|
||||
private static String CLOSE = " ]";
|
||||
private static String SEP = ", ";
|
||||
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof Marker))
|
||||
return false;
|
||||
|
||||
final Marker other = (Marker) obj;
|
||||
return name.equals(other.getName());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (!this.hasReferences()) {
|
||||
return this.getName();
|
||||
public synchronized boolean hasReferences() {
|
||||
return ((referenceList != null) && (referenceList.size() > 0));
|
||||
}
|
||||
Iterator<Marker> it = this.iterator();
|
||||
Marker reference;
|
||||
StringBuilder sb = new StringBuilder(this.getName());
|
||||
sb.append(' ').append(OPEN);
|
||||
while (it.hasNext()) {
|
||||
reference = (Marker) it.next();
|
||||
sb.append(reference.getName());
|
||||
if (it.hasNext()) {
|
||||
sb.append(SEP);
|
||||
}
|
||||
}
|
||||
sb.append(CLOSE);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
public boolean hasChildren() {
|
||||
return hasReferences();
|
||||
}
|
||||
|
||||
public synchronized Iterator<Marker> iterator() {
|
||||
if (referenceList != null) {
|
||||
return referenceList.iterator();
|
||||
} else {
|
||||
List<Marker> emptyList = Collections.emptyList();
|
||||
return emptyList.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean remove(Marker referenceToRemove) {
|
||||
if (referenceList == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int size = referenceList.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Marker m = (Marker) referenceList.get(i);
|
||||
if (referenceToRemove.equals(m)) {
|
||||
referenceList.remove(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(Marker other) {
|
||||
if (other == null) {
|
||||
throw new IllegalArgumentException("Other cannot be null");
|
||||
}
|
||||
|
||||
if (this.equals(other)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasReferences()) {
|
||||
for (int i = 0; i < referenceList.size(); i++) {
|
||||
Marker ref = (Marker) referenceList.get(i);
|
||||
if (ref.contains(other)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is mainly used with Expression Evaluators.
|
||||
*/
|
||||
public boolean contains(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Other cannot be null");
|
||||
}
|
||||
|
||||
if (this.name.equals(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasReferences()) {
|
||||
for (int i = 0; i < referenceList.size(); i++) {
|
||||
Marker ref = (Marker) referenceList.get(i);
|
||||
if (ref.contains(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String OPEN = "[ ";
|
||||
private static String CLOSE = " ]";
|
||||
private static String SEP = ", ";
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof Marker))
|
||||
return false;
|
||||
|
||||
final Marker other = (Marker) obj;
|
||||
return name.equals(other.getName());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (!this.hasReferences()) {
|
||||
return this.getName();
|
||||
}
|
||||
Iterator<Marker> it = this.iterator();
|
||||
Marker reference;
|
||||
StringBuilder sb = new StringBuilder(this.getName());
|
||||
sb.append(' ').append(OPEN);
|
||||
while (it.hasNext()) {
|
||||
reference = (Marker) it.next();
|
||||
sb.append(reference.getName());
|
||||
if (it.hasNext()) {
|
||||
sb.append(SEP);
|
||||
}
|
||||
}
|
||||
sb.append(CLOSE);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,62 +41,59 @@ import org.slf4j.Marker;
|
|||
*/
|
||||
public class BasicMarkerFactory implements IMarkerFactory {
|
||||
|
||||
private final ConcurrentMap<String, Marker> markerMap = new ConcurrentHashMap<String, Marker>();
|
||||
private final ConcurrentMap<String, Marker> markerMap = new ConcurrentHashMap<String, Marker>();
|
||||
|
||||
/**
|
||||
* Regular users should <em>not</em> create
|
||||
* <code>BasicMarkerFactory</code> instances. <code>Marker</code>
|
||||
* instances can be obtained using the static {@link
|
||||
* org.slf4j.MarkerFactory#getMarker} method.
|
||||
*/
|
||||
public BasicMarkerFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Manufacture a {@link BasicMarker} instance by name. If the instance has been
|
||||
* created earlier, return the previously created instance.
|
||||
*
|
||||
* @param name the name of the marker to be created
|
||||
* @return a Marker instance
|
||||
*/
|
||||
public Marker getMarker(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Marker name cannot be null");
|
||||
/**
|
||||
* Regular users should <em>not</em> create
|
||||
* <code>BasicMarkerFactory</code> instances. <code>Marker</code>
|
||||
* instances can be obtained using the static {@link
|
||||
* org.slf4j.MarkerFactory#getMarker} method.
|
||||
*/
|
||||
public BasicMarkerFactory() {
|
||||
}
|
||||
|
||||
Marker marker = markerMap.get(name);
|
||||
if (marker == null) {
|
||||
marker = new BasicMarker(name);
|
||||
Marker oldMarker = markerMap.putIfAbsent(name, marker);
|
||||
if (oldMarker != null) {
|
||||
marker = oldMarker;
|
||||
}
|
||||
/**
|
||||
* Manufacture a {@link BasicMarker} instance by name. If the instance has been
|
||||
* created earlier, return the previously created instance.
|
||||
*
|
||||
* @param name the name of the marker to be created
|
||||
* @return a Marker instance
|
||||
*/
|
||||
public Marker getMarker(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Marker name cannot be null");
|
||||
}
|
||||
|
||||
Marker marker = markerMap.get(name);
|
||||
if (marker == null) {
|
||||
marker = new BasicMarker(name);
|
||||
Marker oldMarker = markerMap.putIfAbsent(name, marker);
|
||||
if (oldMarker != null) {
|
||||
marker = oldMarker;
|
||||
}
|
||||
}
|
||||
return marker;
|
||||
}
|
||||
return marker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the name marked already exist?
|
||||
*/
|
||||
public boolean exists(String name) {
|
||||
if (name == null) {
|
||||
return false;
|
||||
/**
|
||||
* Does the name marked already exist?
|
||||
*/
|
||||
public boolean exists(String name) {
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
return markerMap.containsKey(name);
|
||||
}
|
||||
return markerMap.containsKey(name);
|
||||
}
|
||||
|
||||
public boolean detachMarker(String name) {
|
||||
if(name == null) {
|
||||
return false;
|
||||
public boolean detachMarker(String name) {
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
return (markerMap.remove(name) != null);
|
||||
}
|
||||
return (markerMap.remove(name) != null);
|
||||
}
|
||||
|
||||
|
||||
public Marker getDetachedMarker(String name) {
|
||||
return new BasicMarker(name);
|
||||
}
|
||||
|
||||
|
||||
public Marker getDetachedMarker(String name) {
|
||||
return new BasicMarker(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,47 +31,46 @@ package org.slf4j.helpers;
|
|||
*/
|
||||
public class FormattingTuple {
|
||||
|
||||
static public FormattingTuple NULL = new FormattingTuple(null);
|
||||
|
||||
static public FormattingTuple NULL = new FormattingTuple(null);
|
||||
private String message;
|
||||
private Throwable throwable;
|
||||
private Object[] argArray;
|
||||
|
||||
private String message;
|
||||
private Throwable throwable;
|
||||
private Object[] argArray;
|
||||
|
||||
public FormattingTuple(String message) {
|
||||
this(message, null, null);
|
||||
}
|
||||
|
||||
public FormattingTuple(String message, Object[] argArray, Throwable throwable) {
|
||||
this.message = message;
|
||||
this.throwable = throwable;
|
||||
if(throwable == null) {
|
||||
this.argArray = argArray;
|
||||
} else {
|
||||
this.argArray = trimmedCopy(argArray);
|
||||
public FormattingTuple(String message) {
|
||||
this(message, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
static Object[] trimmedCopy(Object[] argArray) {
|
||||
if(argArray == null || argArray.length == 0) {
|
||||
throw new IllegalStateException("non-sensical empty or null argument array");
|
||||
public FormattingTuple(String message, Object[] argArray, Throwable throwable) {
|
||||
this.message = message;
|
||||
this.throwable = throwable;
|
||||
if (throwable == null) {
|
||||
this.argArray = argArray;
|
||||
} else {
|
||||
this.argArray = trimmedCopy(argArray);
|
||||
}
|
||||
}
|
||||
final int trimemdLen = argArray.length -1;
|
||||
Object[] trimmed = new Object[trimemdLen];
|
||||
System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
static Object[] trimmedCopy(Object[] argArray) {
|
||||
if (argArray == null || argArray.length == 0) {
|
||||
throw new IllegalStateException("non-sensical empty or null argument array");
|
||||
}
|
||||
final int trimemdLen = argArray.length - 1;
|
||||
Object[] trimmed = new Object[trimemdLen];
|
||||
System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
public Object[] getArgArray() {
|
||||
return argArray;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Throwable getThrowable() {
|
||||
return throwable;
|
||||
}
|
||||
public Object[] getArgArray() {
|
||||
return argArray;
|
||||
}
|
||||
|
||||
public Throwable getThrowable() {
|
||||
return throwable;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ package org.slf4j.helpers;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.Marker;
|
||||
|
||||
|
||||
/**
|
||||
* This class serves as base for adapters or native implementations of logging systems
|
||||
* lacking Marker support. In this implementation, methods taking marker data
|
||||
|
|
@ -38,131 +37,130 @@ import org.slf4j.Marker;
|
|||
*/
|
||||
public abstract class MarkerIgnoringBase extends NamedLoggerBase implements Logger {
|
||||
|
||||
private static final long serialVersionUID = 9044267456635152283L;
|
||||
private static final long serialVersionUID = 9044267456635152283L;
|
||||
|
||||
public boolean isTraceEnabled(Marker marker) {
|
||||
return isTraceEnabled();
|
||||
}
|
||||
public boolean isTraceEnabled(Marker marker) {
|
||||
return isTraceEnabled();
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg) {
|
||||
trace(msg);
|
||||
}
|
||||
public void trace(Marker marker, String msg) {
|
||||
trace(msg);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg) {
|
||||
trace(format, arg);
|
||||
}
|
||||
public void trace(Marker marker, String format, Object arg) {
|
||||
trace(format, arg);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object arg1, Object arg2) {
|
||||
trace(format, arg1, arg2);
|
||||
}
|
||||
public void trace(Marker marker, String format, Object arg1, Object arg2) {
|
||||
trace(format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String format, Object... arguments) {
|
||||
trace(format, arguments);
|
||||
}
|
||||
public void trace(Marker marker, String format, Object... arguments) {
|
||||
trace(format, arguments);
|
||||
}
|
||||
|
||||
public void trace(Marker marker, String msg, Throwable t) {
|
||||
trace(msg, t);
|
||||
}
|
||||
public void trace(Marker marker, String msg, Throwable t) {
|
||||
trace(msg, t);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled(Marker marker) {
|
||||
return isDebugEnabled();
|
||||
}
|
||||
public boolean isDebugEnabled(Marker marker) {
|
||||
return isDebugEnabled();
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg) {
|
||||
debug(msg);
|
||||
}
|
||||
public void debug(Marker marker, String msg) {
|
||||
debug(msg);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg) {
|
||||
debug(format, arg);
|
||||
}
|
||||
public void debug(Marker marker, String format, Object arg) {
|
||||
debug(format, arg);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object arg1, Object arg2) {
|
||||
debug(format, arg1, arg2);
|
||||
}
|
||||
public void debug(Marker marker, String format, Object arg1, Object arg2) {
|
||||
debug(format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String format, Object... arguments) {
|
||||
debug(format, arguments);
|
||||
}
|
||||
public void debug(Marker marker, String format, Object... arguments) {
|
||||
debug(format, arguments);
|
||||
}
|
||||
|
||||
public void debug(Marker marker, String msg, Throwable t) {
|
||||
debug(msg, t);
|
||||
}
|
||||
public void debug(Marker marker, String msg, Throwable t) {
|
||||
debug(msg, t);
|
||||
}
|
||||
|
||||
public boolean isInfoEnabled(Marker marker) {
|
||||
return isInfoEnabled();
|
||||
}
|
||||
public boolean isInfoEnabled(Marker marker) {
|
||||
return isInfoEnabled();
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg) {
|
||||
info(msg);
|
||||
}
|
||||
public void info(Marker marker, String msg) {
|
||||
info(msg);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg) {
|
||||
info(format, arg);
|
||||
}
|
||||
public void info(Marker marker, String format, Object arg) {
|
||||
info(format, arg);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object arg1, Object arg2) {
|
||||
info(format, arg1, arg2);
|
||||
}
|
||||
public void info(Marker marker, String format, Object arg1, Object arg2) {
|
||||
info(format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String format, Object... arguments) {
|
||||
info(format, arguments);
|
||||
}
|
||||
public void info(Marker marker, String format, Object... arguments) {
|
||||
info(format, arguments);
|
||||
}
|
||||
|
||||
public void info(Marker marker, String msg, Throwable t) {
|
||||
info(msg, t);
|
||||
}
|
||||
public void info(Marker marker, String msg, Throwable t) {
|
||||
info(msg, t);
|
||||
}
|
||||
|
||||
public boolean isWarnEnabled(Marker marker) {
|
||||
return isWarnEnabled();
|
||||
}
|
||||
public boolean isWarnEnabled(Marker marker) {
|
||||
return isWarnEnabled();
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg) {
|
||||
warn(msg);
|
||||
}
|
||||
public void warn(Marker marker, String msg) {
|
||||
warn(msg);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg) {
|
||||
warn(format, arg);
|
||||
}
|
||||
public void warn(Marker marker, String format, Object arg) {
|
||||
warn(format, arg);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object arg1, Object arg2) {
|
||||
warn(format, arg1, arg2);
|
||||
}
|
||||
public void warn(Marker marker, String format, Object arg1, Object arg2) {
|
||||
warn(format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String format, Object... arguments) {
|
||||
warn(format, arguments);
|
||||
}
|
||||
public void warn(Marker marker, String format, Object... arguments) {
|
||||
warn(format, arguments);
|
||||
}
|
||||
|
||||
public void warn(Marker marker, String msg, Throwable t) {
|
||||
warn(msg, t);
|
||||
}
|
||||
public void warn(Marker marker, String msg, Throwable t) {
|
||||
warn(msg, t);
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled(Marker marker) {
|
||||
return isErrorEnabled();
|
||||
}
|
||||
|
||||
public boolean isErrorEnabled(Marker marker) {
|
||||
return isErrorEnabled();
|
||||
}
|
||||
public void error(Marker marker, String msg) {
|
||||
error(msg);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg) {
|
||||
error(msg);
|
||||
}
|
||||
public void error(Marker marker, String format, Object arg) {
|
||||
error(format, arg);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg) {
|
||||
error(format, arg);
|
||||
}
|
||||
public void error(Marker marker, String format, Object arg1, Object arg2) {
|
||||
error(format, arg1, arg2);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object arg1, Object arg2) {
|
||||
error(format, arg1, arg2);
|
||||
}
|
||||
public void error(Marker marker, String format, Object... arguments) {
|
||||
error(format, arguments);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String format, Object... arguments) {
|
||||
error(format, arguments);
|
||||
}
|
||||
public void error(Marker marker, String msg, Throwable t) {
|
||||
error(msg, t);
|
||||
}
|
||||
|
||||
public void error(Marker marker, String msg, Throwable t) {
|
||||
error(msg, t);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getName()+"("+getName()+")";
|
||||
}
|
||||
public String toString() {
|
||||
return this.getClass().getName() + "(" + getName() + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,328 +96,317 @@ import java.util.Map;
|
|||
* @author Joern Huxhorn
|
||||
*/
|
||||
final public class MessageFormatter {
|
||||
static final char DELIM_START = '{';
|
||||
static final char DELIM_STOP = '}';
|
||||
static final String DELIM_STR = "{}";
|
||||
private static final char ESCAPE_CHAR = '\\';
|
||||
static final char DELIM_START = '{';
|
||||
static final char DELIM_STOP = '}';
|
||||
static final String DELIM_STR = "{}";
|
||||
private static final char ESCAPE_CHAR = '\\';
|
||||
|
||||
/**
|
||||
* Performs single argument substitution for the 'messagePattern' passed as
|
||||
* parameter.
|
||||
* <p>
|
||||
* For example,
|
||||
*
|
||||
* <pre>
|
||||
* MessageFormatter.format("Hi {}.", "there");
|
||||
* </pre>
|
||||
*
|
||||
* will return the string "Hi there.".
|
||||
* <p>
|
||||
*
|
||||
* @param messagePattern
|
||||
* The message pattern which will be parsed and formatted
|
||||
* @param argument
|
||||
* The argument to be substituted in place of the formatting anchor
|
||||
* @return The formatted message
|
||||
*/
|
||||
final public static FormattingTuple format(String messagePattern, Object arg) {
|
||||
return arrayFormat(messagePattern, new Object[] { arg });
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Performs a two argument substitution for the 'messagePattern' passed as
|
||||
* parameter.
|
||||
* <p>
|
||||
* For example,
|
||||
*
|
||||
* <pre>
|
||||
* MessageFormatter.format("Hi {}. My name is {}.", "Alice", "Bob");
|
||||
* </pre>
|
||||
*
|
||||
* will return the string "Hi Alice. My name is Bob.".
|
||||
*
|
||||
* @param messagePattern
|
||||
* The message pattern which will be parsed and formatted
|
||||
* @param arg1
|
||||
* The argument to be substituted in place of the first formatting
|
||||
* anchor
|
||||
* @param arg2
|
||||
* The argument to be substituted in place of the second formatting
|
||||
* anchor
|
||||
* @return The formatted message
|
||||
*/
|
||||
final public static FormattingTuple format(final String messagePattern,
|
||||
Object arg1, Object arg2) {
|
||||
return arrayFormat(messagePattern, new Object[] { arg1, arg2 });
|
||||
}
|
||||
|
||||
static final Throwable getThrowableCandidate(Object[] argArray) {
|
||||
if (argArray == null || argArray.length == 0) {
|
||||
return null;
|
||||
/**
|
||||
* Performs single argument substitution for the 'messagePattern' passed as
|
||||
* parameter.
|
||||
* <p>
|
||||
* For example,
|
||||
*
|
||||
* <pre>
|
||||
* MessageFormatter.format("Hi {}.", "there");
|
||||
* </pre>
|
||||
*
|
||||
* will return the string "Hi there.".
|
||||
* <p>
|
||||
*
|
||||
* @param messagePattern
|
||||
* The message pattern which will be parsed and formatted
|
||||
* @param argument
|
||||
* The argument to be substituted in place of the formatting anchor
|
||||
* @return The formatted message
|
||||
*/
|
||||
final public static FormattingTuple format(String messagePattern, Object arg) {
|
||||
return arrayFormat(messagePattern, new Object[] { arg });
|
||||
}
|
||||
|
||||
final Object lastEntry = argArray[argArray.length - 1];
|
||||
if (lastEntry instanceof Throwable) {
|
||||
return (Throwable) lastEntry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same principle as the {@link #format(String, Object)} and
|
||||
* {@link #format(String, Object, Object)} methods except that any number of
|
||||
* arguments can be passed in an array.
|
||||
*
|
||||
* @param messagePattern
|
||||
* The message pattern which will be parsed and formatted
|
||||
* @param argArray
|
||||
* An array of arguments to be substituted in place of formatting
|
||||
* anchors
|
||||
* @return The formatted message
|
||||
*/
|
||||
final public static FormattingTuple arrayFormat(final String messagePattern,
|
||||
final Object[] argArray) {
|
||||
|
||||
Throwable throwableCandidate = getThrowableCandidate(argArray);
|
||||
|
||||
if (messagePattern == null) {
|
||||
return new FormattingTuple(null, argArray, throwableCandidate);
|
||||
/**
|
||||
*
|
||||
* Performs a two argument substitution for the 'messagePattern' passed as
|
||||
* parameter.
|
||||
* <p>
|
||||
* For example,
|
||||
*
|
||||
* <pre>
|
||||
* MessageFormatter.format("Hi {}. My name is {}.", "Alice", "Bob");
|
||||
* </pre>
|
||||
*
|
||||
* will return the string "Hi Alice. My name is Bob.".
|
||||
*
|
||||
* @param messagePattern
|
||||
* The message pattern which will be parsed and formatted
|
||||
* @param arg1
|
||||
* The argument to be substituted in place of the first formatting
|
||||
* anchor
|
||||
* @param arg2
|
||||
* The argument to be substituted in place of the second formatting
|
||||
* anchor
|
||||
* @return The formatted message
|
||||
*/
|
||||
final public static FormattingTuple format(final String messagePattern, Object arg1, Object arg2) {
|
||||
return arrayFormat(messagePattern, new Object[] { arg1, arg2 });
|
||||
}
|
||||
|
||||
if (argArray == null) {
|
||||
return new FormattingTuple(messagePattern);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int j;
|
||||
// use string builder for better multicore performance
|
||||
StringBuilder sbuf = new StringBuilder(messagePattern.length() + 50);
|
||||
|
||||
int L;
|
||||
for (L = 0; L < argArray.length; L++) {
|
||||
|
||||
j = messagePattern.indexOf(DELIM_STR, i);
|
||||
|
||||
if (j == -1) {
|
||||
// no more variables
|
||||
if (i == 0) { // this is a simple string
|
||||
return new FormattingTuple(messagePattern, argArray,
|
||||
throwableCandidate);
|
||||
} else { // add the tail string which contains no variables and return
|
||||
// the result.
|
||||
sbuf.append(messagePattern.substring(i, messagePattern.length()));
|
||||
return new FormattingTuple(sbuf.toString(), argArray,
|
||||
throwableCandidate);
|
||||
static final Throwable getThrowableCandidate(Object[] argArray) {
|
||||
if (argArray == null || argArray.length == 0) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (isEscapedDelimeter(messagePattern, j)) {
|
||||
if (!isDoubleEscaped(messagePattern, j)) {
|
||||
L--; // DELIM_START was escaped, thus should not be incremented
|
||||
sbuf.append(messagePattern.substring(i, j - 1));
|
||||
sbuf.append(DELIM_START);
|
||||
i = j + 1;
|
||||
} else {
|
||||
// The escape character preceding the delimiter start is
|
||||
// itself escaped: "abc x:\\{}"
|
||||
// we have to consume one backward slash
|
||||
sbuf.append(messagePattern.substring(i, j - 1));
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
|
||||
i = j + 2;
|
||||
}
|
||||
|
||||
final Object lastEntry = argArray[argArray.length - 1];
|
||||
if (lastEntry instanceof Throwable) {
|
||||
return (Throwable) lastEntry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same principle as the {@link #format(String, Object)} and
|
||||
* {@link #format(String, Object, Object)} methods except that any number of
|
||||
* arguments can be passed in an array.
|
||||
*
|
||||
* @param messagePattern
|
||||
* The message pattern which will be parsed and formatted
|
||||
* @param argArray
|
||||
* An array of arguments to be substituted in place of formatting
|
||||
* anchors
|
||||
* @return The formatted message
|
||||
*/
|
||||
final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray) {
|
||||
|
||||
Throwable throwableCandidate = getThrowableCandidate(argArray);
|
||||
|
||||
if (messagePattern == null) {
|
||||
return new FormattingTuple(null, argArray, throwableCandidate);
|
||||
}
|
||||
|
||||
if (argArray == null) {
|
||||
return new FormattingTuple(messagePattern);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int j;
|
||||
// use string builder for better multicore performance
|
||||
StringBuilder sbuf = new StringBuilder(messagePattern.length() + 50);
|
||||
|
||||
int L;
|
||||
for (L = 0; L < argArray.length; L++) {
|
||||
|
||||
j = messagePattern.indexOf(DELIM_STR, i);
|
||||
|
||||
if (j == -1) {
|
||||
// no more variables
|
||||
if (i == 0) { // this is a simple string
|
||||
return new FormattingTuple(messagePattern, argArray, throwableCandidate);
|
||||
} else { // add the tail string which contains no variables and return
|
||||
// the result.
|
||||
sbuf.append(messagePattern.substring(i, messagePattern.length()));
|
||||
return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
|
||||
}
|
||||
} else {
|
||||
if (isEscapedDelimeter(messagePattern, j)) {
|
||||
if (!isDoubleEscaped(messagePattern, j)) {
|
||||
L--; // DELIM_START was escaped, thus should not be incremented
|
||||
sbuf.append(messagePattern.substring(i, j - 1));
|
||||
sbuf.append(DELIM_START);
|
||||
i = j + 1;
|
||||
} else {
|
||||
// The escape character preceding the delimiter start is
|
||||
// itself escaped: "abc x:\\{}"
|
||||
// we have to consume one backward slash
|
||||
sbuf.append(messagePattern.substring(i, j - 1));
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
|
||||
i = j + 2;
|
||||
}
|
||||
} else {
|
||||
// normal case
|
||||
sbuf.append(messagePattern.substring(i, j));
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
|
||||
i = j + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
// append the characters following the last {} pair.
|
||||
sbuf.append(messagePattern.substring(i, messagePattern.length()));
|
||||
if (L < argArray.length - 1) {
|
||||
return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
|
||||
} else {
|
||||
// normal case
|
||||
sbuf.append(messagePattern.substring(i, j));
|
||||
deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
|
||||
i = j + 2;
|
||||
return new FormattingTuple(sbuf.toString(), argArray, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
// append the characters following the last {} pair.
|
||||
sbuf.append(messagePattern.substring(i, messagePattern.length()));
|
||||
if (L < argArray.length - 1) {
|
||||
return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
|
||||
} else {
|
||||
return new FormattingTuple(sbuf.toString(), argArray, null);
|
||||
}
|
||||
}
|
||||
|
||||
final static boolean isEscapedDelimeter(String messagePattern,
|
||||
int delimeterStartIndex) {
|
||||
|
||||
if (delimeterStartIndex == 0) {
|
||||
return false;
|
||||
}
|
||||
char potentialEscape = messagePattern.charAt(delimeterStartIndex - 1);
|
||||
if (potentialEscape == ESCAPE_CHAR) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final static boolean isDoubleEscaped(String messagePattern,
|
||||
int delimeterStartIndex) {
|
||||
if (delimeterStartIndex >= 2
|
||||
&& messagePattern.charAt(delimeterStartIndex - 2) == ESCAPE_CHAR) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// special treatment of array values was suggested by 'lizongbo'
|
||||
private static void deeplyAppendParameter(StringBuilder sbuf, Object o,
|
||||
Map<Object[], Object> seenMap) {
|
||||
if (o == null) {
|
||||
sbuf.append("null");
|
||||
return;
|
||||
}
|
||||
if (!o.getClass().isArray()) {
|
||||
safeObjectAppend(sbuf, o);
|
||||
} else {
|
||||
// check for primitive array types because they
|
||||
// unfortunately cannot be cast to Object[]
|
||||
if (o instanceof boolean[]) {
|
||||
booleanArrayAppend(sbuf, (boolean[]) o);
|
||||
} else if (o instanceof byte[]) {
|
||||
byteArrayAppend(sbuf, (byte[]) o);
|
||||
} else if (o instanceof char[]) {
|
||||
charArrayAppend(sbuf, (char[]) o);
|
||||
} else if (o instanceof short[]) {
|
||||
shortArrayAppend(sbuf, (short[]) o);
|
||||
} else if (o instanceof int[]) {
|
||||
intArrayAppend(sbuf, (int[]) o);
|
||||
} else if (o instanceof long[]) {
|
||||
longArrayAppend(sbuf, (long[]) o);
|
||||
} else if (o instanceof float[]) {
|
||||
floatArrayAppend(sbuf, (float[]) o);
|
||||
} else if (o instanceof double[]) {
|
||||
doubleArrayAppend(sbuf, (double[]) o);
|
||||
} else {
|
||||
objectArrayAppend(sbuf, (Object[]) o, seenMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void safeObjectAppend(StringBuilder sbuf, Object o) {
|
||||
try {
|
||||
String oAsString = o.toString();
|
||||
sbuf.append(oAsString);
|
||||
} catch (Throwable t) {
|
||||
System.err
|
||||
.println("SLF4J: Failed toString() invocation on an object of type ["
|
||||
+ o.getClass().getName() + "]");
|
||||
t.printStackTrace();
|
||||
sbuf.append("[FAILED toString()]");
|
||||
}
|
||||
|
||||
}
|
||||
final static boolean isEscapedDelimeter(String messagePattern, int delimeterStartIndex) {
|
||||
|
||||
private static void objectArrayAppend(StringBuilder sbuf, Object[] a,
|
||||
Map<Object[], Object> seenMap) {
|
||||
sbuf.append('[');
|
||||
if (!seenMap.containsKey(a)) {
|
||||
seenMap.put(a, null);
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
deeplyAppendParameter(sbuf, a[i], seenMap);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
// allow repeats in siblings
|
||||
seenMap.remove(a);
|
||||
} else {
|
||||
sbuf.append("...");
|
||||
if (delimeterStartIndex == 0) {
|
||||
return false;
|
||||
}
|
||||
char potentialEscape = messagePattern.charAt(delimeterStartIndex - 1);
|
||||
if (potentialEscape == ESCAPE_CHAR) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void booleanArrayAppend(StringBuilder sbuf, boolean[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
final static boolean isDoubleEscaped(String messagePattern, int delimeterStartIndex) {
|
||||
if (delimeterStartIndex >= 2 && messagePattern.charAt(delimeterStartIndex - 2) == ESCAPE_CHAR) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void byteArrayAppend(StringBuilder sbuf, byte[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
// special treatment of array values was suggested by 'lizongbo'
|
||||
private static void deeplyAppendParameter(StringBuilder sbuf, Object o, Map<Object[], Object> seenMap) {
|
||||
if (o == null) {
|
||||
sbuf.append("null");
|
||||
return;
|
||||
}
|
||||
if (!o.getClass().isArray()) {
|
||||
safeObjectAppend(sbuf, o);
|
||||
} else {
|
||||
// check for primitive array types because they
|
||||
// unfortunately cannot be cast to Object[]
|
||||
if (o instanceof boolean[]) {
|
||||
booleanArrayAppend(sbuf, (boolean[]) o);
|
||||
} else if (o instanceof byte[]) {
|
||||
byteArrayAppend(sbuf, (byte[]) o);
|
||||
} else if (o instanceof char[]) {
|
||||
charArrayAppend(sbuf, (char[]) o);
|
||||
} else if (o instanceof short[]) {
|
||||
shortArrayAppend(sbuf, (short[]) o);
|
||||
} else if (o instanceof int[]) {
|
||||
intArrayAppend(sbuf, (int[]) o);
|
||||
} else if (o instanceof long[]) {
|
||||
longArrayAppend(sbuf, (long[]) o);
|
||||
} else if (o instanceof float[]) {
|
||||
floatArrayAppend(sbuf, (float[]) o);
|
||||
} else if (o instanceof double[]) {
|
||||
doubleArrayAppend(sbuf, (double[]) o);
|
||||
} else {
|
||||
objectArrayAppend(sbuf, (Object[]) o, seenMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void charArrayAppend(StringBuilder sbuf, char[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
private static void safeObjectAppend(StringBuilder sbuf, Object o) {
|
||||
try {
|
||||
String oAsString = o.toString();
|
||||
sbuf.append(oAsString);
|
||||
} catch (Throwable t) {
|
||||
System.err.println("SLF4J: Failed toString() invocation on an object of type [" + o.getClass().getName() + "]");
|
||||
t.printStackTrace();
|
||||
sbuf.append("[FAILED toString()]");
|
||||
}
|
||||
|
||||
private static void shortArrayAppend(StringBuilder sbuf, short[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void intArrayAppend(StringBuilder sbuf, int[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
private static void objectArrayAppend(StringBuilder sbuf, Object[] a, Map<Object[], Object> seenMap) {
|
||||
sbuf.append('[');
|
||||
if (!seenMap.containsKey(a)) {
|
||||
seenMap.put(a, null);
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
deeplyAppendParameter(sbuf, a[i], seenMap);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
// allow repeats in siblings
|
||||
seenMap.remove(a);
|
||||
} else {
|
||||
sbuf.append("...");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void longArrayAppend(StringBuilder sbuf, long[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
private static void booleanArrayAppend(StringBuilder sbuf, boolean[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void floatArrayAppend(StringBuilder sbuf, float[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
private static void byteArrayAppend(StringBuilder sbuf, byte[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void doubleArrayAppend(StringBuilder sbuf, double[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
private static void charArrayAppend(StringBuilder sbuf, char[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void shortArrayAppend(StringBuilder sbuf, short[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void intArrayAppend(StringBuilder sbuf, int[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void longArrayAppend(StringBuilder sbuf, long[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void floatArrayAppend(StringBuilder sbuf, float[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
|
||||
private static void doubleArrayAppend(StringBuilder sbuf, double[] a) {
|
||||
sbuf.append('[');
|
||||
final int len = a.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
sbuf.append(a[i]);
|
||||
if (i != len - 1)
|
||||
sbuf.append(", ");
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
sbuf.append(']');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ package org.slf4j.helpers;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.helpers.MarkerIgnoringBase;
|
||||
|
||||
|
||||
/**
|
||||
* A direct NOP (no operation) implementation of {@link Logger}.
|
||||
*
|
||||
|
|
@ -35,195 +34,187 @@ import org.slf4j.helpers.MarkerIgnoringBase;
|
|||
*/
|
||||
public class NOPLogger extends MarkerIgnoringBase {
|
||||
|
||||
private static final long serialVersionUID = -517220405410904473L;
|
||||
private static final long serialVersionUID = -517220405410904473L;
|
||||
|
||||
/**
|
||||
* The unique instance of NOPLogger.
|
||||
*/
|
||||
public static final NOPLogger NOP_LOGGER = new NOPLogger();
|
||||
/**
|
||||
* The unique instance of NOPLogger.
|
||||
*/
|
||||
public static final NOPLogger NOP_LOGGER = new NOPLogger();
|
||||
|
||||
/**
|
||||
* There is no point in creating multiple instances of NOPLOgger,
|
||||
* except by derived classes, hence the protected access for the constructor.
|
||||
*/
|
||||
protected NOPLogger() {
|
||||
}
|
||||
/**
|
||||
* There is no point in creating multiple instances of NOPLOgger,
|
||||
* except by derived classes, hence the protected access for the constructor.
|
||||
*/
|
||||
protected NOPLogger() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns the string value "NOP".
|
||||
*/
|
||||
public String getName() {
|
||||
return "NOP";
|
||||
}
|
||||
/**
|
||||
* Always returns the string value "NOP".
|
||||
*/
|
||||
public String getName() {
|
||||
return "NOP";
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isTraceEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void trace(String msg) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void trace(String msg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void trace(String format, Object arg) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void trace(String format, Object arg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void trace(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
public final void trace(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void trace(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
public final void trace(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void trace(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void trace(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isDebugEnabled() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isDebugEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void debug(String msg) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void debug(String msg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void debug(String format, Object arg) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void debug(String format, Object arg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void debug(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
public final void debug(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void debug(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
public final void debug(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void debug(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isInfoEnabled() {
|
||||
// NOP
|
||||
return false;
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void debug(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void info(String msg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isInfoEnabled() {
|
||||
// NOP
|
||||
return false;
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void info(String format, Object arg1) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void info(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void info(String msg) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
public final void info(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void info(String format, Object arg1) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void info(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void info(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isWarnEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void info(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String msg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String format, Object arg1) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void info(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void warn(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns false.
|
||||
* @return always false
|
||||
*/
|
||||
final public boolean isWarnEnabled() {
|
||||
return false;
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String msg) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public boolean isErrorEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String format, Object arg1) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void error(String msg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void error(String format, Object arg1) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void warn(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void error(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void error(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void warn(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public boolean isErrorEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void error(String msg) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void error(String format, Object arg1) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void error(String format, Object arg1, Object arg2) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
/** A NOP implementation. */
|
||||
public final void error(String format, Object... argArray) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
|
||||
/** A NOP implementation. */
|
||||
final public void error(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
/** A NOP implementation. */
|
||||
final public void error(String msg, Throwable t) {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.slf4j.ILoggerFactory;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.helpers.NOPLogger;
|
||||
|
||||
|
||||
/**
|
||||
* NOPLoggerFactory is an trivial implementation of {@link
|
||||
* ILoggerFactory} which always returns the unique instance of
|
||||
|
|
@ -38,12 +37,12 @@ import org.slf4j.helpers.NOPLogger;
|
|||
*/
|
||||
public class NOPLoggerFactory implements ILoggerFactory {
|
||||
|
||||
public NOPLoggerFactory() {
|
||||
// nothing to do
|
||||
}
|
||||
public NOPLoggerFactory() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public Logger getLogger(String name) {
|
||||
return NOPLogger.NOP_LOGGER;
|
||||
}
|
||||
public Logger getLogger(String name) {
|
||||
return NOPLogger.NOP_LOGGER;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,25 +39,25 @@ import org.slf4j.spi.MDCAdapter;
|
|||
*/
|
||||
public class NOPMDCAdapter implements MDCAdapter {
|
||||
|
||||
public void clear() {
|
||||
}
|
||||
public void clear() {
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
return null;
|
||||
}
|
||||
public String get(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void put(String key, String val) {
|
||||
}
|
||||
public void put(String key, String val) {
|
||||
}
|
||||
|
||||
public void remove(String key) {
|
||||
}
|
||||
public void remove(String key) {
|
||||
}
|
||||
|
||||
public Map<String, String> getCopyOfContextMap() {
|
||||
return null;
|
||||
}
|
||||
public Map<String, String> getCopyOfContextMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setContextMap(Map<String, String> contextMap) {
|
||||
// NOP
|
||||
}
|
||||
public void setContextMap(Map<String, String> contextMap) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,32 +39,32 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
abstract class NamedLoggerBase implements Logger, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7535258609338176893L;
|
||||
private static final long serialVersionUID = 7535258609338176893L;
|
||||
|
||||
protected String name;
|
||||
protected String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace this instance with a homonymous (same name) logger returned
|
||||
* by LoggerFactory. Note that this method is only called during
|
||||
* deserialization.
|
||||
*
|
||||
* <p>
|
||||
* This approach will work well if the desired ILoggerFactory is the one
|
||||
* references by LoggerFactory. However, if the user manages its logger hierarchy
|
||||
* through a different (non-static) mechanism, e.g. dependency injection, then
|
||||
* this approach would be mostly counterproductive.
|
||||
*
|
||||
* @return logger with same name as returned by LoggerFactory
|
||||
* @throws ObjectStreamException
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException {
|
||||
// using getName() instead of this.name works even for
|
||||
// NOPLogger
|
||||
return LoggerFactory.getLogger(getName());
|
||||
}
|
||||
/**
|
||||
* Replace this instance with a homonymous (same name) logger returned
|
||||
* by LoggerFactory. Note that this method is only called during
|
||||
* deserialization.
|
||||
*
|
||||
* <p>
|
||||
* This approach will work well if the desired ILoggerFactory is the one
|
||||
* references by LoggerFactory. However, if the user manages its logger hierarchy
|
||||
* through a different (non-static) mechanism, e.g. dependency injection, then
|
||||
* this approach would be mostly counterproductive.
|
||||
*
|
||||
* @return logger with same name as returned by LoggerFactory
|
||||
* @throws ObjectStreamException
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException {
|
||||
// using getName() instead of this.name works even for
|
||||
// NOPLogger
|
||||
return LoggerFactory.getLogger(getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -292,12 +292,15 @@ public class SubstituteLogger implements Logger {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
SubstituteLogger that = (SubstituteLogger) o;
|
||||
|
||||
if (!name.equals(that.name)) return false;
|
||||
if (!name.equals(that.name))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,28 +40,28 @@ import java.util.concurrent.ConcurrentMap;
|
|||
*/
|
||||
public class SubstituteLoggerFactory implements ILoggerFactory {
|
||||
|
||||
final ConcurrentMap<String, SubstituteLogger> loggers = new ConcurrentHashMap<String, SubstituteLogger>();
|
||||
final ConcurrentMap<String, SubstituteLogger> loggers = new ConcurrentHashMap<String, SubstituteLogger>();
|
||||
|
||||
public Logger getLogger(String name) {
|
||||
SubstituteLogger logger = loggers.get(name);
|
||||
if (logger == null) {
|
||||
logger = new SubstituteLogger(name);
|
||||
SubstituteLogger oldLogger = loggers.putIfAbsent(name, logger);
|
||||
if (oldLogger != null)
|
||||
logger = oldLogger;
|
||||
public Logger getLogger(String name) {
|
||||
SubstituteLogger logger = loggers.get(name);
|
||||
if (logger == null) {
|
||||
logger = new SubstituteLogger(name);
|
||||
SubstituteLogger oldLogger = loggers.putIfAbsent(name, logger);
|
||||
if (oldLogger != null)
|
||||
logger = oldLogger;
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
public List<String> getLoggerNames() {
|
||||
return new ArrayList<String>(loggers.keySet());
|
||||
}
|
||||
public List<String> getLoggerNames() {
|
||||
return new ArrayList<String>(loggers.keySet());
|
||||
}
|
||||
|
||||
public List<SubstituteLogger> getLoggers() {
|
||||
return new ArrayList<SubstituteLogger>(loggers.values());
|
||||
}
|
||||
public List<SubstituteLogger> getLoggers() {
|
||||
return new ArrayList<SubstituteLogger>(loggers.values());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
loggers.clear();
|
||||
}
|
||||
public void clear() {
|
||||
loggers.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
*/
|
||||
package org.slf4j.helpers;
|
||||
|
||||
|
||||
/**
|
||||
* An internal utility class.
|
||||
*
|
||||
|
|
@ -33,7 +32,8 @@ package org.slf4j.helpers;
|
|||
*/
|
||||
public final class Util {
|
||||
|
||||
private Util() {}
|
||||
private Util() {
|
||||
}
|
||||
|
||||
/**
|
||||
* In order to call {@link SecurityManager#getClassContext()}, which is a
|
||||
|
|
@ -59,16 +59,14 @@ public final class Util {
|
|||
|
||||
// Advance until Util is found
|
||||
int i;
|
||||
for(i = 0; i < trace.length; i++) {
|
||||
if(thisClassName.equals(trace[i].getName()))
|
||||
for (i = 0; i < trace.length; i++) {
|
||||
if (thisClassName.equals(trace[i].getName()))
|
||||
break;
|
||||
}
|
||||
|
||||
// trace[i] = Util; trace[i+1] = caller; trace[i+2] = caller's caller
|
||||
if(i >= trace.length || i + 2 >= trace.length) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to find org.slf4j.helpers.Util or its caller in the stack; " +
|
||||
"this should not happen");
|
||||
if (i >= trace.length || i + 2 >= trace.length) {
|
||||
throw new IllegalStateException("Failed to find org.slf4j.helpers.Util or its caller in the stack; " + "this should not happen");
|
||||
}
|
||||
|
||||
return trace[i + 2];
|
||||
|
|
|
|||
|
|
@ -38,36 +38,36 @@ import org.slf4j.ILoggerFactory;
|
|||
*/
|
||||
public class StaticLoggerBinder {
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
|
||||
|
||||
/**
|
||||
* Return the singleton of this class.
|
||||
*
|
||||
* @return the StaticLoggerBinder singleton
|
||||
*/
|
||||
public static final StaticLoggerBinder getSingleton() {
|
||||
return SINGLETON;
|
||||
}
|
||||
/**
|
||||
* Return the singleton of this class.
|
||||
*
|
||||
* @return the StaticLoggerBinder singleton
|
||||
*/
|
||||
public static final StaticLoggerBinder getSingleton() {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare the version of the SLF4J API this implementation is compiled against.
|
||||
* The value of this field is usually modified with each release.
|
||||
*/
|
||||
// to avoid constant folding by the compiler, this field must *not* be final
|
||||
public static String REQUESTED_API_VERSION = "1.6.99"; // !final
|
||||
/**
|
||||
* Declare the version of the SLF4J API this implementation is compiled against.
|
||||
* The value of this field is usually modified with each release.
|
||||
*/
|
||||
// to avoid constant folding by the compiler, this field must *not* be final
|
||||
public static String REQUESTED_API_VERSION = "1.6.99"; // !final
|
||||
|
||||
private StaticLoggerBinder() {
|
||||
throw new UnsupportedOperationException("This code should have never made it into slf4j-api.jar");
|
||||
}
|
||||
private StaticLoggerBinder() {
|
||||
throw new UnsupportedOperationException("This code should have never made it into slf4j-api.jar");
|
||||
}
|
||||
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
throw new UnsupportedOperationException("This code should never make it into slf4j-api.jar");
|
||||
}
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
throw new UnsupportedOperationException("This code should never make it into slf4j-api.jar");
|
||||
}
|
||||
|
||||
public String getLoggerFactoryClassStr() {
|
||||
throw new UnsupportedOperationException("This code should never make it into slf4j-api.jar");
|
||||
}
|
||||
public String getLoggerFactoryClassStr() {
|
||||
throw new UnsupportedOperationException("This code should never make it into slf4j-api.jar");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ package org.slf4j.impl;
|
|||
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
|
||||
|
||||
/**
|
||||
* This class is only a stub. Real implementations are found in
|
||||
* each SLF4J binding project, e.g. slf4j-nop, slf4j-log4j12 etc.
|
||||
|
|
@ -35,25 +34,24 @@ import org.slf4j.spi.MDCAdapter;
|
|||
*/
|
||||
public class StaticMDCBinder {
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
|
||||
private StaticMDCBinder() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
|
||||
private StaticMDCBinder() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
/**
|
||||
* Currently this method always returns an instance of
|
||||
* {@link StaticMDCBinder}.
|
||||
*/
|
||||
public MDCAdapter getMDCA() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently this method always returns an instance of
|
||||
* {@link StaticMDCBinder}.
|
||||
*/
|
||||
public MDCAdapter getMDCA() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
|
||||
public String getMDCAdapterClassStr() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
public String getMDCAdapterClassStr() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,30 +42,29 @@ import org.slf4j.spi.MarkerFactoryBinder;
|
|||
*/
|
||||
public class StaticMarkerBinder implements MarkerFactoryBinder {
|
||||
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
|
||||
/**
|
||||
* The unique instance of this class.
|
||||
*/
|
||||
public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
|
||||
|
||||
private StaticMarkerBinder() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
private StaticMarkerBinder() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently this method always returns an instance of
|
||||
* {@link BasicMarkerFactory}.
|
||||
*/
|
||||
public IMarkerFactory getMarkerFactory() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently, this method returns the class name of
|
||||
* {@link BasicMarkerFactory}.
|
||||
*/
|
||||
public String getMarkerFactoryClassStr() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
/**
|
||||
* Currently this method always returns an instance of
|
||||
* {@link BasicMarkerFactory}.
|
||||
*/
|
||||
public IMarkerFactory getMarkerFactory() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently, this method returns the class name of
|
||||
* {@link BasicMarkerFactory}.
|
||||
*/
|
||||
public String getMarkerFactoryClassStr() {
|
||||
throw new UnsupportedOperationException("This code should never make it into the jar");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,23 +39,22 @@ import org.slf4j.Marker;
|
|||
*/
|
||||
public interface LocationAwareLogger extends Logger {
|
||||
|
||||
final public int TRACE_INT = 00;
|
||||
final public int DEBUG_INT = 10;
|
||||
final public int INFO_INT = 20;
|
||||
final public int WARN_INT = 30;
|
||||
final public int ERROR_INT = 40;
|
||||
final public int TRACE_INT = 00;
|
||||
final public int DEBUG_INT = 10;
|
||||
final public int INFO_INT = 20;
|
||||
final public int WARN_INT = 30;
|
||||
final public int ERROR_INT = 40;
|
||||
|
||||
|
||||
/**
|
||||
* Printing method with support for location information.
|
||||
*
|
||||
* @param marker The marker to be used for this event, may be null.
|
||||
* @param fqcn The fully qualified class name of the <b>logger instance</b>,
|
||||
* typically the logger class, logger bridge or a logger wrapper.
|
||||
* @param level One of the level integers defined in this interface
|
||||
* @param message The message for the log event
|
||||
* @param t Throwable associated with the log event, may be null.
|
||||
*/
|
||||
public void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t);
|
||||
/**
|
||||
* Printing method with support for location information.
|
||||
*
|
||||
* @param marker The marker to be used for this event, may be null.
|
||||
* @param fqcn The fully qualified class name of the <b>logger instance</b>,
|
||||
* typically the logger class, logger bridge or a logger wrapper.
|
||||
* @param level One of the level integers defined in this interface
|
||||
* @param message The message for the log event
|
||||
* @param t Throwable associated with the log event, may be null.
|
||||
*/
|
||||
public void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,24 +34,24 @@ import org.slf4j.ILoggerFactory;
|
|||
*/
|
||||
public interface LoggerFactoryBinder {
|
||||
|
||||
/**
|
||||
* Return the instance of {@link ILoggerFactory} that
|
||||
* {@link org.slf4j.LoggerFactory} class should bind to.
|
||||
*
|
||||
* @return the instance of {@link ILoggerFactory} that
|
||||
* {@link org.slf4j.LoggerFactory} class should bind to.
|
||||
*/
|
||||
public ILoggerFactory getLoggerFactory();
|
||||
/**
|
||||
* Return the instance of {@link ILoggerFactory} that
|
||||
* {@link org.slf4j.LoggerFactory} class should bind to.
|
||||
*
|
||||
* @return the instance of {@link ILoggerFactory} that
|
||||
* {@link org.slf4j.LoggerFactory} class should bind to.
|
||||
*/
|
||||
public ILoggerFactory getLoggerFactory();
|
||||
|
||||
/**
|
||||
* The String form of the {@link ILoggerFactory} object that this
|
||||
* <code>LoggerFactoryBinder</code> instance is <em>intended</em> to return.
|
||||
*
|
||||
* <p>This method allows the developer to intterogate this binder's intention
|
||||
* which may be different from the {@link ILoggerFactory} instance it is able to
|
||||
* yield in practice. The discrepency should only occur in case of errors.
|
||||
*
|
||||
* @return the class name of the intended {@link ILoggerFactory} instance
|
||||
*/
|
||||
public String getLoggerFactoryClassStr();
|
||||
/**
|
||||
* The String form of the {@link ILoggerFactory} object that this
|
||||
* <code>LoggerFactoryBinder</code> instance is <em>intended</em> to return.
|
||||
*
|
||||
* <p>This method allows the developer to intterogate this binder's intention
|
||||
* which may be different from the {@link ILoggerFactory} instance it is able to
|
||||
* yield in practice. The discrepency should only occur in case of errors.
|
||||
*
|
||||
* @return the class name of the intended {@link ILoggerFactory} instance
|
||||
*/
|
||||
public String getLoggerFactoryClassStr();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,57 +35,57 @@ import java.util.Map;
|
|||
*/
|
||||
public interface MDCAdapter {
|
||||
|
||||
/**
|
||||
* Put a context value (the <code>val</code> parameter) as identified with
|
||||
* the <code>key</code> parameter into the current thread's context map.
|
||||
* The <code>key</code> parameter cannot be null. The code>val</code> parameter
|
||||
* can be null only if the underlying implementation supports it.
|
||||
*
|
||||
* <p>If the current thread does not have a context map it is created as a side
|
||||
* effect of this call.
|
||||
*/
|
||||
public void put(String key, String val);
|
||||
/**
|
||||
* Put a context value (the <code>val</code> parameter) as identified with
|
||||
* the <code>key</code> parameter into the current thread's context map.
|
||||
* The <code>key</code> parameter cannot be null. The code>val</code> parameter
|
||||
* can be null only if the underlying implementation supports it.
|
||||
*
|
||||
* <p>If the current thread does not have a context map it is created as a side
|
||||
* effect of this call.
|
||||
*/
|
||||
public void put(String key, String val);
|
||||
|
||||
/**
|
||||
* Get the context identified by the <code>key</code> parameter.
|
||||
* The <code>key</code> parameter cannot be null.
|
||||
*
|
||||
* @return the string value identified by the <code>key</code> parameter.
|
||||
*/
|
||||
public String get(String key);
|
||||
/**
|
||||
* Get the context identified by the <code>key</code> parameter.
|
||||
* The <code>key</code> parameter cannot be null.
|
||||
*
|
||||
* @return the string value identified by the <code>key</code> parameter.
|
||||
*/
|
||||
public String get(String key);
|
||||
|
||||
/**
|
||||
* Remove the the context identified by the <code>key</code> parameter.
|
||||
* The <code>key</code> parameter cannot be null.
|
||||
*
|
||||
* <p>
|
||||
* This method does nothing if there is no previous value
|
||||
* associated with <code>key</code>.
|
||||
*/
|
||||
public void remove(String key);
|
||||
/**
|
||||
* Remove the the context identified by the <code>key</code> parameter.
|
||||
* The <code>key</code> parameter cannot be null.
|
||||
*
|
||||
* <p>
|
||||
* This method does nothing if there is no previous value
|
||||
* associated with <code>key</code>.
|
||||
*/
|
||||
public void remove(String key);
|
||||
|
||||
/**
|
||||
* Clear all entries in the MDC.
|
||||
*/
|
||||
public void clear();
|
||||
/**
|
||||
* Clear all entries in the MDC.
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
/**
|
||||
* Return a copy of the current thread's context map, with keys and
|
||||
* values of type String. Returned value may be null.
|
||||
*
|
||||
* @return A copy of the current thread's context map. May be null.
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public Map<String, String> getCopyOfContextMap();
|
||||
/**
|
||||
* Return a copy of the current thread's context map, with keys and
|
||||
* values of type String. Returned value may be null.
|
||||
*
|
||||
* @return A copy of the current thread's context map. May be null.
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public Map<String, String> getCopyOfContextMap();
|
||||
|
||||
/**
|
||||
* Set the current thread's context map by first clearing any existing
|
||||
* map and then copying the map passed as parameter. The context map
|
||||
* parameter must only contain keys and values of type String.
|
||||
*
|
||||
* @param contextMap must contain only keys and values of type String
|
||||
*
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public void setContextMap(Map<String, String> contextMap);
|
||||
/**
|
||||
* Set the current thread's context map by first clearing any existing
|
||||
* map and then copying the map passed as parameter. The context map
|
||||
* parameter must only contain keys and values of type String.
|
||||
*
|
||||
* @param contextMap must contain only keys and values of type String
|
||||
*
|
||||
* @since 1.5.1
|
||||
*/
|
||||
public void setContextMap(Map<String, String> contextMap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ package org.slf4j.spi;
|
|||
|
||||
import org.slf4j.IMarkerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* An internal interface which helps the static {@link org.slf4j.MarkerFactory}
|
||||
* class bind with the appropriate {@link IMarkerFactory} instance.
|
||||
|
|
@ -35,24 +34,24 @@ import org.slf4j.IMarkerFactory;
|
|||
*/
|
||||
public interface MarkerFactoryBinder {
|
||||
|
||||
/**
|
||||
* Return the instance of {@link IMarkerFactory} that
|
||||
* {@link org.slf4j.MarkerFactory} class should bind to.
|
||||
*
|
||||
* @return the instance of {@link IMarkerFactory} that
|
||||
* {@link org.slf4j.MarkerFactory} class should bind to.
|
||||
*/
|
||||
public IMarkerFactory getMarkerFactory();
|
||||
/**
|
||||
* Return the instance of {@link IMarkerFactory} that
|
||||
* {@link org.slf4j.MarkerFactory} class should bind to.
|
||||
*
|
||||
* @return the instance of {@link IMarkerFactory} that
|
||||
* {@link org.slf4j.MarkerFactory} class should bind to.
|
||||
*/
|
||||
public IMarkerFactory getMarkerFactory();
|
||||
|
||||
/**
|
||||
* The String form of the {@link IMarkerFactory} object that this
|
||||
* <code>MarkerFactoryBinder</code> instance is <em>intended</em> to return.
|
||||
*
|
||||
* <p>This method allows the developer to intterogate this binder's intention
|
||||
* which may be different from the {@link IMarkerFactory} instance it is able to
|
||||
* return. Such a discrepency should only occur in case of errors.
|
||||
*
|
||||
* @return the class name of the intended {@link IMarkerFactory} instance
|
||||
*/
|
||||
public String getMarkerFactoryClassStr();
|
||||
/**
|
||||
* The String form of the {@link IMarkerFactory} object that this
|
||||
* <code>MarkerFactoryBinder</code> instance is <em>intended</em> to return.
|
||||
*
|
||||
* <p>This method allows the developer to intterogate this binder's intention
|
||||
* which may be different from the {@link IMarkerFactory} instance it is able to
|
||||
* return. Such a discrepency should only occur in case of errors.
|
||||
*
|
||||
* @return the class name of the intended {@link IMarkerFactory} instance
|
||||
*/
|
||||
public String getMarkerFactoryClassStr();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,160 +37,160 @@ import org.slf4j.helpers.BasicMarkerFactory;
|
|||
* @author Joern Huxhorn
|
||||
*/
|
||||
public class BasicMarkerTest extends TestCase {
|
||||
static final String BLUE_STR = "BLUE";
|
||||
static final String RED_STR = "RED";
|
||||
static final String GREEN_STR = "GREEN";
|
||||
static final String COMP_STR = "COMP";
|
||||
static final String MULTI_COMP_STR = "MULTI_COMP";
|
||||
static final String PARENT_MARKER_STR = "PARENT_MARKER";
|
||||
static final String CHILD_MARKER_STR = "CHILD_MARKER";
|
||||
static final String NOT_CONTAINED_MARKER_STR = "NOT_CONTAINED";
|
||||
static final String BLUE_STR = "BLUE";
|
||||
static final String RED_STR = "RED";
|
||||
static final String GREEN_STR = "GREEN";
|
||||
static final String COMP_STR = "COMP";
|
||||
static final String MULTI_COMP_STR = "MULTI_COMP";
|
||||
static final String PARENT_MARKER_STR = "PARENT_MARKER";
|
||||
static final String CHILD_MARKER_STR = "CHILD_MARKER";
|
||||
static final String NOT_CONTAINED_MARKER_STR = "NOT_CONTAINED";
|
||||
|
||||
final IMarkerFactory factory;
|
||||
final Marker blue;
|
||||
final Marker red;
|
||||
final Marker green;
|
||||
final Marker comp;
|
||||
final Marker multiComp;
|
||||
final IMarkerFactory factory;
|
||||
final Marker blue;
|
||||
final Marker red;
|
||||
final Marker green;
|
||||
final Marker comp;
|
||||
final Marker multiComp;
|
||||
|
||||
short diff = Differentiator.getDiffentiator();
|
||||
short diff = Differentiator.getDiffentiator();
|
||||
|
||||
public BasicMarkerTest() {
|
||||
factory = new BasicMarkerFactory();
|
||||
public BasicMarkerTest() {
|
||||
factory = new BasicMarkerFactory();
|
||||
|
||||
blue = factory.getMarker(BLUE_STR);
|
||||
red = factory.getMarker(RED_STR);
|
||||
green = factory.getMarker(GREEN_STR);
|
||||
comp = factory.getMarker(COMP_STR);
|
||||
comp.add(blue);
|
||||
blue = factory.getMarker(BLUE_STR);
|
||||
red = factory.getMarker(RED_STR);
|
||||
green = factory.getMarker(GREEN_STR);
|
||||
comp = factory.getMarker(COMP_STR);
|
||||
comp.add(blue);
|
||||
|
||||
multiComp = factory.getMarker(MULTI_COMP_STR);
|
||||
multiComp.add(green);
|
||||
multiComp.add(comp);
|
||||
}
|
||||
|
||||
public void testPrimitive() {
|
||||
assertEquals(BLUE_STR, blue.getName());
|
||||
assertTrue(blue.contains(blue));
|
||||
|
||||
Marker blue2 = factory.getMarker(BLUE_STR);
|
||||
assertEquals(BLUE_STR, blue2.getName());
|
||||
assertEquals(blue, blue2);
|
||||
assertTrue(blue.contains(blue2));
|
||||
assertTrue(blue2.contains(blue));
|
||||
}
|
||||
|
||||
public void testPrimitiveByName() {
|
||||
assertTrue(blue.contains(BLUE_STR));
|
||||
}
|
||||
|
||||
public void testComposite() {
|
||||
assertTrue(comp.contains(comp));
|
||||
assertTrue(comp.contains(blue));
|
||||
}
|
||||
|
||||
public void testCompositeByName() {
|
||||
assertTrue(comp.contains(COMP_STR));
|
||||
assertTrue(comp.contains(BLUE_STR));
|
||||
}
|
||||
|
||||
public void testMultiComposite() {
|
||||
assertTrue(multiComp.contains(comp));
|
||||
assertTrue(multiComp.contains(blue));
|
||||
assertTrue(multiComp.contains(green));
|
||||
assertFalse(multiComp.contains(red));
|
||||
}
|
||||
|
||||
public void testMultiCompositeByName() {
|
||||
assertTrue(multiComp.contains(COMP_STR));
|
||||
assertTrue(multiComp.contains(BLUE_STR));
|
||||
assertTrue(multiComp.contains(GREEN_STR));
|
||||
assertFalse(multiComp.contains(RED_STR));
|
||||
}
|
||||
|
||||
public void testMultiAdd() {
|
||||
Marker parent = factory.getMarker(PARENT_MARKER_STR);
|
||||
Marker child = factory.getMarker(CHILD_MARKER_STR);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
parent.add(child);
|
||||
multiComp = factory.getMarker(MULTI_COMP_STR);
|
||||
multiComp.add(green);
|
||||
multiComp.add(comp);
|
||||
}
|
||||
|
||||
// check that the child was added once and only once
|
||||
Iterator<Marker> iterator = parent.iterator();
|
||||
assertTrue(iterator.hasNext());
|
||||
assertEquals(CHILD_MARKER_STR, iterator.next().toString());
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
public void testPrimitive() {
|
||||
assertEquals(BLUE_STR, blue.getName());
|
||||
assertTrue(blue.contains(blue));
|
||||
|
||||
public void testAddRemove() {
|
||||
final String NEW_PREFIX = "NEW_";
|
||||
Marker parent = factory.getMarker(NEW_PREFIX + PARENT_MARKER_STR);
|
||||
Marker child = factory.getMarker(NEW_PREFIX + CHILD_MARKER_STR);
|
||||
assertFalse(parent.contains(child));
|
||||
assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
|
||||
assertFalse(parent.remove(child));
|
||||
Marker blue2 = factory.getMarker(BLUE_STR);
|
||||
assertEquals(BLUE_STR, blue2.getName());
|
||||
assertEquals(blue, blue2);
|
||||
assertTrue(blue.contains(blue2));
|
||||
assertTrue(blue2.contains(blue));
|
||||
}
|
||||
|
||||
parent.add(child);
|
||||
public void testPrimitiveByName() {
|
||||
assertTrue(blue.contains(BLUE_STR));
|
||||
}
|
||||
|
||||
assertTrue(parent.contains(child));
|
||||
assertTrue(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
|
||||
public void testComposite() {
|
||||
assertTrue(comp.contains(comp));
|
||||
assertTrue(comp.contains(blue));
|
||||
}
|
||||
|
||||
assertTrue(parent.remove(child));
|
||||
public void testCompositeByName() {
|
||||
assertTrue(comp.contains(COMP_STR));
|
||||
assertTrue(comp.contains(BLUE_STR));
|
||||
}
|
||||
|
||||
assertFalse(parent.contains(child));
|
||||
assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
|
||||
assertFalse(parent.remove(child));
|
||||
}
|
||||
public void testMultiComposite() {
|
||||
assertTrue(multiComp.contains(comp));
|
||||
assertTrue(multiComp.contains(blue));
|
||||
assertTrue(multiComp.contains(green));
|
||||
assertFalse(multiComp.contains(red));
|
||||
}
|
||||
|
||||
public void testSelfRecursion() {
|
||||
final String diffPrefix = "NEW_"+diff;
|
||||
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
|
||||
final String NOT_CONTAINED_NAME = diffPrefix + NOT_CONTAINED_MARKER_STR;
|
||||
Marker parent = factory.getMarker(PARENT_NAME);
|
||||
Marker notContained = factory.getMarker(NOT_CONTAINED_NAME);
|
||||
parent.add(parent);
|
||||
assertTrue(parent.contains(parent));
|
||||
assertTrue(parent.contains(PARENT_NAME));
|
||||
assertFalse(parent.contains(notContained));
|
||||
assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
|
||||
}
|
||||
public void testMultiCompositeByName() {
|
||||
assertTrue(multiComp.contains(COMP_STR));
|
||||
assertTrue(multiComp.contains(BLUE_STR));
|
||||
assertTrue(multiComp.contains(GREEN_STR));
|
||||
assertFalse(multiComp.contains(RED_STR));
|
||||
}
|
||||
|
||||
public void testIndirectRecursion() {
|
||||
final String diffPrefix = "NEW_"+diff;
|
||||
final String PARENT_NAME=diffPrefix+PARENT_MARKER_STR;
|
||||
final String CHILD_NAME=diffPrefix+CHILD_MARKER_STR;
|
||||
final String NOT_CONTAINED_NAME=diffPrefix+NOT_CONTAINED_MARKER_STR;
|
||||
public void testMultiAdd() {
|
||||
Marker parent = factory.getMarker(PARENT_MARKER_STR);
|
||||
Marker child = factory.getMarker(CHILD_MARKER_STR);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
parent.add(child);
|
||||
}
|
||||
|
||||
Marker parent = factory.getMarker(PARENT_NAME);
|
||||
Marker child = factory.getMarker(CHILD_NAME);
|
||||
Marker notContained = factory.getMarker(NOT_CONTAINED_NAME);
|
||||
// check that the child was added once and only once
|
||||
Iterator<Marker> iterator = parent.iterator();
|
||||
assertTrue(iterator.hasNext());
|
||||
assertEquals(CHILD_MARKER_STR, iterator.next().toString());
|
||||
assertFalse(iterator.hasNext());
|
||||
}
|
||||
|
||||
parent.add(child);
|
||||
child.add(parent);
|
||||
assertTrue(parent.contains(parent));
|
||||
assertTrue(parent.contains(child));
|
||||
assertTrue(parent.contains(PARENT_NAME));
|
||||
assertTrue(parent.contains(CHILD_NAME));
|
||||
assertFalse(parent.contains(notContained));
|
||||
assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
|
||||
}
|
||||
public void testAddRemove() {
|
||||
final String NEW_PREFIX = "NEW_";
|
||||
Marker parent = factory.getMarker(NEW_PREFIX + PARENT_MARKER_STR);
|
||||
Marker child = factory.getMarker(NEW_PREFIX + CHILD_MARKER_STR);
|
||||
assertFalse(parent.contains(child));
|
||||
assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
|
||||
assertFalse(parent.remove(child));
|
||||
|
||||
public void testHomonyms() {
|
||||
final String diffPrefix = "homonym"+diff;
|
||||
final String PARENT_NAME=diffPrefix+PARENT_MARKER_STR;
|
||||
final String CHILD_NAME=diffPrefix+CHILD_MARKER_STR;
|
||||
Marker parent = factory.getMarker(PARENT_NAME);
|
||||
Marker child = factory.getMarker(CHILD_NAME);
|
||||
parent.add(child);
|
||||
parent.add(child);
|
||||
|
||||
IMarkerFactory otherFactory = new BasicMarkerFactory();
|
||||
Marker otherParent = otherFactory.getMarker(PARENT_NAME);
|
||||
Marker otherChild = otherFactory.getMarker(CHILD_NAME);
|
||||
assertTrue(parent.contains(child));
|
||||
assertTrue(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
|
||||
|
||||
assertTrue(parent.contains(otherParent));
|
||||
assertTrue(parent.contains(otherChild));
|
||||
assertTrue(parent.remove(child));
|
||||
|
||||
assertTrue(parent.remove(otherChild));
|
||||
}
|
||||
assertFalse(parent.contains(child));
|
||||
assertFalse(parent.contains(NEW_PREFIX + CHILD_MARKER_STR));
|
||||
assertFalse(parent.remove(child));
|
||||
}
|
||||
|
||||
public void testSelfRecursion() {
|
||||
final String diffPrefix = "NEW_" + diff;
|
||||
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
|
||||
final String NOT_CONTAINED_NAME = diffPrefix + NOT_CONTAINED_MARKER_STR;
|
||||
Marker parent = factory.getMarker(PARENT_NAME);
|
||||
Marker notContained = factory.getMarker(NOT_CONTAINED_NAME);
|
||||
parent.add(parent);
|
||||
assertTrue(parent.contains(parent));
|
||||
assertTrue(parent.contains(PARENT_NAME));
|
||||
assertFalse(parent.contains(notContained));
|
||||
assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
|
||||
}
|
||||
|
||||
public void testIndirectRecursion() {
|
||||
final String diffPrefix = "NEW_" + diff;
|
||||
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
|
||||
final String CHILD_NAME = diffPrefix + CHILD_MARKER_STR;
|
||||
final String NOT_CONTAINED_NAME = diffPrefix + NOT_CONTAINED_MARKER_STR;
|
||||
|
||||
Marker parent = factory.getMarker(PARENT_NAME);
|
||||
Marker child = factory.getMarker(CHILD_NAME);
|
||||
Marker notContained = factory.getMarker(NOT_CONTAINED_NAME);
|
||||
|
||||
parent.add(child);
|
||||
child.add(parent);
|
||||
assertTrue(parent.contains(parent));
|
||||
assertTrue(parent.contains(child));
|
||||
assertTrue(parent.contains(PARENT_NAME));
|
||||
assertTrue(parent.contains(CHILD_NAME));
|
||||
assertFalse(parent.contains(notContained));
|
||||
assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
|
||||
}
|
||||
|
||||
public void testHomonyms() {
|
||||
final String diffPrefix = "homonym" + diff;
|
||||
final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
|
||||
final String CHILD_NAME = diffPrefix + CHILD_MARKER_STR;
|
||||
Marker parent = factory.getMarker(PARENT_NAME);
|
||||
Marker child = factory.getMarker(CHILD_NAME);
|
||||
parent.add(child);
|
||||
|
||||
IMarkerFactory otherFactory = new BasicMarkerFactory();
|
||||
Marker otherParent = otherFactory.getMarker(PARENT_NAME);
|
||||
Marker otherChild = otherFactory.getMarker(CHILD_NAME);
|
||||
|
||||
assertTrue(parent.contains(otherParent));
|
||||
assertTrue(parent.contains(otherChild));
|
||||
|
||||
assertTrue(parent.remove(otherChild));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ import java.util.Random;
|
|||
|
||||
public class Differentiator {
|
||||
|
||||
static Random random = new Random(System.currentTimeMillis());
|
||||
static Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
static public short getDiffentiator() {
|
||||
return (short) random.nextInt(Short.MAX_VALUE);
|
||||
}
|
||||
static public short getDiffentiator() {
|
||||
return (short) random.nextInt(Short.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,21 +33,21 @@ import junit.framework.TestCase;
|
|||
|
||||
public class NoBindingTest extends TestCase {
|
||||
|
||||
int diff = new Random().nextInt(10000);
|
||||
int diff = new Random().nextInt(10000);
|
||||
|
||||
public void testLogger() {
|
||||
Logger logger = LoggerFactory.getLogger(NoBindingTest.class);
|
||||
logger.debug("hello"+diff);
|
||||
assertTrue(logger instanceof NOPLogger);
|
||||
}
|
||||
public void testLogger() {
|
||||
Logger logger = LoggerFactory.getLogger(NoBindingTest.class);
|
||||
logger.debug("hello" + diff);
|
||||
assertTrue(logger instanceof NOPLogger);
|
||||
}
|
||||
|
||||
public void testMDC() {
|
||||
MDC.put("k"+diff, "v");
|
||||
assertNull(MDC.get("k"));
|
||||
}
|
||||
public void testMDC() {
|
||||
MDC.put("k" + diff, "v");
|
||||
assertNull(MDC.get("k"));
|
||||
}
|
||||
|
||||
public void testMarker() {
|
||||
Marker m = MarkerFactory.getMarker("a"+diff);
|
||||
assertTrue(m instanceof BasicMarker);
|
||||
}
|
||||
public void testMarker() {
|
||||
Marker m = MarkerFactory.getMarker("a" + diff);
|
||||
assertTrue(m instanceof BasicMarker);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,124 +36,115 @@ import junit.framework.AssertionFailedError;
|
|||
*/
|
||||
public class BogoPerf {
|
||||
|
||||
private static long NANOS_IN_ONE_SECOND = 1000 * 1000 * 1000;
|
||||
private static int INITIAL_N = 1000;
|
||||
private static int LAST_N = 100;
|
||||
private static int SLACK_FACTOR = 3;
|
||||
private static long NANOS_IN_ONE_SECOND = 1000 * 1000 * 1000;
|
||||
private static int INITIAL_N = 1000;
|
||||
private static int LAST_N = 100;
|
||||
private static int SLACK_FACTOR = 3;
|
||||
|
||||
static {
|
||||
// let the JIT warm up
|
||||
computeBogoIPS(INITIAL_N);
|
||||
double bogo_ips = computeBogoIPS(INITIAL_N);
|
||||
System.out.println("Host runs at " + bogo_ips + " BIPS");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute bogoInstructions per second
|
||||
* <p>
|
||||
* on a 3.2 Ghz Pentium D CPU (around 2007), we obtain about 9'000 bogoIPS.
|
||||
*
|
||||
* @param N
|
||||
* number of bogoInstructions to average over in order to
|
||||
* compute the result
|
||||
* @return bogo Instructions Per Second
|
||||
*/
|
||||
private static double computeBogoIPS(int N) {
|
||||
long begin = System.nanoTime();
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
bogoInstruction();
|
||||
static {
|
||||
// let the JIT warm up
|
||||
computeBogoIPS(INITIAL_N);
|
||||
double bogo_ips = computeBogoIPS(INITIAL_N);
|
||||
System.out.println("Host runs at " + bogo_ips + " BIPS");
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
|
||||
// duration
|
||||
double D = end - begin;
|
||||
// average duration per instruction
|
||||
double avgDPIS = D / N;
|
||||
// System.out.println(D + " nanos for " + N + " instructions");
|
||||
// System.out.println(avgD + " nanos per instruction");
|
||||
/**
|
||||
* Compute bogoInstructions per second
|
||||
* <p>
|
||||
* on a 3.2 Ghz Pentium D CPU (around 2007), we obtain about 9'000 bogoIPS.
|
||||
*
|
||||
* @param N
|
||||
* number of bogoInstructions to average over in order to
|
||||
* compute the result
|
||||
* @return bogo Instructions Per Second
|
||||
*/
|
||||
private static double computeBogoIPS(int N) {
|
||||
long begin = System.nanoTime();
|
||||
|
||||
double bogoIPS = NANOS_IN_ONE_SECOND / avgDPIS;
|
||||
// System.out.println(bogoIPS + " bogoIPS");
|
||||
for (int i = 0; i < N; i++) {
|
||||
bogoInstruction();
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
|
||||
return bogoIPS;
|
||||
}
|
||||
// duration
|
||||
double D = end - begin;
|
||||
// average duration per instruction
|
||||
double avgDPIS = D / N;
|
||||
// System.out.println(D + " nanos for " + N + " instructions");
|
||||
// System.out.println(avgD + " nanos per instruction");
|
||||
|
||||
private static void bogoInstruction() {
|
||||
// use our own random number generator, independent of the host JDK
|
||||
MyRandom myRandom = new MyRandom(100);
|
||||
int len = 150;
|
||||
int[] intArray = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
intArray[i] = myRandom.nextInt();
|
||||
double bogoIPS = NANOS_IN_ONE_SECOND / avgDPIS;
|
||||
// System.out.println(bogoIPS + " bogoIPS");
|
||||
|
||||
return bogoIPS;
|
||||
}
|
||||
// use our own sort algorithm, independent of the host JDK
|
||||
BubbleSort.sort(intArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computed the BogoIPS for this host CPU.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static double currentBIPS() {
|
||||
return computeBogoIPS(LAST_N);
|
||||
}
|
||||
|
||||
static double min(double a, double b) {
|
||||
return (a <= b) ? a : b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assertion used for values that <b>decrease</b> with faster CPUs, typically
|
||||
* the time (duration) needed to perform a task.
|
||||
*
|
||||
* @param currentDuration
|
||||
* @param referenceDuration
|
||||
* @param referenceBIPS
|
||||
* @throws AssertionFailedError
|
||||
*/
|
||||
public static void assertDuration(double currentDuration,
|
||||
long referenceDuration, double referenceBIPS) throws AssertionFailedError {
|
||||
double ajustedDuration = adjustExpectedDuration(referenceDuration,
|
||||
referenceBIPS);
|
||||
if (currentDuration > ajustedDuration * SLACK_FACTOR) {
|
||||
throw new AssertionFailedError("current duration " + currentDuration
|
||||
+ " exceeded expected " + ajustedDuration + " (adjusted reference), "
|
||||
+ referenceDuration + " (raw reference)");
|
||||
private static void bogoInstruction() {
|
||||
// use our own random number generator, independent of the host JDK
|
||||
MyRandom myRandom = new MyRandom(100);
|
||||
int len = 150;
|
||||
int[] intArray = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
intArray[i] = myRandom.nextInt();
|
||||
}
|
||||
// use our own sort algorithm, independent of the host JDK
|
||||
BubbleSort.sort(intArray);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assertion used for values that <b>increase<b> with faster CPUs, typically
|
||||
* the number of operations accomplished per unit of time.
|
||||
*
|
||||
* @param currentPerformance
|
||||
* @param referencePerformance
|
||||
* @param referenceBIPS
|
||||
* @throws AssertionFailedError
|
||||
*/
|
||||
public static void assertPerformance(double currentPerformance,
|
||||
long referencePerformance, double referenceBIPS)
|
||||
throws AssertionFailedError {
|
||||
double ajustedPerf = adjustExpectedPerformance(referencePerformance,
|
||||
referenceBIPS);
|
||||
if (currentPerformance * SLACK_FACTOR < ajustedPerf) {
|
||||
throw new AssertionFailedError(currentPerformance + " below expected "
|
||||
+ ajustedPerf + " (adjusted), " + referencePerformance + " (raw)");
|
||||
/**
|
||||
* Computed the BogoIPS for this host CPU.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static double currentBIPS() {
|
||||
return computeBogoIPS(LAST_N);
|
||||
}
|
||||
}
|
||||
|
||||
private static double adjustExpectedPerformance(long referenceDuration,
|
||||
double referenceBIPS) {
|
||||
double currentBIPS = currentBIPS();
|
||||
return referenceDuration * (currentBIPS / referenceBIPS);
|
||||
}
|
||||
static double min(double a, double b) {
|
||||
return (a <= b) ? a : b;
|
||||
}
|
||||
|
||||
private static double adjustExpectedDuration(long referenceDuration,
|
||||
double referenceBIPS) {
|
||||
double currentBIPS = currentBIPS();
|
||||
System.out.println("currentBIPS=" + currentBIPS + " BIPS");
|
||||
return referenceDuration * (referenceBIPS / currentBIPS);
|
||||
}
|
||||
/**
|
||||
* Assertion used for values that <b>decrease</b> with faster CPUs, typically
|
||||
* the time (duration) needed to perform a task.
|
||||
*
|
||||
* @param currentDuration
|
||||
* @param referenceDuration
|
||||
* @param referenceBIPS
|
||||
* @throws AssertionFailedError
|
||||
*/
|
||||
public static void assertDuration(double currentDuration, long referenceDuration, double referenceBIPS) throws AssertionFailedError {
|
||||
double ajustedDuration = adjustExpectedDuration(referenceDuration, referenceBIPS);
|
||||
if (currentDuration > ajustedDuration * SLACK_FACTOR) {
|
||||
throw new AssertionFailedError("current duration " + currentDuration + " exceeded expected " + ajustedDuration + " (adjusted reference), "
|
||||
+ referenceDuration + " (raw reference)");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assertion used for values that <b>increase<b> with faster CPUs, typically
|
||||
* the number of operations accomplished per unit of time.
|
||||
*
|
||||
* @param currentPerformance
|
||||
* @param referencePerformance
|
||||
* @param referenceBIPS
|
||||
* @throws AssertionFailedError
|
||||
*/
|
||||
public static void assertPerformance(double currentPerformance, long referencePerformance, double referenceBIPS) throws AssertionFailedError {
|
||||
double ajustedPerf = adjustExpectedPerformance(referencePerformance, referenceBIPS);
|
||||
if (currentPerformance * SLACK_FACTOR < ajustedPerf) {
|
||||
throw new AssertionFailedError(currentPerformance + " below expected " + ajustedPerf + " (adjusted), " + referencePerformance + " (raw)");
|
||||
}
|
||||
}
|
||||
|
||||
private static double adjustExpectedPerformance(long referenceDuration, double referenceBIPS) {
|
||||
double currentBIPS = currentBIPS();
|
||||
return referenceDuration * (currentBIPS / referenceBIPS);
|
||||
}
|
||||
|
||||
private static double adjustExpectedDuration(long referenceDuration, double referenceBIPS) {
|
||||
double currentBIPS = currentBIPS();
|
||||
System.out.println("currentBIPS=" + currentBIPS + " BIPS");
|
||||
return referenceDuration * (referenceBIPS / currentBIPS);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,19 +32,20 @@ package org.slf4j.helpers;
|
|||
*/
|
||||
class BubbleSort {
|
||||
|
||||
static void sort(int[] a) {
|
||||
int len = a.length;
|
||||
for (int i = 0; i < len - 1; i++) {
|
||||
for (int j = 0; j < len - 1 - i; j++) {
|
||||
if (a[j] > a[j + 1]) {
|
||||
swap(a, j, j + 1);
|
||||
static void sort(int[] a) {
|
||||
int len = a.length;
|
||||
for (int i = 0; i < len - 1; i++) {
|
||||
for (int j = 0; j < len - 1 - i; j++) {
|
||||
if (a[j] > a[j + 1]) {
|
||||
swap(a, j, j + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static void swap(int[] a, int i, int j) {
|
||||
int t = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = t;
|
||||
}
|
||||
|
||||
static void swap(int[] a, int i, int j) {
|
||||
int t = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = t;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,65 +37,64 @@ import junit.framework.TestCase;
|
|||
*/
|
||||
public class BubbleSortTest extends TestCase {
|
||||
|
||||
public void testSmoke() {
|
||||
int[] a = new int[] {5,3,2,7};
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(2, a[i++]);
|
||||
assertEquals(3, a[i++]);
|
||||
assertEquals(5, a[i++]);
|
||||
assertEquals(7, a[i++]);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
int[] a = new int[] {};
|
||||
BubbleSort.sort(a);
|
||||
}
|
||||
|
||||
public void testSorted() {
|
||||
int[] a = new int[] {3,30,300,3000};
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(3, a[i++]);
|
||||
assertEquals(30, a[i++]);
|
||||
assertEquals(300, a[i++]);
|
||||
assertEquals(3000, a[i++]);
|
||||
}
|
||||
|
||||
public void testInverted() {
|
||||
int[] a = new int[] {3000,300,30,3};
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(3, a[i++]);
|
||||
assertEquals(30, a[i++]);
|
||||
assertEquals(300, a[i++]);
|
||||
assertEquals(3000, a[i++]);
|
||||
}
|
||||
|
||||
public void testWithSameEntry() {
|
||||
int[] a = new int[] {10,20,10,20};
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(10, a[i++]);
|
||||
assertEquals(10, a[i++]);
|
||||
assertEquals(20, a[i++]);
|
||||
assertEquals(20, a[i++]);
|
||||
}
|
||||
|
||||
|
||||
public void testRandom() {
|
||||
int len = 100;
|
||||
Random random = new Random(156);
|
||||
int[] a = new int[len];
|
||||
int[] witness = new int[len];
|
||||
for(int i = 0; i < len; i++) {
|
||||
int r = random.nextInt();
|
||||
a[i] = r;
|
||||
witness[i] = r;
|
||||
public void testSmoke() {
|
||||
int[] a = new int[] { 5, 3, 2, 7 };
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(2, a[i++]);
|
||||
assertEquals(3, a[i++]);
|
||||
assertEquals(5, a[i++]);
|
||||
assertEquals(7, a[i++]);
|
||||
}
|
||||
|
||||
public void testEmpty() {
|
||||
int[] a = new int[] {};
|
||||
BubbleSort.sort(a);
|
||||
}
|
||||
|
||||
public void testSorted() {
|
||||
int[] a = new int[] { 3, 30, 300, 3000 };
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(3, a[i++]);
|
||||
assertEquals(30, a[i++]);
|
||||
assertEquals(300, a[i++]);
|
||||
assertEquals(3000, a[i++]);
|
||||
}
|
||||
|
||||
public void testInverted() {
|
||||
int[] a = new int[] { 3000, 300, 30, 3 };
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(3, a[i++]);
|
||||
assertEquals(30, a[i++]);
|
||||
assertEquals(300, a[i++]);
|
||||
assertEquals(3000, a[i++]);
|
||||
}
|
||||
|
||||
public void testWithSameEntry() {
|
||||
int[] a = new int[] { 10, 20, 10, 20 };
|
||||
BubbleSort.sort(a);
|
||||
int i = 0;
|
||||
assertEquals(10, a[i++]);
|
||||
assertEquals(10, a[i++]);
|
||||
assertEquals(20, a[i++]);
|
||||
assertEquals(20, a[i++]);
|
||||
}
|
||||
|
||||
public void testRandom() {
|
||||
int len = 100;
|
||||
Random random = new Random(156);
|
||||
int[] a = new int[len];
|
||||
int[] witness = new int[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
int r = random.nextInt();
|
||||
a[i] = r;
|
||||
witness[i] = r;
|
||||
}
|
||||
BubbleSort.sort(a);
|
||||
Arrays.sort(witness);
|
||||
assertTrue(Arrays.equals(witness, a));
|
||||
}
|
||||
BubbleSort.sort(a);
|
||||
Arrays.sort(witness);
|
||||
assertTrue(Arrays.equals(witness, a));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,84 +32,80 @@ import org.junit.Ignore;
|
|||
@Ignore
|
||||
public class MessageFormatterPerfTest extends TestCase {
|
||||
|
||||
Integer i1 = new Integer(1);
|
||||
Integer i2 = new Integer(2);
|
||||
static long RUN_LENGTH = 100 * 1000;
|
||||
//
|
||||
static long REFERENCE_BIPS = 48416;
|
||||
Integer i1 = new Integer(1);
|
||||
Integer i2 = new Integer(2);
|
||||
static long RUN_LENGTH = 100 * 1000;
|
||||
//
|
||||
static long REFERENCE_BIPS = 48416;
|
||||
|
||||
public MessageFormatterPerfTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void XtestJDKFormatterPerf() {
|
||||
jdkMessageFormatter(RUN_LENGTH);
|
||||
double duration = jdkMessageFormatter(RUN_LENGTH);
|
||||
System.out.println("jdk duration = " + duration + " nanos");
|
||||
}
|
||||
|
||||
public void testSLF4JPerf_OneArg() {
|
||||
slf4jMessageFormatter_OneArg(RUN_LENGTH);
|
||||
double duration = slf4jMessageFormatter_OneArg(RUN_LENGTH);
|
||||
System.out.println("duration=" + duration);
|
||||
long referencePerf = 36;
|
||||
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
|
||||
}
|
||||
|
||||
public void testSLF4JPerf_TwoArg() {
|
||||
slf4jMessageFormatter_TwoArg(RUN_LENGTH);
|
||||
double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
|
||||
long referencePerf = 60;
|
||||
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
|
||||
}
|
||||
|
||||
|
||||
public double slf4jMessageFormatter_OneArg(long len) {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < len; i++) {
|
||||
final FormattingTuple tp = MessageFormatter.format("This is some rather short message {} ", i1);
|
||||
tp.getMessage();
|
||||
tp.getArgArray();
|
||||
tp.getThrowable();
|
||||
|
||||
MessageFormatter.format("This is some rather short message {} ", i1);
|
||||
public MessageFormatterPerfTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start)/(1000*1000.0);
|
||||
}
|
||||
|
||||
public double slf4jMessageFormatter_TwoArg(long len) {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < len; i++) {
|
||||
final FormattingTuple tp = MessageFormatter.format(
|
||||
"This is some {} short message {} ", i1, i2);
|
||||
tp.getMessage();
|
||||
tp.getArgArray();
|
||||
tp.getThrowable();
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start)/(1000*1000.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public double jdkMessageFormatter(long len) {
|
||||
@SuppressWarnings("unused")
|
||||
String s = "";
|
||||
s += ""; // keep compiler happy
|
||||
long start = System.currentTimeMillis();
|
||||
Object[] oa = new Object[] { i1 };
|
||||
for (int i = 0; i < len; i++) {
|
||||
s = MessageFormat.format("This is some rather short message {0}", oa);
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
public void XtestJDKFormatterPerf() {
|
||||
jdkMessageFormatter(RUN_LENGTH);
|
||||
double duration = jdkMessageFormatter(RUN_LENGTH);
|
||||
System.out.println("jdk duration = " + duration + " nanos");
|
||||
}
|
||||
|
||||
public void testSLF4JPerf_OneArg() {
|
||||
slf4jMessageFormatter_OneArg(RUN_LENGTH);
|
||||
double duration = slf4jMessageFormatter_OneArg(RUN_LENGTH);
|
||||
System.out.println("duration=" + duration);
|
||||
long referencePerf = 36;
|
||||
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
|
||||
}
|
||||
|
||||
public void testSLF4JPerf_TwoArg() {
|
||||
slf4jMessageFormatter_TwoArg(RUN_LENGTH);
|
||||
double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
|
||||
long referencePerf = 60;
|
||||
BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
|
||||
}
|
||||
|
||||
public double slf4jMessageFormatter_OneArg(long len) {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < len; i++) {
|
||||
final FormattingTuple tp = MessageFormatter.format("This is some rather short message {} ", i1);
|
||||
tp.getMessage();
|
||||
tp.getArgArray();
|
||||
tp.getThrowable();
|
||||
|
||||
MessageFormatter.format("This is some rather short message {} ", i1);
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start) / (1000 * 1000.0);
|
||||
}
|
||||
|
||||
public double slf4jMessageFormatter_TwoArg(long len) {
|
||||
long start = System.nanoTime();
|
||||
for (int i = 0; i < len; i++) {
|
||||
final FormattingTuple tp = MessageFormatter.format("This is some {} short message {} ", i1, i2);
|
||||
tp.getMessage();
|
||||
tp.getArgArray();
|
||||
tp.getThrowable();
|
||||
}
|
||||
long end = System.nanoTime();
|
||||
return (end - start) / (1000 * 1000.0);
|
||||
}
|
||||
|
||||
public double jdkMessageFormatter(long len) {
|
||||
@SuppressWarnings("unused")
|
||||
String s = "";
|
||||
s += ""; // keep compiler happy
|
||||
long start = System.currentTimeMillis();
|
||||
Object[] oa = new Object[] { i1 };
|
||||
for (int i = 0; i < len; i++) {
|
||||
s = MessageFormat.format("This is some rather short message {0}", oa);
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
return (1.0 * end - start);
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
return (1.0 * end - start);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,327 +35,290 @@ import static org.junit.Assert.*;
|
|||
*/
|
||||
public class MessageFormatterTest {
|
||||
|
||||
Integer i1 = new Integer(1);
|
||||
Integer i2 = new Integer(2);
|
||||
Integer i3 = new Integer(3);
|
||||
Integer[] ia0 = new Integer[] { i1, i2, i3 };
|
||||
Integer[] ia1 = new Integer[] { new Integer(10), new Integer(20),
|
||||
new Integer(30) };
|
||||
Integer i1 = new Integer(1);
|
||||
Integer i2 = new Integer(2);
|
||||
Integer i3 = new Integer(3);
|
||||
Integer[] ia0 = new Integer[] { i1, i2, i3 };
|
||||
Integer[] ia1 = new Integer[] { new Integer(10), new Integer(20), new Integer(30) };
|
||||
|
||||
String result;
|
||||
String result;
|
||||
|
||||
@Test
|
||||
public void testNull() {
|
||||
result = MessageFormatter.format(null, i1).getMessage();
|
||||
assertEquals(null, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullParametersShouldBeHandledWithoutBarfing() {
|
||||
result = MessageFormatter.format("Value is {}.", null).getMessage();
|
||||
assertEquals("Value is null.", result);
|
||||
|
||||
result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, null)
|
||||
.getMessage();
|
||||
assertEquals("Val1 is null, val2 is null.", result);
|
||||
|
||||
result = MessageFormatter.format("Val1 is {}, val2 is {}.", i1, null)
|
||||
.getMessage();
|
||||
assertEquals("Val1 is 1, val2 is null.", result);
|
||||
|
||||
result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, i2)
|
||||
.getMessage();
|
||||
assertEquals("Val1 is null, val2 is 2.", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}",
|
||||
new Integer[] { null, null, null }).getMessage();
|
||||
assertEquals("Val1 is null, val2 is null, val3 is null", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}",
|
||||
new Integer[] { null, i2, i3 }).getMessage();
|
||||
assertEquals("Val1 is null, val2 is 2, val3 is 3", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}",
|
||||
new Integer[] { null, null, i3 }).getMessage();
|
||||
assertEquals("Val1 is null, val2 is null, val3 is 3", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyOneParameterIsHandledCorrectly() {
|
||||
result = MessageFormatter.format("Value is {}.", i3).getMessage();
|
||||
assertEquals("Value is 3.", result);
|
||||
|
||||
result = MessageFormatter.format("Value is {", i3).getMessage();
|
||||
assertEquals("Value is {", result);
|
||||
|
||||
result = MessageFormatter.format("{} is larger than 2.", i3).getMessage();
|
||||
assertEquals("3 is larger than 2.", result);
|
||||
|
||||
result = MessageFormatter.format("No subst", i3).getMessage();
|
||||
assertEquals("No subst", result);
|
||||
|
||||
result = MessageFormatter.format("Incorrect {subst", i3).getMessage();
|
||||
assertEquals("Incorrect {subst", result);
|
||||
|
||||
result = MessageFormatter.format("Value is {bla} {}", i3).getMessage();
|
||||
assertEquals("Value is {bla} 3", result);
|
||||
|
||||
result = MessageFormatter.format("Escaped \\{} subst", i3).getMessage();
|
||||
assertEquals("Escaped {} subst", result);
|
||||
|
||||
result = MessageFormatter.format("{Escaped", i3).getMessage();
|
||||
assertEquals("{Escaped", result);
|
||||
|
||||
result = MessageFormatter.format("\\{}Escaped", i3).getMessage();
|
||||
assertEquals("{}Escaped", result);
|
||||
|
||||
result = MessageFormatter.format("File name is {{}}.", "App folder.zip")
|
||||
.getMessage();
|
||||
assertEquals("File name is {App folder.zip}.", result);
|
||||
|
||||
// escaping the escape character
|
||||
result = MessageFormatter
|
||||
.format("File name is C:\\\\{}.", "App folder.zip").getMessage();
|
||||
assertEquals("File name is C:\\App folder.zip.", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoParameters() {
|
||||
result = MessageFormatter.format("Value {} is smaller than {}.", i1, i2)
|
||||
.getMessage();
|
||||
assertEquals("Value 1 is smaller than 2.", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than {}", i1, i2)
|
||||
.getMessage();
|
||||
assertEquals("Value 1 is smaller than 2", result);
|
||||
|
||||
result = MessageFormatter.format("{}{}", i1, i2).getMessage();
|
||||
assertEquals("12", result);
|
||||
|
||||
result = MessageFormatter.format("Val1={}, Val2={", i1, i2).getMessage();
|
||||
assertEquals("Val1=1, Val2={", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than \\{}", i1, i2)
|
||||
.getMessage();
|
||||
assertEquals("Value 1 is smaller than {}", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than \\{} tail", i1,
|
||||
i2).getMessage();
|
||||
assertEquals("Value 1 is smaller than {} tail", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than \\{", i1, i2)
|
||||
.getMessage();
|
||||
assertEquals("Value 1 is smaller than \\{", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than {tail", i1, i2)
|
||||
.getMessage();
|
||||
assertEquals("Value 1 is smaller than {tail", result);
|
||||
|
||||
result = MessageFormatter.format("Value \\{} is smaller than {}", i1, i2)
|
||||
.getMessage();
|
||||
assertEquals("Value {} is smaller than 1", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionIn_toString() {
|
||||
Object o = new Object() {
|
||||
public String toString() {
|
||||
throw new IllegalStateException("a");
|
||||
}
|
||||
};
|
||||
result = MessageFormatter.format("Troublesome object {}", o).getMessage();
|
||||
assertEquals("Troublesome object [FAILED toString()]", result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullArray() {
|
||||
String msg0 = "msg0";
|
||||
String msg1 = "msg1 {}";
|
||||
String msg2 = "msg2 {} {}";
|
||||
String msg3 = "msg3 {} {} {}";
|
||||
|
||||
Object[] args = null;
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg0, args).getMessage();
|
||||
assertEquals(msg0, result);
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg1, args).getMessage();
|
||||
assertEquals(msg1, result);
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg2, args).getMessage();
|
||||
assertEquals(msg2, result);
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg3, args).getMessage();
|
||||
assertEquals(msg3, result);
|
||||
}
|
||||
|
||||
// tests the case when the parameters are supplied in a single array
|
||||
@Test
|
||||
public void testArrayFormat() {
|
||||
result = MessageFormatter.arrayFormat(
|
||||
"Value {} is smaller than {} and {}.", ia0).getMessage();
|
||||
assertEquals("Value 1 is smaller than 2 and 3.", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("{}{}{}", ia0).getMessage();
|
||||
assertEquals("123", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Value {} is smaller than {}.", ia0)
|
||||
.getMessage();
|
||||
assertEquals("Value 1 is smaller than 2.", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Value {} is smaller than {}", ia0)
|
||||
.getMessage();
|
||||
assertEquals("Value 1 is smaller than 2", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0)
|
||||
.getMessage();
|
||||
assertEquals("Val=1, {, Val=2", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0)
|
||||
.getMessage();
|
||||
assertEquals("Val=1, {, Val=2", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1={}, Val2={", ia0).getMessage();
|
||||
assertEquals("Val1=1, Val2={", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayValues() {
|
||||
Integer p0 = i1;
|
||||
Integer[] p1 = new Integer[] { i2, i3 };
|
||||
|
||||
result = MessageFormatter.format("{}{}", p0, p1).getMessage();
|
||||
assertEquals("1[2, 3]", result);
|
||||
|
||||
// Integer[]
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", p1 })
|
||||
.getMessage();
|
||||
assertEquals("a[2, 3]", result);
|
||||
|
||||
// byte[]
|
||||
result = MessageFormatter.arrayFormat("{}{}",
|
||||
new Object[] { "a", new byte[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1, 2]", result);
|
||||
|
||||
// int[]
|
||||
result = MessageFormatter.arrayFormat("{}{}",
|
||||
new Object[] { "a", new int[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1, 2]", result);
|
||||
|
||||
// float[]
|
||||
result = MessageFormatter.arrayFormat("{}{}",
|
||||
new Object[] { "a", new float[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1.0, 2.0]", result);
|
||||
|
||||
// double[]
|
||||
result = MessageFormatter.arrayFormat("{}{}",
|
||||
new Object[] { "a", new double[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1.0, 2.0]", result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiDimensionalArrayValues() {
|
||||
Integer[][] multiIntegerA = new Integer[][] { ia0, ia1 };
|
||||
result = MessageFormatter.arrayFormat("{}{}",
|
||||
new Object[] { "a", multiIntegerA }).getMessage();
|
||||
assertEquals("a[[1, 2, 3], [10, 20, 30]]", result);
|
||||
|
||||
int[][] multiIntA = new int[][] { { 1, 2 }, { 10, 20 } };
|
||||
result = MessageFormatter.arrayFormat("{}{}",
|
||||
new Object[] { "a", multiIntA }).getMessage();
|
||||
assertEquals("a[[1, 2], [10, 20]]", result);
|
||||
|
||||
float[][] multiFloatA = new float[][] { { 1, 2 }, { 10, 20 } };
|
||||
result = MessageFormatter.arrayFormat("{}{}",
|
||||
new Object[] { "a", multiFloatA }).getMessage();
|
||||
assertEquals("a[[1.0, 2.0], [10.0, 20.0]]", result);
|
||||
|
||||
Object[][] multiOA = new Object[][] { ia0, ia1 };
|
||||
result = MessageFormatter
|
||||
.arrayFormat("{}{}", new Object[] { "a", multiOA }).getMessage();
|
||||
assertEquals("a[[1, 2, 3], [10, 20, 30]]", result);
|
||||
|
||||
Object[][][] _3DOA = new Object[][][] { multiOA, multiOA };
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", _3DOA })
|
||||
.getMessage();
|
||||
assertEquals("a[[[1, 2, 3], [10, 20, 30]], [[1, 2, 3], [10, 20, 30]]]",
|
||||
result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCyclicArrays() {
|
||||
{
|
||||
Object[] cyclicA = new Object[1];
|
||||
cyclicA[0] = cyclicA;
|
||||
assertEquals("[[...]]", MessageFormatter.arrayFormat("{}", cyclicA)
|
||||
.getMessage());
|
||||
@Test
|
||||
public void testNull() {
|
||||
result = MessageFormatter.format(null, i1).getMessage();
|
||||
assertEquals(null, result);
|
||||
}
|
||||
{
|
||||
Object[] a = new Object[2];
|
||||
a[0] = i1;
|
||||
Object[] c = new Object[] { i3, a };
|
||||
Object[] b = new Object[] { i2, c };
|
||||
a[1] = b;
|
||||
assertEquals("1[2, [3, [1, [...]]]]", MessageFormatter.arrayFormat(
|
||||
"{}{}", a).getMessage());
|
||||
|
||||
@Test
|
||||
public void nullParametersShouldBeHandledWithoutBarfing() {
|
||||
result = MessageFormatter.format("Value is {}.", null).getMessage();
|
||||
assertEquals("Value is null.", result);
|
||||
|
||||
result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, null).getMessage();
|
||||
assertEquals("Val1 is null, val2 is null.", result);
|
||||
|
||||
result = MessageFormatter.format("Val1 is {}, val2 is {}.", i1, null).getMessage();
|
||||
assertEquals("Val1 is 1, val2 is null.", result);
|
||||
|
||||
result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, i2).getMessage();
|
||||
assertEquals("Val1 is null, val2 is 2.", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}", new Integer[] { null, null, null }).getMessage();
|
||||
assertEquals("Val1 is null, val2 is null, val3 is null", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}", new Integer[] { null, i2, i3 }).getMessage();
|
||||
assertEquals("Val1 is null, val2 is 2, val3 is 3", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}", new Integer[] { null, null, i3 }).getMessage();
|
||||
assertEquals("Val1 is null, val2 is null, val3 is 3", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayThrowable() {
|
||||
FormattingTuple ft;
|
||||
Throwable t = new Throwable();
|
||||
Object[] ia = new Object[] { i1, i2, i3, t };
|
||||
Object[] iaWitness = new Object[] { i1, i2, i3 };
|
||||
@Test
|
||||
public void verifyOneParameterIsHandledCorrectly() {
|
||||
result = MessageFormatter.format("Value is {}.", i3).getMessage();
|
||||
assertEquals("Value is 3.", result);
|
||||
|
||||
ft = MessageFormatter
|
||||
.arrayFormat("Value {} is smaller than {} and {}.", ia);
|
||||
assertEquals("Value 1 is smaller than 2 and 3.", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
result = MessageFormatter.format("Value is {", i3).getMessage();
|
||||
assertEquals("Value is {", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat("{}{}{}", ia);
|
||||
assertEquals("123", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
result = MessageFormatter.format("{} is larger than 2.", i3).getMessage();
|
||||
assertEquals("3 is larger than 2.", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Value {} is smaller than {}.", ia);
|
||||
assertEquals("Value 1 is smaller than 2.", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
result = MessageFormatter.format("No subst", i3).getMessage();
|
||||
assertEquals("No subst", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Value {} is smaller than {}", ia);
|
||||
assertEquals("Value 1 is smaller than 2", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
result = MessageFormatter.format("Incorrect {subst", i3).getMessage();
|
||||
assertEquals("Incorrect {subst", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia);
|
||||
assertEquals("Val=1, {, Val=2", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
result = MessageFormatter.format("Value is {bla} {}", i3).getMessage();
|
||||
assertEquals("Value is {bla} 3", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Val={}, \\{, Val={}", ia);
|
||||
assertEquals("Val=1, \\{, Val=2", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
result = MessageFormatter.format("Escaped \\{} subst", i3).getMessage();
|
||||
assertEquals("Escaped {} subst", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Val1={}, Val2={", ia);
|
||||
assertEquals("Val1=1, Val2={", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
result = MessageFormatter.format("{Escaped", i3).getMessage();
|
||||
assertEquals("{Escaped", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat(
|
||||
"Value {} is smaller than {} and {} -- {} .", ia);
|
||||
assertEquals("Value 1 is smaller than 2 and 3 -- " + t.toString() + " .",
|
||||
ft.getMessage());
|
||||
assertTrue(Arrays.equals(ia, ft.getArgArray()));
|
||||
assertNull(ft.getThrowable());
|
||||
result = MessageFormatter.format("\\{}Escaped", i3).getMessage();
|
||||
assertEquals("{}Escaped", result);
|
||||
|
||||
ft = MessageFormatter.arrayFormat("{}{}{}{}", ia);
|
||||
assertEquals("123" + t.toString(), ft.getMessage());
|
||||
assertTrue(Arrays.equals(ia, ft.getArgArray()));
|
||||
assertNull(ft.getThrowable());
|
||||
}
|
||||
result = MessageFormatter.format("File name is {{}}.", "App folder.zip").getMessage();
|
||||
assertEquals("File name is {App folder.zip}.", result);
|
||||
|
||||
// escaping the escape character
|
||||
result = MessageFormatter.format("File name is C:\\\\{}.", "App folder.zip").getMessage();
|
||||
assertEquals("File name is C:\\App folder.zip.", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoParameters() {
|
||||
result = MessageFormatter.format("Value {} is smaller than {}.", i1, i2).getMessage();
|
||||
assertEquals("Value 1 is smaller than 2.", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than {}", i1, i2).getMessage();
|
||||
assertEquals("Value 1 is smaller than 2", result);
|
||||
|
||||
result = MessageFormatter.format("{}{}", i1, i2).getMessage();
|
||||
assertEquals("12", result);
|
||||
|
||||
result = MessageFormatter.format("Val1={}, Val2={", i1, i2).getMessage();
|
||||
assertEquals("Val1=1, Val2={", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than \\{}", i1, i2).getMessage();
|
||||
assertEquals("Value 1 is smaller than {}", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than \\{} tail", i1, i2).getMessage();
|
||||
assertEquals("Value 1 is smaller than {} tail", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than \\{", i1, i2).getMessage();
|
||||
assertEquals("Value 1 is smaller than \\{", result);
|
||||
|
||||
result = MessageFormatter.format("Value {} is smaller than {tail", i1, i2).getMessage();
|
||||
assertEquals("Value 1 is smaller than {tail", result);
|
||||
|
||||
result = MessageFormatter.format("Value \\{} is smaller than {}", i1, i2).getMessage();
|
||||
assertEquals("Value {} is smaller than 1", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionIn_toString() {
|
||||
Object o = new Object() {
|
||||
public String toString() {
|
||||
throw new IllegalStateException("a");
|
||||
}
|
||||
};
|
||||
result = MessageFormatter.format("Troublesome object {}", o).getMessage();
|
||||
assertEquals("Troublesome object [FAILED toString()]", result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullArray() {
|
||||
String msg0 = "msg0";
|
||||
String msg1 = "msg1 {}";
|
||||
String msg2 = "msg2 {} {}";
|
||||
String msg3 = "msg3 {} {} {}";
|
||||
|
||||
Object[] args = null;
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg0, args).getMessage();
|
||||
assertEquals(msg0, result);
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg1, args).getMessage();
|
||||
assertEquals(msg1, result);
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg2, args).getMessage();
|
||||
assertEquals(msg2, result);
|
||||
|
||||
result = MessageFormatter.arrayFormat(msg3, args).getMessage();
|
||||
assertEquals(msg3, result);
|
||||
}
|
||||
|
||||
// tests the case when the parameters are supplied in a single array
|
||||
@Test
|
||||
public void testArrayFormat() {
|
||||
result = MessageFormatter.arrayFormat("Value {} is smaller than {} and {}.", ia0).getMessage();
|
||||
assertEquals("Value 1 is smaller than 2 and 3.", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("{}{}{}", ia0).getMessage();
|
||||
assertEquals("123", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Value {} is smaller than {}.", ia0).getMessage();
|
||||
assertEquals("Value 1 is smaller than 2.", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Value {} is smaller than {}", ia0).getMessage();
|
||||
assertEquals("Value 1 is smaller than 2", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0).getMessage();
|
||||
assertEquals("Val=1, {, Val=2", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia0).getMessage();
|
||||
assertEquals("Val=1, {, Val=2", result);
|
||||
|
||||
result = MessageFormatter.arrayFormat("Val1={}, Val2={", ia0).getMessage();
|
||||
assertEquals("Val1=1, Val2={", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayValues() {
|
||||
Integer p0 = i1;
|
||||
Integer[] p1 = new Integer[] { i2, i3 };
|
||||
|
||||
result = MessageFormatter.format("{}{}", p0, p1).getMessage();
|
||||
assertEquals("1[2, 3]", result);
|
||||
|
||||
// Integer[]
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", p1 }).getMessage();
|
||||
assertEquals("a[2, 3]", result);
|
||||
|
||||
// byte[]
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", new byte[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1, 2]", result);
|
||||
|
||||
// int[]
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", new int[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1, 2]", result);
|
||||
|
||||
// float[]
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", new float[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1.0, 2.0]", result);
|
||||
|
||||
// double[]
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", new double[] { 1, 2 } }).getMessage();
|
||||
assertEquals("a[1.0, 2.0]", result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiDimensionalArrayValues() {
|
||||
Integer[][] multiIntegerA = new Integer[][] { ia0, ia1 };
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", multiIntegerA }).getMessage();
|
||||
assertEquals("a[[1, 2, 3], [10, 20, 30]]", result);
|
||||
|
||||
int[][] multiIntA = new int[][] { { 1, 2 }, { 10, 20 } };
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", multiIntA }).getMessage();
|
||||
assertEquals("a[[1, 2], [10, 20]]", result);
|
||||
|
||||
float[][] multiFloatA = new float[][] { { 1, 2 }, { 10, 20 } };
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", multiFloatA }).getMessage();
|
||||
assertEquals("a[[1.0, 2.0], [10.0, 20.0]]", result);
|
||||
|
||||
Object[][] multiOA = new Object[][] { ia0, ia1 };
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", multiOA }).getMessage();
|
||||
assertEquals("a[[1, 2, 3], [10, 20, 30]]", result);
|
||||
|
||||
Object[][][] _3DOA = new Object[][][] { multiOA, multiOA };
|
||||
result = MessageFormatter.arrayFormat("{}{}", new Object[] { "a", _3DOA }).getMessage();
|
||||
assertEquals("a[[[1, 2, 3], [10, 20, 30]], [[1, 2, 3], [10, 20, 30]]]", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCyclicArrays() {
|
||||
{
|
||||
Object[] cyclicA = new Object[1];
|
||||
cyclicA[0] = cyclicA;
|
||||
assertEquals("[[...]]", MessageFormatter.arrayFormat("{}", cyclicA).getMessage());
|
||||
}
|
||||
{
|
||||
Object[] a = new Object[2];
|
||||
a[0] = i1;
|
||||
Object[] c = new Object[] { i3, a };
|
||||
Object[] b = new Object[] { i2, c };
|
||||
a[1] = b;
|
||||
assertEquals("1[2, [3, [1, [...]]]]", MessageFormatter.arrayFormat("{}{}", a).getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayThrowable() {
|
||||
FormattingTuple ft;
|
||||
Throwable t = new Throwable();
|
||||
Object[] ia = new Object[] { i1, i2, i3, t };
|
||||
Object[] iaWitness = new Object[] { i1, i2, i3 };
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Value {} is smaller than {} and {}.", ia);
|
||||
assertEquals("Value 1 is smaller than 2 and 3.", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("{}{}{}", ia);
|
||||
assertEquals("123", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Value {} is smaller than {}.", ia);
|
||||
assertEquals("Value 1 is smaller than 2.", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Value {} is smaller than {}", ia);
|
||||
assertEquals("Value 1 is smaller than 2", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia);
|
||||
assertEquals("Val=1, {, Val=2", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Val={}, \\{, Val={}", ia);
|
||||
assertEquals("Val=1, \\{, Val=2", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Val1={}, Val2={", ia);
|
||||
assertEquals("Val1=1, Val2={", ft.getMessage());
|
||||
assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
|
||||
assertEquals(t, ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("Value {} is smaller than {} and {} -- {} .", ia);
|
||||
assertEquals("Value 1 is smaller than 2 and 3 -- " + t.toString() + " .", ft.getMessage());
|
||||
assertTrue(Arrays.equals(ia, ft.getArgArray()));
|
||||
assertNull(ft.getThrowable());
|
||||
|
||||
ft = MessageFormatter.arrayFormat("{}{}{}{}", ia);
|
||||
assertEquals("123" + t.toString(), ft.getMessage());
|
||||
assertTrue(Arrays.equals(ia, ft.getArgArray()));
|
||||
assertNull(ft.getThrowable());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,31 +24,28 @@
|
|||
*/
|
||||
package org.slf4j.helpers;
|
||||
|
||||
class MyRandom {
|
||||
|
||||
class MyRandom {
|
||||
private final static long m = 200000000041L; // a prime number
|
||||
private final static long a = 2000000011L; // a prime number
|
||||
|
||||
private final static long m = 200000000041L; // a prime number
|
||||
private final static long a = 2000000011L; // a prime number
|
||||
long y;
|
||||
long unused;
|
||||
int bits = 32;
|
||||
|
||||
long y;
|
||||
long unused;
|
||||
int bits = 32;
|
||||
public MyRandom() {
|
||||
this(System.nanoTime());
|
||||
}
|
||||
|
||||
public MyRandom() {
|
||||
this(System.nanoTime());
|
||||
}
|
||||
public MyRandom(long seed) {
|
||||
this.y = seed;
|
||||
}
|
||||
|
||||
|
||||
public MyRandom(long seed) {
|
||||
this.y = seed;
|
||||
}
|
||||
|
||||
|
||||
int nextInt() {
|
||||
// we don't really care about the randomness of this
|
||||
// generator
|
||||
y = (a*y + 1) % m;
|
||||
unused = y >>> (48-bits); // just exercise the >>> operator
|
||||
return (int)(y);
|
||||
}
|
||||
int nextInt() {
|
||||
// we don't really care about the randomness of this
|
||||
// generator
|
||||
y = (a * y + 1) % m;
|
||||
unused = y >>> (48 - bits); // just exercise the >>> operator
|
||||
return (int) (y);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,67 +41,66 @@ import org.slf4j.Logger;
|
|||
* @author Chetan Mehrotra
|
||||
*/
|
||||
public class SubstitutableLoggerTest extends TestCase {
|
||||
private static final Set<String> EXCLUDED_METHODS = new HashSet<String>(Arrays.asList("getName"));
|
||||
private static final Set<String> EXCLUDED_METHODS = new HashSet<String>(Arrays.asList("getName"));
|
||||
|
||||
public void testDelegate() throws Exception {
|
||||
SubstituteLogger log = new SubstituteLogger("foo");
|
||||
assertTrue(log.delegate() instanceof NOPLogger);
|
||||
public void testDelegate() throws Exception {
|
||||
SubstituteLogger log = new SubstituteLogger("foo");
|
||||
assertTrue(log.delegate() instanceof NOPLogger);
|
||||
|
||||
Set<String> expectedMethodSignatures = determineMethodSignatures(Logger.class);
|
||||
LoggerInvocationHandler ih = new LoggerInvocationHandler();
|
||||
Logger proxyLogger = (Logger) Proxy.newProxyInstance(getClass().getClassLoader(),
|
||||
new Class[]{Logger.class}, ih);
|
||||
log.setDelegate(proxyLogger);
|
||||
Set<String> expectedMethodSignatures = determineMethodSignatures(Logger.class);
|
||||
LoggerInvocationHandler ih = new LoggerInvocationHandler();
|
||||
Logger proxyLogger = (Logger) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Logger.class }, ih);
|
||||
log.setDelegate(proxyLogger);
|
||||
|
||||
invokeMethods(log);
|
||||
invokeMethods(log);
|
||||
|
||||
//Assert that all methods are delegated
|
||||
expectedMethodSignatures.removeAll(ih.getInvokedMethodSignatures());
|
||||
if (!expectedMethodSignatures.isEmpty()) {
|
||||
fail("Following methods are not delegated " + expectedMethodSignatures.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeMethods(Logger proxyLogger) throws InvocationTargetException, IllegalAccessException {
|
||||
for (Method m : Logger.class.getDeclaredMethods()) {
|
||||
if (!EXCLUDED_METHODS.contains(m.getName())) {
|
||||
m.invoke(proxyLogger, new Object[m.getParameterTypes().length]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class LoggerInvocationHandler implements InvocationHandler {
|
||||
private final Set<String> invokedMethodSignatures = new HashSet<String>();
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
invokedMethodSignatures.add(getMethodSignature(method));
|
||||
if (method.getName().startsWith("is")) {
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
// Assert that all methods are delegated
|
||||
expectedMethodSignatures.removeAll(ih.getInvokedMethodSignatures());
|
||||
if (!expectedMethodSignatures.isEmpty()) {
|
||||
fail("Following methods are not delegated " + expectedMethodSignatures.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getInvokedMethodSignatures() {
|
||||
return invokedMethodSignatures;
|
||||
private void invokeMethods(Logger proxyLogger) throws InvocationTargetException, IllegalAccessException {
|
||||
for (Method m : Logger.class.getDeclaredMethods()) {
|
||||
if (!EXCLUDED_METHODS.contains(m.getName())) {
|
||||
m.invoke(proxyLogger, new Object[m.getParameterTypes().length]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<String> determineMethodSignatures(Class<Logger> loggerClass) {
|
||||
Set<String> methodSignatures = new HashSet<String>();
|
||||
for (Method m : loggerClass.getDeclaredMethods()) {
|
||||
if (!EXCLUDED_METHODS.contains(m.getName())) {
|
||||
methodSignatures.add(getMethodSignature(m));
|
||||
}
|
||||
}
|
||||
return methodSignatures;
|
||||
}
|
||||
private class LoggerInvocationHandler implements InvocationHandler {
|
||||
private final Set<String> invokedMethodSignatures = new HashSet<String>();
|
||||
|
||||
private static String getMethodSignature(Method m) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
result.add(m.getName());
|
||||
for (Class<?> clazz : m.getParameterTypes()) {
|
||||
result.add(clazz.getSimpleName());
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
invokedMethodSignatures.add(getMethodSignature(method));
|
||||
if (method.getName().startsWith("is")) {
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Set<String> getInvokedMethodSignatures() {
|
||||
return invokedMethodSignatures;
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<String> determineMethodSignatures(Class<Logger> loggerClass) {
|
||||
Set<String> methodSignatures = new HashSet<String>();
|
||||
for (Method m : loggerClass.getDeclaredMethods()) {
|
||||
if (!EXCLUDED_METHODS.contains(m.getName())) {
|
||||
methodSignatures.add(getMethodSignature(m));
|
||||
}
|
||||
}
|
||||
return methodSignatures;
|
||||
}
|
||||
|
||||
private static String getMethodSignature(Method m) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
result.add(m.getName());
|
||||
for (Class<?> clazz : m.getParameterTypes()) {
|
||||
result.add(clazz.getSimpleName());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,39 +31,39 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SubstituteLoggerFactoryTest extends TestCase{
|
||||
private SubstituteLoggerFactory factory = new SubstituteLoggerFactory();
|
||||
public class SubstituteLoggerFactoryTest extends TestCase {
|
||||
private SubstituteLoggerFactory factory = new SubstituteLoggerFactory();
|
||||
|
||||
public void testFactory() {
|
||||
Logger log = factory.getLogger("foo");
|
||||
assertNotNull(log);
|
||||
public void testFactory() {
|
||||
Logger log = factory.getLogger("foo");
|
||||
assertNotNull(log);
|
||||
|
||||
Logger log2 = factory.getLogger("foo");
|
||||
assertTrue("Loggers with same name must be same",log == log2);
|
||||
}
|
||||
|
||||
public void testLoggerNameList() {
|
||||
factory.getLogger("foo1");
|
||||
factory.getLogger("foo2");
|
||||
|
||||
Set<String> expectedNames = new HashSet<String>(Arrays.asList("foo1","foo2"));
|
||||
Set<String> actualNames = new HashSet<String>(factory.getLoggerNames());
|
||||
|
||||
assertEquals(expectedNames, actualNames);
|
||||
}
|
||||
|
||||
public void testLoggers() {
|
||||
factory.getLogger("foo1");
|
||||
factory.getLogger("foo2");
|
||||
|
||||
Set<String> expectedNames = new HashSet<String>(Arrays.asList("foo1","foo2"));
|
||||
|
||||
Set<String> actualNames = new HashSet<String>();
|
||||
for(SubstituteLogger slog : factory.getLoggers()){
|
||||
actualNames.add(slog.getName());
|
||||
Logger log2 = factory.getLogger("foo");
|
||||
assertTrue("Loggers with same name must be same", log == log2);
|
||||
}
|
||||
|
||||
assertEquals(expectedNames, actualNames);
|
||||
}
|
||||
public void testLoggerNameList() {
|
||||
factory.getLogger("foo1");
|
||||
factory.getLogger("foo2");
|
||||
|
||||
Set<String> expectedNames = new HashSet<String>(Arrays.asList("foo1", "foo2"));
|
||||
Set<String> actualNames = new HashSet<String>(factory.getLoggerNames());
|
||||
|
||||
assertEquals(expectedNames, actualNames);
|
||||
}
|
||||
|
||||
public void testLoggers() {
|
||||
factory.getLogger("foo1");
|
||||
factory.getLogger("foo2");
|
||||
|
||||
Set<String> expectedNames = new HashSet<String>(Arrays.asList("foo1", "foo2"));
|
||||
|
||||
Set<String> actualNames = new HashSet<String>();
|
||||
for (SubstituteLogger slog : factory.getLoggers()) {
|
||||
actualNames.add(slog.getName());
|
||||
}
|
||||
|
||||
assertEquals(expectedNames, actualNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,36 +27,36 @@ package org.slf4j;
|
|||
import org.slf4j.MDC;
|
||||
|
||||
public class NDC {
|
||||
public final static String PREFIX = "NDC";
|
||||
public final static String PREFIX = "NDC";
|
||||
|
||||
private static int size() {
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String val = MDC.get(PREFIX + i);
|
||||
if (val != null) {
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
private static int size() {
|
||||
int i = 0;
|
||||
while (true) {
|
||||
String val = MDC.get(PREFIX + i);
|
||||
if (val != null) {
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static void push(String val) {
|
||||
int next = size();
|
||||
MDC.put(PREFIX + next, val);
|
||||
}
|
||||
|
||||
public static String pop() {
|
||||
int next = size();
|
||||
if(next == 0) {
|
||||
return "";
|
||||
public static void push(String val) {
|
||||
int next = size();
|
||||
MDC.put(PREFIX + next, val);
|
||||
}
|
||||
|
||||
public static String pop() {
|
||||
int next = size();
|
||||
if (next == 0) {
|
||||
return "";
|
||||
}
|
||||
int last = next - 1;
|
||||
String key = PREFIX + last;
|
||||
String val = MDC.get(key);
|
||||
MDC.remove(key);
|
||||
return val;
|
||||
}
|
||||
int last = next-1;
|
||||
String key = PREFIX+last;
|
||||
String val = MDC.get(key);
|
||||
MDC.remove(key);
|
||||
return val;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,27 +37,27 @@ package org.slf4j.agent;
|
|||
*/
|
||||
public class AgentOptions {
|
||||
|
||||
/**
|
||||
* List of class prefixes to ignore when instrumenting. Note: Classes loaded
|
||||
* before the agent cannot be instrumented.
|
||||
*/
|
||||
public static final String IGNORE = "ignore";
|
||||
/**
|
||||
* Indicate the SLF4J level that should be used by the logging statements
|
||||
* added by the agent. Default is "info".
|
||||
*/
|
||||
public static final String LEVEL = "level";
|
||||
/**
|
||||
* Indicate that the agent should print out "new java.util.Date()" at the time
|
||||
* the option was processed and at shutdown time (using the shutdown hook).
|
||||
*
|
||||
*/
|
||||
public static final String TIME = "time";
|
||||
/**
|
||||
* Indicate that the agent should log actions to System.err, like adding
|
||||
* logging to methods, etc.
|
||||
*
|
||||
*/
|
||||
public static final String VERBOSE = "verbose";
|
||||
/**
|
||||
* List of class prefixes to ignore when instrumenting. Note: Classes loaded
|
||||
* before the agent cannot be instrumented.
|
||||
*/
|
||||
public static final String IGNORE = "ignore";
|
||||
/**
|
||||
* Indicate the SLF4J level that should be used by the logging statements
|
||||
* added by the agent. Default is "info".
|
||||
*/
|
||||
public static final String LEVEL = "level";
|
||||
/**
|
||||
* Indicate that the agent should print out "new java.util.Date()" at the time
|
||||
* the option was processed and at shutdown time (using the shutdown hook).
|
||||
*
|
||||
*/
|
||||
public static final String TIME = "time";
|
||||
/**
|
||||
* Indicate that the agent should log actions to System.err, like adding
|
||||
* logging to methods, etc.
|
||||
*
|
||||
*/
|
||||
public static final String VERBOSE = "verbose";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,94 +38,91 @@ import org.slf4j.instrumentation.LogTransformer;
|
|||
*/
|
||||
public class AgentPremain {
|
||||
|
||||
/**
|
||||
* JavaAgent premain entry point as specified in the MANIFEST.MF file. See
|
||||
* {@link http
|
||||
* ://java.sun.com/javase/6/docs/api/java/lang/instrument/package-
|
||||
* summary.html} for details.
|
||||
*
|
||||
* @param agentArgument
|
||||
* string provided after "=" up to first space
|
||||
* @param instrumentation
|
||||
* instrumentation environment provided by the JVM
|
||||
*/
|
||||
public static void premain(String agentArgument,
|
||||
Instrumentation instrumentation) {
|
||||
/**
|
||||
* JavaAgent premain entry point as specified in the MANIFEST.MF file. See
|
||||
* {@link http
|
||||
* ://java.sun.com/javase/6/docs/api/java/lang/instrument/package-
|
||||
* summary.html} for details.
|
||||
*
|
||||
* @param agentArgument
|
||||
* string provided after "=" up to first space
|
||||
* @param instrumentation
|
||||
* instrumentation environment provided by the JVM
|
||||
*/
|
||||
public static void premain(String agentArgument, Instrumentation instrumentation) {
|
||||
|
||||
// We cannot do sanity checks for slf4j here as the jars loaded
|
||||
// by the application are not visible here.
|
||||
// We cannot do sanity checks for slf4j here as the jars loaded
|
||||
// by the application are not visible here.
|
||||
|
||||
LogTransformer.Builder builder = new LogTransformer.Builder();
|
||||
builder = builder.addEntryExit(true);
|
||||
LogTransformer.Builder builder = new LogTransformer.Builder();
|
||||
builder = builder.addEntryExit(true);
|
||||
|
||||
if (agentArgument != null) {
|
||||
Properties args = parseArguments(agentArgument, ",");
|
||||
if (agentArgument != null) {
|
||||
Properties args = parseArguments(agentArgument, ",");
|
||||
|
||||
if (args.containsKey(AgentOptions.VERBOSE)) {
|
||||
builder = builder.verbose(true);
|
||||
}
|
||||
if (args.containsKey(AgentOptions.VERBOSE)) {
|
||||
builder = builder.verbose(true);
|
||||
}
|
||||
|
||||
if (args.containsKey(AgentOptions.TIME)) {
|
||||
printStartStopTimes();
|
||||
}
|
||||
if (args.containsKey(AgentOptions.TIME)) {
|
||||
printStartStopTimes();
|
||||
}
|
||||
|
||||
if (args.containsKey(AgentOptions.IGNORE)) {
|
||||
String ignore = args.getProperty(AgentOptions.IGNORE);
|
||||
builder = builder.ignore(ignore.split(":"));
|
||||
}
|
||||
if (args.containsKey(AgentOptions.IGNORE)) {
|
||||
String ignore = args.getProperty(AgentOptions.IGNORE);
|
||||
builder = builder.ignore(ignore.split(":"));
|
||||
}
|
||||
|
||||
if (args.containsKey(AgentOptions.LEVEL)) {
|
||||
builder = builder.level(args.getProperty(AgentOptions.LEVEL));
|
||||
}
|
||||
}
|
||||
if (args.containsKey(AgentOptions.LEVEL)) {
|
||||
builder = builder.level(args.getProperty(AgentOptions.LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
instrumentation.addTransformer(builder.build());
|
||||
}
|
||||
instrumentation.addTransformer(builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Consider the argument string to be a property file (by converting the
|
||||
* splitter character to line feeds), and then reading it like any other
|
||||
* property file.
|
||||
*
|
||||
*
|
||||
* @param agentArgument
|
||||
* string given by instrumentation framework
|
||||
* @param separator
|
||||
* String to convert to line feeds
|
||||
* @return argument converted to properties
|
||||
*/
|
||||
private static Properties parseArguments(String agentArgument,
|
||||
String separator) {
|
||||
Properties p = new Properties();
|
||||
try {
|
||||
String argumentAsLines = agentArgument.replaceAll(separator, "\n");
|
||||
p.load(new ByteArrayInputStream(argumentAsLines.getBytes()));
|
||||
} catch (IOException e) {
|
||||
String s = "Could not load arguments as properties";
|
||||
throw new RuntimeException(s, e);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
/**
|
||||
* Consider the argument string to be a property file (by converting the
|
||||
* splitter character to line feeds), and then reading it like any other
|
||||
* property file.
|
||||
*
|
||||
*
|
||||
* @param agentArgument
|
||||
* string given by instrumentation framework
|
||||
* @param separator
|
||||
* String to convert to line feeds
|
||||
* @return argument converted to properties
|
||||
*/
|
||||
private static Properties parseArguments(String agentArgument, String separator) {
|
||||
Properties p = new Properties();
|
||||
try {
|
||||
String argumentAsLines = agentArgument.replaceAll(separator, "\n");
|
||||
p.load(new ByteArrayInputStream(argumentAsLines.getBytes()));
|
||||
} catch (IOException e) {
|
||||
String s = "Could not load arguments as properties";
|
||||
throw new RuntimeException(s, e);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the start message to System.err with the time NOW, and register a
|
||||
* shutdown hook which will print the stop message to System.err with the
|
||||
* time then and the number of milliseconds passed since.
|
||||
*
|
||||
*/
|
||||
private static void printStartStopTimes() {
|
||||
final long start = System.currentTimeMillis();
|
||||
/**
|
||||
* Print the start message to System.err with the time NOW, and register a
|
||||
* shutdown hook which will print the stop message to System.err with the
|
||||
* time then and the number of milliseconds passed since.
|
||||
*
|
||||
*/
|
||||
private static void printStartStopTimes() {
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
System.err.println("Start at " + new Date());
|
||||
System.err.println("Start at " + new Date());
|
||||
|
||||
Thread hook = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
long timePassed = System.currentTimeMillis() - start;
|
||||
System.err.println("Stop at " + new Date()
|
||||
+ ", execution time = " + timePassed + " ms");
|
||||
}
|
||||
};
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
}
|
||||
Thread hook = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
long timePassed = System.currentTimeMillis() - start;
|
||||
System.err.println("Stop at " + new Date() + ", execution time = " + timePassed + " ms");
|
||||
}
|
||||
};
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
}
|
||||
}
|
||||
|
|
@ -41,138 +41,133 @@ import ch.qos.cal10n.MessageParameterObj;
|
|||
*/
|
||||
public class LocLogger extends LoggerWrapper implements Logger {
|
||||
|
||||
private static final String FQCN = LocLogger.class.getName();
|
||||
private static final String FQCN = LocLogger.class.getName();
|
||||
|
||||
/**
|
||||
* Every localized message logged by a LocLogger will bear this marker. It
|
||||
* allows marker-aware implementations to perform additional processing on
|
||||
* localized messages.
|
||||
*/
|
||||
static Marker LOCALIZED = MarkerFactory.getMarker("LOCALIZED");
|
||||
/**
|
||||
* Every localized message logged by a LocLogger will bear this marker. It
|
||||
* allows marker-aware implementations to perform additional processing on
|
||||
* localized messages.
|
||||
*/
|
||||
static Marker LOCALIZED = MarkerFactory.getMarker("LOCALIZED");
|
||||
|
||||
final IMessageConveyor imc;
|
||||
final IMessageConveyor imc;
|
||||
|
||||
public LocLogger(Logger logger, IMessageConveyor imc) {
|
||||
super(logger, LoggerWrapper.class.getName());
|
||||
if (imc == null) {
|
||||
throw new IllegalArgumentException("IMessageConveyor cannot be null");
|
||||
public LocLogger(Logger logger, IMessageConveyor imc) {
|
||||
super(logger, LoggerWrapper.class.getName());
|
||||
if (imc == null) {
|
||||
throw new IllegalArgumentException("IMessageConveyor cannot be null");
|
||||
}
|
||||
this.imc = imc;
|
||||
}
|
||||
this.imc = imc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a localized message at the TRACE level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void trace(Enum<?> key, Object... args) {
|
||||
if (!logger.isTraceEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
/**
|
||||
* Log a localized message at the TRACE level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void trace(Enum<?> key, Object... args) {
|
||||
if (!logger.isTraceEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
|
||||
LocationAwareLogger.TRACE_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.trace(LOCALIZED, translatedMsg, mpo);
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.TRACE_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.trace(LOCALIZED, translatedMsg, mpo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a localized message at the DEBUG level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void debug(Enum<?> key, Object... args) {
|
||||
if (!logger.isDebugEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
/**
|
||||
* Log a localized message at the DEBUG level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void debug(Enum<?> key, Object... args) {
|
||||
if (!logger.isDebugEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
|
||||
LocationAwareLogger.DEBUG_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.debug(LOCALIZED, translatedMsg, mpo);
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.DEBUG_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.debug(LOCALIZED, translatedMsg, mpo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a localized message at the INFO level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void info(Enum<?> key, Object... args) {
|
||||
if (!logger.isInfoEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
/**
|
||||
* Log a localized message at the INFO level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void info(Enum<?> key, Object... args) {
|
||||
if (!logger.isInfoEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
|
||||
LocationAwareLogger.INFO_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.info(LOCALIZED, translatedMsg, mpo);
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.INFO_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.info(LOCALIZED, translatedMsg, mpo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a localized message at the WARN level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void warn(Enum<?> key, Object... args) {
|
||||
if (!logger.isWarnEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
/**
|
||||
* Log a localized message at the WARN level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void warn(Enum<?> key, Object... args) {
|
||||
if (!logger.isWarnEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
|
||||
LocationAwareLogger.WARN_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.warn(LOCALIZED, translatedMsg, mpo);
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.WARN_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.warn(LOCALIZED, translatedMsg, mpo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a localized message at the ERROR level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void error(Enum<?> key, Object... args) {
|
||||
if (!logger.isErrorEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
/**
|
||||
* Log a localized message at the ERROR level.
|
||||
*
|
||||
* @param key
|
||||
* the key used for localization
|
||||
* @param args
|
||||
* optional arguments
|
||||
*/
|
||||
public void error(Enum<?> key, Object... args) {
|
||||
if (!logger.isErrorEnabled()) {
|
||||
return;
|
||||
}
|
||||
String translatedMsg = imc.getMessage(key, args);
|
||||
MessageParameterObj mpo = new MessageParameterObj(key, args);
|
||||
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN,
|
||||
LocationAwareLogger.ERROR_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.error(LOCALIZED, translatedMsg, mpo);
|
||||
if (instanceofLAL) {
|
||||
((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.ERROR_INT, translatedMsg, args, null);
|
||||
} else {
|
||||
logger.error(LOCALIZED, translatedMsg, mpo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,30 +46,30 @@ import ch.qos.cal10n.IMessageConveyor;
|
|||
*/
|
||||
public class LocLoggerFactory {
|
||||
|
||||
final IMessageConveyor imc;
|
||||
final IMessageConveyor imc;
|
||||
|
||||
public LocLoggerFactory(IMessageConveyor imc) {
|
||||
this.imc = imc;
|
||||
}
|
||||
public LocLoggerFactory(IMessageConveyor imc) {
|
||||
this.imc = imc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an LocLogger instance by name.
|
||||
*
|
||||
* @param name
|
||||
* @return LocLogger instance by name.
|
||||
*/
|
||||
public LocLogger getLocLogger(String name) {
|
||||
return new LocLogger(LoggerFactory.getLogger(name), imc);
|
||||
}
|
||||
/**
|
||||
* Get an LocLogger instance by name.
|
||||
*
|
||||
* @param name
|
||||
* @return LocLogger instance by name.
|
||||
*/
|
||||
public LocLogger getLocLogger(String name) {
|
||||
return new LocLogger(LoggerFactory.getLogger(name), imc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new LocLogger instance by class. The returned LocLogger will be named
|
||||
* after the class.
|
||||
*
|
||||
* @param clazz
|
||||
* @return LocLogger instance by class
|
||||
*/
|
||||
public LocLogger getLocLogger(Class<?> clazz) {
|
||||
return getLocLogger(clazz.getName());
|
||||
}
|
||||
/**
|
||||
* Get a new LocLogger instance by class. The returned LocLogger will be named
|
||||
* after the class.
|
||||
*
|
||||
* @param clazz
|
||||
* @return LocLogger instance by class
|
||||
*/
|
||||
public LocLogger getLocLogger(Class<?> clazz) {
|
||||
return getLocLogger(clazz.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue