Skip to content

Add an option to format logs with JSON #378

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
Aug 30, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added integration tests for log format
  • Loading branch information
Massimiliano Pippi committed Aug 29, 2019
commit 363fbd5fba8c93c84c6c3b51ded086e11bf65e9d
36 changes: 36 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# otherwise use the software for commercial activities involving the Arduino
# software without disclosing the source code of your own applications. To purchase
# a commercial license, send an email to license@arduino.cc.
import os
import json

import semver


Expand All @@ -36,3 +38,37 @@ def test_version(run_command):
assert parsed_out.get("Application", False) == "arduino-cli"
assert isinstance(semver.parse(parsed_out.get("VersionString", False)), dict)
assert isinstance(parsed_out.get("Commit", False), str)


def test_log_options(run_command, data_dir):
"""
using `version` as a test command
"""

# no logs
out_lines = run_command("version").stdout.strip().split("\n")
assert len(out_lines) == 1

# plain text logs on stdoud
out_lines = run_command("version -v").stdout.strip().split("\n")
assert len(out_lines) > 1
assert out_lines[0].startswith("\x1b[36mINFO\x1b[0m") # account for the colors

# plain text logs on file
log_file = os.path.join(data_dir, "log.txt")
run_command("version --log-file " + log_file)
with open(log_file) as f:
lines = f.readlines()
assert lines[0].startswith('time="') # file format is different from console

# json on stdout
out_lines = run_command("version -v --log-format JSON").stdout.strip().split("\n")
lg = json.loads(out_lines[0])
assert "level" in lg

# json on file
log_file = os.path.join(data_dir, "log.json")
run_command("version --log-format json --log-file " + log_file)
with open(log_file) as f:
for line in f.readlines():
json.loads(line)