hibernate-orm/design/logger_id_ranges.adoc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
3.8 KiB
Plaintext
Raw Normal View History

2020-05-27 11:22:49 -04:00
= Logging design
2019-10-15 12:38:08 -04:00
2020-05-27 11:22:49 -04:00
== "System"-specific Loggers
The basic idea here is to group log messages into a more logical hierarchy of Logger names for
the purpose of filtering.
E.g. "org.hibernate.orm.model.mapping" is one such system we define for the purpose of
grouping hierarchy of loggers names related to specific aspects of the mapping model:
----
* org.hibernate.orm.model.mapping
|- * org.hibernate.orm.model.mapping.creation
\- * org.hibernate.orm.model.mapping....
----
Just like with normal log filtering, here we'd use these system names in the underlying logger config.
E.g., in our test-suite we've found the following log4j pattern to be great for these systems:
----
...
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}(%C{1}:%L) - %m%n
log4j.logger.org.hibernate.orm.model.mapping.creation=trace
...
----
An example of output:
----
09:45:34,713 DEBUG creation(MappingModelCreationProcess:76) - Starting generic post-init callbacks
09:45:34,713 DEBUG creation(MappingModelCreationProcess$PostInitCallbackEntry:160) - Starting MappingModelCreationProcess.PostInitCallbackEntry processing : EmbeddableMappingType builder : org.hibernate.type.EmbeddedComponentType@69b2f8e5
09:45:34,714 DEBUG creation(MappingModelCreationProcess$PostInitCallbackEntry:160) - Starting MappingModelCreationProcess.PostInitCallbackEntry processing : Static fetchable list builder : org.hibernate.test.ecid.CompositeIdAssociationsWithEmbeddedCompositeIdTest$Parent
----
The pattern could use `%c` rather than `%c{1}`. That approach is much nicer for these system-based names. However,
that would be verbose with the more normal pattern of using class name for logger name.
As an example output:
----
09:45:34,713 DEBUG org.hibernate.orm.model.mapping.creation(MappingModelCreationProcess:76) - Starting generic post-init callbacks
09:45:34,713 DEBUG org.hibernate.orm.model.mapping.creation(MappingModelCreationProcess$PostInitCallbackEntry:160) - Starting MappingModelCreationProcess.PostInitCallbackEntry processing : EmbeddableMappingType builder : org.hibernate.type.EmbeddedComponentType@69b2f8e5
09:45:34,714 DEBUG org.hibernate.orm.model.mapping.creation(MappingModelCreationProcess$PostInitCallbackEntry:160) - Starting MappingModelCreationProcess.PostInitCallbackEntry processing : Static fetchable list builder : org.hibernate.test.ecid.CompositeIdAssociationsWithEmbeddedCompositeIdTest$Parent
----
Typically, a class would be created for each system to hold a shared reference to a singleton Logger instance as
well as some helper info such as whether DEBUG or TRACE are enabled. E.g.:
[source,java]
----
@MessageLogger( projectCode = "HHH" )
@ValidIdRange( min = 90005701, max = 90005800 )
public interface MappingModelCreationLogger extends BasicLogger {
String LOGGER_NAME = "org.hibernate.orm.model.mapping.creation";
MappingModelCreationLogger LOGGER = Logger.getMessageLogger( MappingModelCreationLogger.class, LOGGER_NAME );
boolean TRACE_ENABLED = LOGGER.isTraceEnabled();
boolean DEBUG_ENABLED = LOGGER.isDebugEnabled();
}
----
2022-03-11 15:45:43 -05:00
== Sub-system logging registry
2020-05-27 11:22:49 -04:00
2022-03-11 15:45:43 -05:00
[width="50%",cols=">s,>s,^2m",options="header"]
2019-10-15 12:38:08 -04:00
|===
2022-03-11 15:45:43 -05:00
|Channel (category)
|Id Range (?)
|Purpose
2019-10-15 12:38:08 -04:00
2022-03-11 15:45:43 -05:00
|[[connections-pooling]]org.hibernate.orm.connections.pooling
|<<ConnectionInfoLogger>>
|Logging related to connections and connection pooling
2019-10-15 12:38:08 -04:00
2022-03-11 15:45:43 -05:00
|org.hibernate.orm.boot
2020-05-27 11:22:49 -04:00
|n/a
2022-03-11 15:45:43 -05:00
|Logging related to bootstrapping of a SessionFactory / EntityManagerFactory
2019-10-15 12:38:08 -04:00
2022-03-11 15:45:43 -05:00
|===
2019-10-15 12:38:08 -04:00
2022-03-11 15:45:43 -05:00
== MessageLogger id registry
2019-10-15 12:38:08 -04:00
2022-03-11 15:45:43 -05:00
[width="50%",cols=">s,>s,^2m,^2m",options="header"]
|===
|`ValidIdRange#min`
|`ValidIdRange#max`
|Logger
|Sub-system (?)
2019-10-15 12:38:08 -04:00
|[[ConnectionInfoLogger]]10001001
2019-10-15 12:38:08 -04:00
|10001500
|org.hibernate.internal.log.ConnectionInfoLogger
2022-03-11 15:45:43 -05:00
| <<connections-pooling>>
2019-10-15 12:38:08 -04:00
2022-03-11 15:45:43 -05:00
|1
|2
|org.hibernate.TheLogger
2020-05-27 11:22:49 -04:00
|n/a
2019-10-15 12:38:08 -04:00
|===