-
Notifications
You must be signed in to change notification settings - Fork 6
Add log_solution package #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TwojaTata
wants to merge
2
commits into
java-academy:rozwiązania
Choose a base branch
from
TwojaTata:log-solution
base: rozwiązania
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/ja/workshops/hibernate/parts/log_solution/App.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package ja.workshops.hibernate.parts.log_solution; | ||
|
|
||
| import ja.workshops.hibernate.parts.connectors.H2Connector; | ||
| import ja.workshops.hibernate.parts.model.Author; | ||
| import ja.workshops.hibernate.parts.model.Book; | ||
| import ja.workshops.hibernate.parts.model.Genre; | ||
| import org.hibernate.Session; | ||
| import org.hibernate.Transaction; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Implementation of solution for log task. | ||
| * Main goal was to create log4j2.xml file with config of log4j2.xml | ||
| * which you can find in hiber/src/main/resources/log4j2.xml | ||
| * | ||
| * @author krzysztof.niedzielski | ||
| */ | ||
| public class App { | ||
| public static void main(String[] args) { | ||
| connect(); | ||
| } | ||
|
|
||
| private static void connect() { | ||
| try (Session session = new H2Connector().getSession()) { | ||
| Transaction transaction = session.beginTransaction(); | ||
|
|
||
| Author brzechwa = new Author("Jan", "Brzechwa"); | ||
| Author kupajki = new Author("Bartosz", "Kupajski"); | ||
| Author wrupek = new Author("Wiktor", "Wrupek"); | ||
| Set<Author> authors = new HashSet<>(); | ||
| authors.add(wrupek); | ||
| authors.add(brzechwa); | ||
| authors.add(kupajki); | ||
|
|
||
| Book book1 = new Book("w pustyni i w puszczy", Collections.singleton(brzechwa), Genre.CLASSIC); | ||
| Book book2 = new Book("angular in 5 minutes", authors, Genre.CLASSIC); | ||
| Book book3 = new Book("todo list - html js", Collections.singleton(wrupek), Genre.CLASSIC); | ||
| session.save(book1); | ||
| session.save(book2); | ||
| session.save(book3); | ||
| session.save(brzechwa); | ||
| session.save(kupajki); | ||
| session.save(wrupek); | ||
|
|
||
| transaction.commit(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Configuration> | ||
| <Appenders> | ||
|
|
||
| <!-- Console Appender --> | ||
| <Console name="Console" target="SYSTEM_OUT"> | ||
| <PatternLayout pattern="%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" /> | ||
| </Console> | ||
|
|
||
| <!-- File Appender --> | ||
| <File name="File" fileName="logs/app.log"> | ||
| <PatternLayout pattern="%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n" /> | ||
| </File> | ||
|
|
||
| </Appenders> | ||
| <Loggers> | ||
| <!-- Log everything in hibernate --> | ||
| <Logger name="org.hibernate" level="info" additivity="false"> | ||
| <AppenderRef ref="Console" /> | ||
| </Logger> | ||
|
|
||
| <!-- Log SQL statements --> | ||
| <Logger name="org.hibernate.SQL" level="debug" additivity="false"> | ||
| <AppenderRef ref="Console" /> | ||
| <AppenderRef ref="File" /> | ||
| </Logger> | ||
|
|
||
| <!-- Log JDBC bind parameters --> | ||
| <Logger name="org.hibernate.type.descriptor.sql" level="trace" additivity="false"> | ||
| <AppenderRef ref="Console" /> | ||
| <AppenderRef ref="File" /> | ||
| </Logger> | ||
|
|
||
| <!-- Log custom packages --> | ||
| <Logger name="com.boraji.tutorial.hibernate" level="debug" additivity="false"> | ||
| <AppenderRef ref="Console" /> | ||
| <AppenderRef ref="File" /> | ||
| </Logger> | ||
|
|
||
| <Root level="error"> | ||
| <AppenderRef ref="Console" /> | ||
| <AppenderRef ref="File" /> | ||
| </Root> | ||
| </Loggers> | ||
| </Configuration> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publiczna klasa bez dokumentacji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dokumentacja została dodana