GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Log4j

Jerry Reeves Jr Information Technology Englisch 60 Karten

Karten in diesem Stapel (60)

  1. 1What is Log4j?Log4j is a reliable, fast, and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License.
    Log4j has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages.
    Log4j is highly configurable through external configuration files at runtime.It views the logging process in terms of levels of priorities and offers mechanisms to direct logging information to a great variety of destinations, such as a database, file, console, UNIX Syslog, etc.
  2. 2What are the components of Log4j?Log4j has three main components −
    loggers: Responsible for capturing logging information.
    appenders: Responsible for publishing logging information to various preferred destinations.
    layouts: Responsible for formatting logging information in different styles.
  3. 3What are the support objects in Log4j?Level Object
    Filter Object
    Object Renderer
    Log Manager
  4. 4What are the features of log4j?Following are features of log4j −
    It is thread-safe.
    It is optimized for speed.
    It is based on a named logger hierarchy.
    It supports multiple output appenders per logger.
    It supports internationalization.
    It is not restricted to a predefined set of facilities.
  5. 5What are Pros and Cons of Logging?A well-written logging code offers quick debugging, easy maintenance, and structured storage of an application’s runtime information.
    Logging does have its drawbacks also.It can slow down an application.If too verbose, it can cause scrolling blindness.To alleviate these concerns, log4j is designed to be reliable, fast, and extensible.
    Since logging is rarely the main focus of an application, the log4j API strives to be simple to understand and to use
  6. 6Explain why to use Apache Log4j?Being open-source its completely free to use.
    You can easily save log information into either files or even databases.
    Can be used for projects of any sizes small or large.
  7. 7What is the purpose of Logger object?The top-level layer of log4j architecture is the Logger which provides the Logger object.The Logger object is responsible for capturing logging information and they are stored in a namespace hierarchy.
  8. 8What is the purpose of Layout object?The layout of log4j architecture provides objects which are used to format logging information in different styles.It provides support to appender objects before publishing logging information.
    Layout objects play an important role in publishing logging information in a way that is human-readable and reusable.
  9. 9What is the purpose of Appender object?This is a lower-level layer of log4j architecture which provides Appender objects.The Appender object is responsible for publishing logging information to various preferred destinations such as a database, file, console, UNIX Syslog, etc.
  10. 10What is the purpose of Level object?The Level object defines the granularity and priority of any logging information.There are seven levels of logging defined within the API: OFF, DEBUG, INFO, ERROR, WARN, FATAL, and ALL.
  11. 11What is the purpose of Filter object?The Filter object is used to analyze logging information and make further decisions on whether that information should be logged or not.An Appender objects can have several Filter objects associated with them.If logging information is passed to a particular Appender object, all the Filter objects associated with that Appender need to approve the logging information before it can be published to the attached destination.
  12. 12What is the purpose of ObjectRenderer object?The ObjectRenderer object is specialized in providing a String representation of different objects passed to the logging framework.This object is used by Layout objects to prepare the final logging information.
  13. 13What is the purpose of LogManager object?The LogManager object manages the logging framework.It is responsible for reading the initial configuration parameters from a system-wide configuration file or a configuration class.
  14. 14What is the use of log4j.properties?The log4j.properties file is a log4j configuration file which keeps properties in key-value pairs.By default, the LogManager looks for a file named log4j.properties in the CLASSPATH.
  15. 15What is the purpose of layout object in Appender?Appender uses the Layout objects and the conversion pattern associated with them to format the logging information.
  16. 16What is the purpose of target in Appender?The target may be a console, a file, or another item depending on the appender.
  17. 17What is the purpose of level in Appender?The level is required to control the filtration of the log messages.
  18. 18What is the purpose of threshold in Appender?Appender can have a threshold level associated with it independent of the logger level.The Appender ignores any logging messages that have a level lower than the threshold level.
  19. 19What is the purpose of filter in Appender?The Filter objects can analyze logging information beyond level matching and decide whether logging requests should be handled by a particular Appender or ignored.
  20. 20How will you define a root logger with appender file using log4j.properties?Following syntax defines the root logger with appender file:
    //Define the root logger with appender file
    log = /usr/home/log4j
    log4j.rootLogger = DEBUG, FILE
  21. 21How will you define a file appender using log4j.properties?Following syntax defines a file appender −
    //Define the file appender
    log4j.appender.FILE=org.apache.log4j.FileAppender
    log4j.appender.FILE.File=${log}/log.out
  22. 22How will you define the layout of file appender using log4j.properties?Following syntax defines the layout of file appender −
    // Define the layout for file appender
    log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.FILE.layout.conversionPattern=%m%n
  23. 23What are the different log levels in the logger component?All
    Debug
    Info
    Warn
    Error
    Fatal
    Off
  24. 24What is purpose of DEBUG log level?DEBUG − Designates fine-grained informational events that are most useful to debug an application.
  25. 25What is purpose of ERROR log level?ERROR − Designates error events that might still allow the application to continue running.
  26. 26What is purpose of FATAL log level?FATAL − Designates very severe error events that will presumably lead the application to abort.
  27. 27What is purpose of INFO log level?INFO − Designates informational messages that highlight the progress of the application at coarse-grained level.
  28. 28What is purpose of OFF log level?OFF − The highest possible rank and is intended to turn off logging.
  29. 29What is purpose of TRACE log level?TRACE − Designates finer-grained informational events than the DEBUG.
  30. 30What is purpose of WARN log level?WARN − Designates potentially harmful situations.
  31. 31How do Levels Works?A log request of level p in a logger with level q is enabled if p >= q.This rule is at the heart of log4j.It assumes that levels are ordered.For the standard levels, we have ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF.
  32. 32How will you define a root logger turning DEBUG mode off?Following syntax defines the root logger with WARN mode turning DEBUG mode off.
    //Define the root logger with appender file
    log = /usr/home/log4j
    log4j.rootLogger = WARN, FILE
  33. 33How will you create a logger in any class?Any other named Logger object instance is obtained through the second method by passing the name of the logger.The name of the logger can be any string you can pass, usually a class or a package name
    static Logger log = Logger.getLogger(log4jExample.class.getName();
  34. 34How will you print a log message in debug mode?public void debug(Object message) of Logger class prints messages with the level Level.DEBUG.
  35. 35How will you print a log message in error mode?public void error(Object message) of Logger class prints messages with the level Level.ERROR.
  36. 36How will you print a log message in fatal mode?public void fatal(Object message) of Logger class prints messages with the level Level.FATAL.
  37. 37How will you print a log message in info mode?public void info(Object message) of Logger class prints messages with the level Level.INFO.
  38. 38How will you print a log message in warn mode?public void warn(Object message) of Logger class prints messages with the level Level.WARN.
  39. 39How will you print a log message in trace mode?public void trace(Object message) of Logger class prints messages with the level Level.TRACE.
  40. 40Mention what are the different types of Appenders?Some of the Appenders type include
    ConsoleAppender logs to standard output
    FileAppender prints logs to some file
    Rolling file appender to a file with maximum size
  41. 41Mention what are the two static methods for obtaining a logger object?The two static methods for obtaining a logger object are
    Public static Logger getRootLogger()
    Public static Logger getLogger(String name)
  42. 42How log4j file is defined?Log4j file is defined by the name log4j.properties, it keeps properties in key-value pairs.By default, the log manager looks for a file name log4j.properties in the CLASSPATH.
  43. 43Explain what is the command to write your logging information into a file?To write your logging information into a file, you would need to use a command org.apache.log4j.FileAppender.
  44. 44Mention what are the logging methods provided by logger class?Logger class provides a variety of methods to handle logging activities.To obtain a logger object it provides two static methods: Public static logger getRootLogger(); Public static logger getLogger(String name);
  45. 45In log4j how can you log into the database?The log4j API provides the object org.apache.log4j.jdbc.JDBCAppender object can put logging information in a particular database.
  46. 46Can you customize the log output format?Yes, you can extend the layout class to create your own customized log format.Appenders can be parameterized to use the layout of your choice.
  47. 47What are the system properties checked by log4j?The system properties checked by log4j are
    Log4j debug, if true, log4j will show internal debugging messages to the console.
    defaultInitOverride, if true, log4j will not execute default initialization.
    configuration, URL for default initialization configuration file.
    configurationClass, Class name for configurator to execute default initialization configuration file.
    ignoreTCL, if true, the thread class loader will be overlooked when loading classes.
  48. 48Explain how can you get multiple processes to log to the same file?We may have each process log to a socket Appender.The receiving socket server can receive all the events and send them to a single log file.
  49. 49Mention what is the difference between Threshold and LevelRangeFilter in log4j?Both Threshold and LevelRangeFilter does the same thing.However, threshold should be faster.Filters enable you to implement your own logic, and you can also link them together if required.If you need a basic threshold functionality, then threshold function will be enough.
  50. 50Mention what does .class mean in log4j context?In log4j context, .class is used to get the full name of your class and that string is used to configure this logger object. For example,
    logger.getlogget (Myclass.class)
  51. 51What is the purpose of PatternLayout object?If we want to generate your logging information in a particular format based on a pattern, then we can use org.apache.log4j.PatternLayout to format your logging information.
    The PatternLayout class extends the abstract org.apache.log4j.Layout class and overrides the format() method to structure the logging information according to a supplied pattern.
  52. 52What is package level logging in log4j?Package level logging is the standard logging of log4j, with this you would determine the package and the associated level.
  53. 53What does WARN and TRACE level indicates in log4j?Log4j level WARN gives a warning about an unpredicted event to the user.The messages coming out of this level may not stop the progress of the system.The TRACE level provides more detailed information than the DEBUG level, and it will stay on the top of the hierarchy.
  54. 54What are the format characters used in log4j?The format characters used in log4j are
    L- it is used to output the line number from where the logging request was processed or issued
    m- It is used to output the application supplied message related with the logging event
    p-It is used to output the priority of the logging event
    C- It is used to output the class name of the caller issuing the logging request
    When any number is used along with the character it means the priority of the logging event should be justified to a width of 4 characters.
  55. 55What is the best way to migrate from java.util logging to log4j?The best way to migrate from java.util logged to log4j is to use global file search/replace method.It will replace with org.apache.log4j.Logger.
  56. 56Why do you get multiple copies of the message in log file sometime?There could be two reasons why this may happen:
    Repeated configuration of log4j.
    Attaching the same appenders to multiple loggers.
  57. 57How can we change the Log level for the application?By changing the Root Level within Log4j config.
  58. 58In following log4j configuration file, How should we change the logging level to WARNWe should change the root level from DEBUG to WARN.
  59. 59Can you organize following Log4j levels in hierarchy? WARN, DEBUG,INFO, ERROR Log4jDEBUG
    INFO
    WARN
    ERROR
    Root Log level of DEBUG will print all
    Root Log Level of INFO will print INFO, WARN and ERROR
    Root Log level of WARN will print WARN and ERROR
    Root Log level of ERROR will print ERROR alone
  60. 60What should be the logging level while logging exceptions?It depends on how severe the exception is.If the exception is completely unexpected and breaks the request, It should be logged as ERROR or FATAL.If it's not expected but we can live with it and the application request continue in-spite of it, It should be WARN.If it's expected , it can be just INFO.

Informationen

Beschreibung
Log4j Interview Questions
Erstellt von
Jerry Reeves Jr
Aufrufe
7
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck