Skip to content

Commit 9a08d43

Browse files
committed
Added error log/console log save database and file. Error Log send email.
1 parent 6b3c5da commit 9a08d43

File tree

7 files changed

+178
-15
lines changed

7 files changed

+178
-15
lines changed

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<java.version>11</java.version>
2929
<node.version>v16.14.0</node.version>
3030
<npm.version>8.6.0</npm.version>
31-
31+
<logstash-logback-encoder.version>6.6</logstash-logback-encoder.version>
3232
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3333
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3434
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
@@ -106,6 +106,18 @@
106106
</dependencyManagement>
107107

108108
<dependencies>
109+
110+
<dependency>
111+
<groupId>ch.qos.logback</groupId>
112+
<artifactId>logback-classic</artifactId>
113+
<version>1.2.6</version>
114+
</dependency>
115+
<dependency>
116+
<groupId>ch.qos.logback</groupId>
117+
<artifactId>logback-core</artifactId>
118+
<version>1.2.6</version>
119+
</dependency>
120+
109121
<dependency>
110122
<groupId>tech.jhipster</groupId>
111123
<artifactId>jhipster-framework</artifactId>

src/main/resources/config/application-dev.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ spring:
4747
liquibase:
4848
# Remove 'faker' if you do not want the sample data to be loaded automatically
4949
contexts: dev, faker
50-
mail:
51-
host: localhost
52-
port: 25
53-
username:
54-
password:
50+
# mail:
51+
# host: localhost
52+
# port: 25
53+
# username:
54+
# password:
5555
messages:
5656
cache-duration: PT1S # 1 second, see the ISO 8601 standard
5757
thymeleaf:

src/main/resources/config/application-prod.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ spring:
4444
# Replace by 'prod, faker' to add the faker context and have sample data loaded in production
4545
liquibase:
4646
contexts: prod
47-
mail:
48-
host: localhost
49-
port: 25
50-
username:
51-
password:
47+
# mail:
48+
# host: localhost
49+
# port: 25
50+
# username:
51+
# password:
5252
thymeleaf:
5353
cache: true
5454
sleuth:

src/main/resources/config/application.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,17 @@ spring:
156156
output:
157157
ansi:
158158
console-available: true
159-
159+
mail:
160+
host: smtp.gmail.com
161+
port: 587
162+
163+
password: vfztdeyooyssiezs
164+
properties:
165+
mail:
166+
smtp:
167+
auth: true
168+
starttls:
169+
enable: true
160170
server:
161171
servlet:
162172
session:
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.5.xsd
7+
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
8+
9+
<!-- logback loglarını tabloya kayıt yapabilmek için oluşturulmuştur. -->
10+
<changeSet id="logback-01" author="cevheri" dbms="postgresql">
11+
<sql>
12+
CREATE SEQUENCE logging_event_id_seq MINVALUE 1 START 1;
13+
</sql>
14+
</changeSet>
15+
16+
<changeSet id="logback-02" author="cevheri" dbms="postgresql">
17+
<sql>
18+
CREATE TABLE logging_event
19+
(
20+
timestmp BIGINT NOT NULL,
21+
formatted_message TEXT NOT NULL,
22+
logger_name VARCHAR(254) NOT NULL,
23+
level_string VARCHAR(254) NOT NULL,
24+
thread_name VARCHAR(254),
25+
reference_flag SMALLINT,
26+
arg0 VARCHAR(254),
27+
arg1 VARCHAR(254),
28+
arg2 VARCHAR(254),
29+
arg3 VARCHAR(254),
30+
caller_filename VARCHAR(254) NOT NULL,
31+
caller_class VARCHAR(254) NOT NULL,
32+
caller_method VARCHAR(254) NOT NULL,
33+
caller_line CHAR(4) NOT NULL,
34+
event_id BIGINT DEFAULT nextval('logging_event_id_seq') PRIMARY KEY
35+
);
36+
</sql>
37+
</changeSet>
38+
39+
<changeSet id="logback-03" author="cevheri" dbms="postgresql">
40+
<sql>
41+
CREATE TABLE logging_event_property
42+
(
43+
event_id BIGINT NOT NULL,
44+
mapped_key VARCHAR(254) NOT NULL,
45+
mapped_value VARCHAR(1024),
46+
PRIMARY KEY(event_id, mapped_key),
47+
FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
48+
);
49+
</sql>
50+
</changeSet>
51+
52+
<changeSet id="logback-04" author="cevheri" dbms="postgresql">
53+
<sql>
54+
CREATE TABLE logging_event_exception
55+
(
56+
event_id BIGINT NOT NULL,
57+
i SMALLINT NOT NULL,
58+
trace_line VARCHAR(254) NOT NULL,
59+
PRIMARY KEY(event_id, i),
60+
FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
61+
);
62+
</sql>
63+
</changeSet>
64+
65+
<changeSet id="logback-h2-01" author="cevheri" dbms="h2">
66+
<sql>
67+
CREATE TABLE logging_event (
68+
timestmp BIGINT NOT NULL,
69+
formatted_message LONGVARCHAR NOT NULL,
70+
logger_name VARCHAR(256) NOT NULL,
71+
level_string VARCHAR(256) NOT NULL,
72+
thread_name VARCHAR(256),
73+
reference_flag SMALLINT,
74+
arg0 VARCHAR(256),
75+
arg1 VARCHAR(256),
76+
arg2 VARCHAR(256),
77+
arg3 VARCHAR(256),
78+
caller_filename VARCHAR(256),
79+
caller_class VARCHAR(256),
80+
caller_method VARCHAR(256),
81+
caller_line CHAR(4),
82+
event_id IDENTITY NOT NULL);
83+
84+
85+
CREATE TABLE logging_event_property (
86+
event_id BIGINT NOT NULL,
87+
mapped_key VARCHAR(254) NOT NULL,
88+
mapped_value LONGVARCHAR,
89+
PRIMARY KEY(event_id, mapped_key),
90+
FOREIGN KEY (event_id) REFERENCES logging_event(event_id));
91+
92+
CREATE TABLE logging_event_exception (
93+
event_id BIGINT NOT NULL,
94+
i SMALLINT NOT NULL,
95+
trace_line VARCHAR(256) NOT NULL,
96+
PRIMARY KEY(event_id, i),
97+
FOREIGN KEY (event_id) REFERENCES logging_event(event_id));
98+
</sql>
99+
</changeSet>
100+
101+
</databaseChangeLog>

src/main/resources/config/liquibase/master.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
<!-- jhipster-needle-liquibase-add-incremental-changelog - JHipster will add incremental liquibase changelogs here -->
3434

3535
<include file="config/liquibase/changelog/EntityAuditEvent.xml" relativeToChangelogFile="false"/>
36+
<include file="config/liquibase/changelog/logback.xml" relativeToChangelogFile="false"/>
3637
</databaseChangeLog>

src/main/resources/logback-spring.xml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
<include resource="org/springframework/boot/logging/logback/base.xml"/>
66

77
<!-- The FILE and ASYNC appenders are here as examples for a production configuration -->
8-
<!--
98
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
109
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
1110
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
12-
<maxHistory>90</maxHistory>
11+
<maxHistory>15</maxHistory>
1312
</rollingPolicy>
1413
<encoder>
1514
<charset>utf-8</charset>
@@ -25,7 +24,6 @@
2524
<root level="${logging.level.root}">
2625
<appender-ref ref="ASYNC"/>
2726
</root>
28-
-->
2927

3028
<logger name="javax.activation" level="WARN"/>
3129
<logger name="javax.mail" level="WARN"/>
@@ -69,4 +67,45 @@
6967
<resetJUL>true</resetJUL>
7068
</contextListener>
7169

70+
<!-- &lt;!&ndash;Cevheri : Postgresql LogBack Appander &ndash;&gt;-->
71+
<appender name="POSTGRES" class="ch.qos.logback.classic.db.DBAppender">
72+
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
73+
<driverClass>com.zaxxer.hikari.HikariDataSource</driverClass>
74+
<url>jdbc:postgresql://ec2-54-228-32-29.eu-west-1.compute.amazonaws.com:5432/d3u9gjp7sid0q6</url>
75+
<user>nlkshkvuuobqke</user>
76+
<password>837dd58cd40354dccde06e066dc8aa20788d5b04659e8fb9adf9493af2e7c5f9</password>
77+
</connectionSource>
78+
</appender>
79+
<root level="ERROR">
80+
<appender-ref ref="POSTGRES"/>
81+
</root>
82+
<!--end postgres -->
83+
84+
85+
<!--email -->
86+
87+
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
88+
<smtpHost>smtp.gmail.com</smtpHost>
89+
<smtpPort>587</smtpPort>
90+
<STARTTLS>true</STARTTLS>
91+
<!-- <username>[email protected]</username>-->
92+
<!-- <password>vncnpmoscajsmmow</password> -->
93+
<username>[email protected]</username>
94+
<password>vfztdeyooyssiezs</password>
95+
96+
97+
<from>[email protected]</from>
98+
<subject>blog Java Error: %logger{20} - %m</subject>
99+
<layout class="ch.qos.logback.classic.PatternLayout">
100+
<pattern>%date %-5level %logger - %message%n</pattern>
101+
</layout>
102+
</appender>
103+
104+
<!-- <root level="ERROR">-->
105+
<!-- <appender-ref ref="EMAIL" />-->
106+
<!-- </root>-->
107+
108+
<!--end email-->
109+
110+
72111
</configuration>

0 commit comments

Comments
 (0)