Skip to content

Commit

Permalink
add CONAN_LOG_LEVEL env-var (conan-io#15263)
Browse files Browse the repository at this point in the history
* add CONAN_LOG_LEVEL env-var

* Update conan/cli/command.py

---------

Co-authored-by: Francisco Ramírez <franchuti688@gmail.com>
  • Loading branch information
memsharded and franramirez688 authored Dec 13, 2023
1 parent 032eefc commit 6f3f445
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion conan/cli/command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import os
import textwrap

from conan.api.output import ConanOutput
Expand Down Expand Up @@ -101,7 +102,7 @@ def __init__(self, *args, **kwargs):

def parse_args(self, args=None, namespace=None):
args = super().parse_args(args)
ConanOutput.define_log_level(args.v)
ConanOutput.define_log_level(os.getenv("CONAN_LOG_LEVEL", args.v))
return args


Expand Down
43 changes: 41 additions & 2 deletions conans/test/integration/command_v2/test_output_level.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json

from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient
from conans.util.env import environment_update


def test_invalid_output_level():
Expand Down Expand Up @@ -142,3 +141,43 @@ def test_output_level():
assert "This is a success" not in t.out
assert "This is a warning" not in t.out
assert "This is a error" in t.out


def test_output_level_envvar():

lines = ("self.output.trace('This is a trace')",
"self.output.debug('This is a debug')",
"self.output.verbose('This is a verbose')",
"self.output.info('This is a info')",
"self.output.highlight('This is a highlight')",
"self.output.success('This is a success')",
"self.output.warning('This is a warning')",
"self.output.error('This is a error')",
)

t = TestClient()
t.save({"conanfile.py": GenConanfile().with_package(*lines)})

# Check if -v argument is equal to VERBOSE level
with environment_update({"CONAN_LOG_LEVEL": "verbose"}):
t.run("create . --name foo --version 1.0")
assert "This is a trace" not in t.out
assert "This is a debug" not in t.out
assert "This is a verbose" in t.out
assert "This is a info" in t.out
assert "This is a highlight" in t.out
assert "This is a success" in t.out
assert "This is a warning" in t.out
assert "This is a error" in t.out

# Check if -v argument is equal to VERBOSE level
with environment_update({"CONAN_LOG_LEVEL": "error"}):
t.run("create . --name foo --version 1.0")
assert "This is a trace" not in t.out
assert "This is a debug" not in t.out
assert "This is a verbose" not in t.out
assert "This is a info" not in t.out
assert "This is a highlight" not in t.out
assert "This is a success" not in t.out
assert "This is a warning" not in t.out
assert "This is a error" in t.out

0 comments on commit 6f3f445

Please sign in to comment.