Skip to content

Commit 33c2a7e

Browse files
committed
added_logger
1 parent 715a7b6 commit 33c2a7e

File tree

6 files changed

+227
-4
lines changed

6 files changed

+227
-4
lines changed

sheets/esheets.ecf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<library name="cypress_consumer" location="$ISE_LIBRARY\contrib\library\web\authentication\oauth\cypress\consumer\consumer.ecf" readonly="false"/>
2222
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder.ecf"/>
2323
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf" readonly="false"/>
24+
<library name="logging" location="$ISE_LIBRARY\library\runtime\logging\logging.ecf"/>
2425
<library name="login_with_google" location="$ISE_LIBRARY\contrib\library\web\authentication\oauth\cypress\login_with\google\login_with_google.ecf" readonly="false"/>
2526
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri.ecf"/>
2627
<cluster name="esheets_api" location=".\src\" recursive="true"/>

sheets/src/eg_sheets_api.e

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ feature -- Error Report
117117
if attached {JSON_OBJECT} l_json_parser.parsed_json_value as l_main_jso then
118118
if attached {JSON_OBJECT} l_main_jso.item ("error") as l_error_jso then
119119
if attached {JSON_NUMBER} l_error_jso.item ("code") as l_jso then
120-
print ("parse_last_response-> error code:" + l_jso.representation)
120+
print ("parse_last_response-> error code:" + l_jso.representation + "%N")
121121
end
122122
if attached {JSON_STRING} l_error_jso.item ("message") as l_jso then
123-
print ("parse_last_response-> error message:" + l_jso.unescaped_string_8)
123+
print ("parse_last_response-> error message:" + l_jso.unescaped_string_8 + "%N")
124124
end
125125
if attached {JSON_STRING} l_error_jso.item ("status") as l_jso then
126-
print ("parse_last_response-> error status:" + l_jso.unescaped_string_8)
126+
print ("parse_last_response-> error status:" + l_jso.unescaped_string_8 + "%N")
127127
end
128128
end
129129
end

sheets/src/errors/eg_sheet_error.e

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
note
2+
description: "Summary description for {EG_SHEET_ERROR}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
EG_SHEET_ERROR
9+
10+
create
11+
make,
12+
make_from_separate
13+
14+
feature {NONE} -- Initialize
15+
16+
make (a_msg: like message)
17+
do
18+
message := a_msg
19+
ensure
20+
message = a_msg
21+
end
22+
23+
make_from_separate (other: separate like Current)
24+
do
25+
create message.make_from_separate (other.message)
26+
end
27+
28+
feature -- Access
29+
30+
message: STRING
31+
32+
feature -- SCOOP
33+
34+
error_from_separate (an_err: separate like Current): EG_SHEET_ERROR
35+
do
36+
create Result.make_from_separate (an_err)
37+
ensure
38+
instance_free: Class
39+
end
40+
41+
end

sheets/src/errors/fallible.e

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
note
2+
description: "Base class for error gestion"
3+
author: "Philippe Gachoud"
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
FALLIBLE
9+
10+
inherit
11+
LOGGABLE
12+
redefine
13+
default_create,
14+
out
15+
end
16+
17+
18+
feature {NONE} -- Initialization
19+
20+
default_create
21+
do
22+
Precursor
23+
create warnings.make
24+
end
25+
26+
make_from_separate (other: separate like Current)
27+
do
28+
-- Precursor (other)
29+
create warnings.make
30+
if attached other.last_error as l_e then
31+
create last_error.make_from_separate (l_e)
32+
end
33+
if attached other.last_success_message as l_e then
34+
create last_success_message.make_from_separate (l_e)
35+
end
36+
end
37+
38+
feature -- Access
39+
40+
warnings: LINKED_LIST[STRING]
41+
42+
last_error: detachable EG_SHEET_ERROR
43+
-- Last error
44+
45+
last_success_message: detachable STRING
46+
-- If any
47+
48+
49+
feature -- Status report
50+
51+
has_error: BOOLEAN
52+
-- Based on last_error
53+
do
54+
Result := last_error /= Void
55+
end
56+
57+
has_warnings: BOOLEAN
58+
do
59+
Result := warnings.is_empty
60+
end
61+
62+
is_valid: BOOLEAN
63+
do
64+
Result := not has_error
65+
end
66+
67+
feature -- Output
68+
69+
out: STRING
70+
do
71+
Result := generating_type.out + ": Fallible, error_status:" + has_error.out
72+
if attached last_error as l_err then
73+
Result.append (l_err.out)
74+
end
75+
if attached last_success_message as l_msg then
76+
Result.append (l_msg)
77+
end
78+
end
79+
80+
81+
feature -- Status setting
82+
83+
set_last_error_from_fallible (o: FALLIBLE)
84+
require
85+
attached o.last_error
86+
do
87+
last_error := o.last_error
88+
last_success_message := Void
89+
ensure
90+
attached o.last_error implies last_success_message = Void
91+
end
92+
93+
set_last_error_from_fallible_sep (other: separate FALLIBLE)
94+
require
95+
attached other.last_error
96+
do
97+
if attached other.last_error as l_le then
98+
last_error := {EG_SHEET_ERROR}.error_from_separate (l_le)
99+
last_success_message := Void
100+
else
101+
last_error := Void
102+
end
103+
ensure
104+
attached other.last_error implies last_success_message = Void
105+
end
106+
107+
set_last_error (an_error: like last_error)
108+
do
109+
last_error:= an_error
110+
if attached an_error then
111+
last_success_message := Void
112+
logger.write_warning ("Class: " + generating_type.out + " set_last_error-> Error setted: " + an_error.message)
113+
end
114+
ensure
115+
attached an_error implies last_success_message = Void
116+
has_error
117+
end
118+
119+
set_last_success_message_from_fallible (o: attached like Current)
120+
require
121+
attached o.last_success_message
122+
do
123+
last_success_message := o.last_success_message
124+
last_error := Void
125+
ensure
126+
attached o.last_success_message implies last_error = Void
127+
end
128+
129+
set_last_success_message (a_msg: attached like last_success_message)
130+
do
131+
last_success_message := a_msg
132+
last_error := Void
133+
ensure
134+
attached a_msg implies last_error = Void
135+
end
136+
137+
wipe_last_error
138+
-- Once you consider having treated it
139+
do
140+
last_error := Void
141+
ensure
142+
last_error = Void
143+
end
144+
145+
wipe_last_success_message
146+
do
147+
last_success_message := Void
148+
ensure
149+
last_success_message = Void
150+
end
151+
152+
extend_warnings (v: like warnings.item)
153+
do
154+
logger.write_warning (v)
155+
warnings.extend (v)
156+
end
157+
158+
invariant
159+
never_both_attached: not (attached last_error and attached last_success_message)
160+
is_valid implies not has_error
161+
has_error implies not is_valid
162+
end

sheets/src/logger/loggable.e

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
note
2+
description: "Summary description for {LOGGABLE}."
3+
author: "Philippe Gachoud"
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
LOGGABLE
9+
10+
feature -- Access
11+
12+
logger: LOG_LOGGING_FACILITY
13+
once
14+
create Result.make
15+
-- Result.set_file_path_sep (l_app_instance_sep.log_file_path_s)
16+
-- Result.register
17+
end
18+
19+
end

sheets/test/test_sheets_api.e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ feature -- Tests
3636
if l_esapi.has_error then
3737
-- debug ("test_create_sheet")
3838
print ("test_create_sheet-> Error %N" )
39-
print ("test_create_sheet-> Error: msg:" + l_esapi.error_message)
39+
print ("test_create_sheet-> Error: msg:" + l_esapi.error_message + "%N")
4040
print ("test_create_sheet-> See codes here: https://developers.google.com/maps-booking/reference/rest-api-v3/status_codes")
4141
print ("%N")
4242
-- end

0 commit comments

Comments
 (0)