Skip to content

Commit 7bf56d6

Browse files
committed
mi/event: improve logging in tools
1 parent 81d1fbe commit 7bf56d6

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

opensips/event/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def main():
112112
timeout=0.1)
113113
else:
114114
if not args.bash_complete:
115-
print(f'Unknown type: {args.type}')
115+
print(f'ERROR: unknown type: {args.type}')
116116
sys.exit(1)
117117

118118
if args.bash_complete is not None:
@@ -144,7 +144,7 @@ def main():
144144
sys.exit(1)
145145

146146
if args.event is None:
147-
print('Event name is required')
147+
print(f'ERROR: unknown type: {args.type}')
148148
sys.exit(1)
149149

150150
hdl = OpenSIPSEventHandler(mi, args.transport,
@@ -160,7 +160,7 @@ def event_handler(message):
160160
try:
161161
print(json.dumps(message, indent=4))
162162
except json.JSONDecodeError as e:
163-
print(f"Failed to decode JSON: {e}")
163+
print(f"ERROR: failed to decode JSON: {e}")
164164

165165
ev = None
166166

@@ -179,7 +179,7 @@ def timer(*_):
179179
try:
180180
ev = hdl.subscribe(args.event, event_handler, args.expire)
181181
except OpenSIPSEventException as e:
182-
print(e)
182+
print("ERROR:", e)
183183
sys.exit(1)
184184

185185
while True:

opensips/mi/__main__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,26 @@ def main():
135135
sys.exit(1)
136136

137137
if args.stats:
138-
print('Using get_statistics! Be careful not to use '
139-
'command after -s/--stats.')
140138
args.command = 'get_statistics'
141139

142140
if args.json:
143-
print('Cannot use -s/--stats with -j/--json!')
141+
print('ERROR: cannot use -s/--stats with -j/--json!')
144142
sys.exit(1)
145143

146144
args.parameters = {'statistics': args.stats}
147145
else:
148146
if args.json:
149147
try:
150148
args.parameters = json.loads(args.json)
151-
print(args.parameters)
152149
except json.JSONDecodeError as e:
153-
print('Invalid JSON: ', e)
150+
print('ERROR: invalid JSON: ', e)
154151
sys.exit(1)
155152

156153
try:
157154
response = mi.execute(args.command, args.parameters)
158155
print(json.dumps(response, indent=4))
159156
except OpenSIPSMIException as e:
160-
print('Error: ', e)
157+
print('ERROR: ', e)
161158
sys.exit(1)
162159

163160

0 commit comments

Comments
 (0)