Skip to content

cmdline args for logging in samples #33

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

Merged
merged 3 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions samples/basic_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,16 @@
parser.add_argument('-m', '--mode', action='store', dest='mode', default='both',
help='Operation modes: %s'%str(allowed_actions))
parser.add_argument('-M', '--message', action='store', dest='message', default='Hello World!',
help='Message to publish')
help='Message to publish')
parser.add_argument('--region', action='store', dest='region', default='us-east-1')
parser.add_argument('--max-pub-ops', action='store', dest='max_pub_ops', default=10)
parser.add_argument('--print-discover-resp-only', action='store_true', dest='print_discover_resp_only', default=False)
parser.add_argument('-v', '--verbose', action='store', dest='verbosity', default='NoLogs')
parser.add_argument('-v', '--verbosity', choices=[x.name for x in LogLevel], default=LogLevel.NoLogs.name,
help='Logging level')

args = parser.parse_args()

if args.verbosity.lower() == 'fatal':
io.init_logging(LogLevel.Fatal, 'stderr')
elif args.verbosity.lower() == 'error':
io.init_logging(LogLevel.Error, 'stderr')
elif args.verbosity.lower() == 'warn':
io.init_logging(LogLevel.Warn, 'stderr')
elif args.verbosity.lower() == 'info':
io.init_logging(LogLevel.Info, 'stderr')
elif args.verbosity.lower() == 'debug':
io.init_logging(LogLevel.Debug, 'stderr')
elif args.verbosity.lower() == 'trace':
io.init_logging(LogLevel.Trace, 'stderr')
io.init_logging(getattr(LogLevel, args.verbosity), 'stderr')

event_loop_group = io.EventLoopGroup(1)
host_resolver = io.DefaultHostResolver(event_loop_group)
Expand Down
3 changes: 3 additions & 0 deletions samples/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
parser.add_argument('--proxy-host', help="Hostname for proxy to connect to. Note: if you use this feature, " +
"you will likely need to set --root-ca to the ca for your proxy.")
parser.add_argument('--proxy-port', type=int, default=8080, help="Port for proxy to connect to.")
parser.add_argument('--verbosity', choices=[x.name for x in io.LogLevel], default=io.LogLevel.NoLogs.name,
help='Logging level')

# Using globals to simplify sample code
is_sample_done = threading.Event()
Expand Down Expand Up @@ -232,6 +234,7 @@ def on_update_job_execution_rejected(rejected):
# Process input args
args = parser.parse_args()
thing_name = args.thing_name
io.init_logging(getattr(io.LogLevel, args.verbosity), 'stderr')

# Spin up resources
event_loop_group = io.EventLoopGroup(1)
Expand Down
4 changes: 4 additions & 0 deletions samples/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@
parser.add_argument('--proxy-host', help="Hostname for proxy to connect to. Note: if you use this feature, " +
"you will likely need to set --root-ca to the ca for your proxy.")
parser.add_argument('--proxy-port', type=int, default=8080, help="Port for proxy to connect to.")
parser.add_argument('--verbosity', choices=[x.name for x in io.LogLevel], default=io.LogLevel.NoLogs.name,
help='Logging level')

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

io.init_logging(getattr(io.LogLevel, args.verbosity), 'stderr')

received_count = 0
received_all_event = threading.Event()

Expand Down
3 changes: 3 additions & 0 deletions samples/shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
parser.add_argument('--proxy-host', help="Hostname for proxy to connect to. Note: if you use this feature, " +
"you will likely need to set --root-ca to the ca for your proxy.")
parser.add_argument('--proxy-port', type=int, default=8080, help="Port for proxy to connect to.")
parser.add_argument('--verbosity', choices=[x.name for x in io.LogLevel], default=io.LogLevel.NoLogs.name,
help='Logging level')

# Using globals to simplify sample code
is_sample_done = threading.Event()
Expand Down Expand Up @@ -237,6 +239,7 @@ def user_input_thread_fn():
args = parser.parse_args()
thing_name = args.thing_name
shadow_property = args.shadow_property
io.init_logging(getattr(io.LogLevel, args.verbosity), 'stderr')

# Spin up resources
event_loop_group = io.EventLoopGroup(1)
Expand Down
4 changes: 2 additions & 2 deletions test/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_pubsub(self):
"--key", config.key_filepath,
"--client-id", create_client_id(),
"--count", "1",
#"--verbosity", "Trace",
"--verbosity", "Trace",
]

def stdout_checker(stdout):
Expand All @@ -130,7 +130,7 @@ def test_basic_discovery_response_only(self):
"--cert", config.cert_filepath,
"--key", config.key_filepath,
"--thing-name", "aws-sdk-crt-unit-test",
"-v", "Trace",
"--verbosity", "Trace",
]

def stdout_checker(stdout):
Expand Down