Skip to content

Commit 65454ac

Browse files
authored
cmdline args for logging in samples (#33)
1 parent 74ba429 commit 65454ac

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

samples/basic_discovery.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,16 @@
3333
parser.add_argument('-m', '--mode', action='store', dest='mode', default='both',
3434
help='Operation modes: %s'%str(allowed_actions))
3535
parser.add_argument('-M', '--message', action='store', dest='message', default='Hello World!',
36-
help='Message to publish')
36+
help='Message to publish')
3737
parser.add_argument('--region', action='store', dest='region', default='us-east-1')
3838
parser.add_argument('--max-pub-ops', action='store', dest='max_pub_ops', default=10)
3939
parser.add_argument('--print-discover-resp-only', action='store_true', dest='print_discover_resp_only', default=False)
40-
parser.add_argument('-v', '--verbose', action='store', dest='verbosity', default='NoLogs')
40+
parser.add_argument('-v', '--verbosity', choices=[x.name for x in LogLevel], default=LogLevel.NoLogs.name,
41+
help='Logging level')
4142

4243
args = parser.parse_args()
4344

44-
if args.verbosity.lower() == 'fatal':
45-
io.init_logging(LogLevel.Fatal, 'stderr')
46-
elif args.verbosity.lower() == 'error':
47-
io.init_logging(LogLevel.Error, 'stderr')
48-
elif args.verbosity.lower() == 'warn':
49-
io.init_logging(LogLevel.Warn, 'stderr')
50-
elif args.verbosity.lower() == 'info':
51-
io.init_logging(LogLevel.Info, 'stderr')
52-
elif args.verbosity.lower() == 'debug':
53-
io.init_logging(LogLevel.Debug, 'stderr')
54-
elif args.verbosity.lower() == 'trace':
55-
io.init_logging(LogLevel.Trace, 'stderr')
45+
io.init_logging(getattr(LogLevel, args.verbosity), 'stderr')
5646

5747
event_loop_group = io.EventLoopGroup(1)
5848
host_resolver = io.DefaultHostResolver(event_loop_group)

samples/jobs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
parser.add_argument('--proxy-host', help="Hostname for proxy to connect to. Note: if you use this feature, " +
6464
"you will likely need to set --root-ca to the ca for your proxy.")
6565
parser.add_argument('--proxy-port', type=int, default=8080, help="Port for proxy to connect to.")
66+
parser.add_argument('--verbosity', choices=[x.name for x in io.LogLevel], default=io.LogLevel.NoLogs.name,
67+
help='Logging level')
6668

6769
# Using globals to simplify sample code
6870
is_sample_done = threading.Event()
@@ -232,6 +234,7 @@ def on_update_job_execution_rejected(rejected):
232234
# Process input args
233235
args = parser.parse_args()
234236
thing_name = args.thing_name
237+
io.init_logging(getattr(io.LogLevel, args.verbosity), 'stderr')
235238

236239
# Spin up resources
237240
event_loop_group = io.EventLoopGroup(1)

samples/pubsub.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@
4848
parser.add_argument('--proxy-host', help="Hostname for proxy to connect to. Note: if you use this feature, " +
4949
"you will likely need to set --root-ca to the ca for your proxy.")
5050
parser.add_argument('--proxy-port', type=int, default=8080, help="Port for proxy to connect to.")
51+
parser.add_argument('--verbosity', choices=[x.name for x in io.LogLevel], default=io.LogLevel.NoLogs.name,
52+
help='Logging level')
5153

5254
# Using globals to simplify sample code
5355
args = parser.parse_args()
5456

57+
io.init_logging(getattr(io.LogLevel, args.verbosity), 'stderr')
58+
5559
received_count = 0
5660
received_all_event = threading.Event()
5761

samples/shadow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
parser.add_argument('--proxy-host', help="Hostname for proxy to connect to. Note: if you use this feature, " +
6161
"you will likely need to set --root-ca to the ca for your proxy.")
6262
parser.add_argument('--proxy-port', type=int, default=8080, help="Port for proxy to connect to.")
63+
parser.add_argument('--verbosity', choices=[x.name for x in io.LogLevel], default=io.LogLevel.NoLogs.name,
64+
help='Logging level')
6365

6466
# Using globals to simplify sample code
6567
is_sample_done = threading.Event()
@@ -237,6 +239,7 @@ def user_input_thread_fn():
237239
args = parser.parse_args()
238240
thing_name = args.thing_name
239241
shadow_property = args.shadow_property
242+
io.init_logging(getattr(io.LogLevel, args.verbosity), 'stderr')
240243

241244
# Spin up resources
242245
event_loop_group = io.EventLoopGroup(1)

test/test_samples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_pubsub(self):
110110
"--key", config.key_filepath,
111111
"--client-id", create_client_id(),
112112
"--count", "1",
113-
#"--verbosity", "Trace",
113+
"--verbosity", "Trace",
114114
]
115115

116116
def stdout_checker(stdout):
@@ -130,7 +130,7 @@ def test_basic_discovery_response_only(self):
130130
"--cert", config.cert_filepath,
131131
"--key", config.key_filepath,
132132
"--thing-name", "aws-sdk-crt-unit-test",
133-
"-v", "Trace",
133+
"--verbosity", "Trace",
134134
]
135135

136136
def stdout_checker(stdout):

0 commit comments

Comments
 (0)