Skip to content

Commit df9f345

Browse files
jacky8hyfHONG Yifan
andauthored
pkg_install: modify log levels & print destdir by default. (#891)
After this change, log levels are defined by the following: * -q: only print errors (not even warnings) * (default): print errors, warnings, infos * -v: print above & also debug logs. There are no errors and warnings logs at this moment. The existing verbose logs about file operations are categorized as debug logs, so they are only printed when -v is set. By default (if no flag is set), the destdir is printed as an INFO level log. Also improve the logging format to be similar to bazel's output, e.g. INFO: Installing to /tmp/inst Fixes #889 Co-authored-by: HONG Yifan <elsk@google.com>
1 parent 03cbc6c commit df9f345

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

pkg/private/install.py.tpl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,29 @@ class NativeInstaller(object):
6565

6666
def _chown_chmod(self, dest, mode, user, group):
6767
if mode:
68-
logging.info("CHMOD %s %s", mode, dest)
68+
logging.debug("CHMOD %s %s", mode, dest)
6969
os.chmod(dest, int(mode, 8))
7070
if user or group:
7171
# Ownership can only be changed by sufficiently
7272
# privileged users.
7373
# TODO(nacl): This does not support windows
7474
if hasattr(os, "getuid") and os.getuid() == 0:
75-
logging.info("CHOWN %s:%s %s", user, group, dest)
75+
logging.debug("CHOWN %s:%s %s", user, group, dest)
7676
shutil.chown(dest, user, group)
7777

7878
def _do_file_copy(self, src, dest):
79-
logging.info("COPY %s <- %s", dest, src)
79+
logging.debug("COPY %s <- %s", dest, src)
8080
shutil.copyfile(src, dest)
8181

8282
def _do_mkdir(self, dirname, mode):
83-
logging.info("MKDIR %s %s", mode, dirname)
83+
logging.debug("MKDIR %s %s", mode, dirname)
8484
os.makedirs(dirname, int(mode, 8), exist_ok=True)
8585

8686
def _do_symlink(self, target, link_name, mode, user, group):
8787
raise NotImplementedError("symlinking not yet supported")
8888

8989
def _maybe_make_unowned_dir(self, path):
90-
logging.info("MKDIR (unowned) %s", path)
90+
logging.debug("MKDIR (unowned) %s", path)
9191
# TODO(nacl): consider default permissions here
9292
# TODO(nacl): consider default ownership here
9393
os.makedirs(path, 0o755, exist_ok=True)
@@ -107,7 +107,7 @@ class NativeInstaller(object):
107107
self._chown_chmod(dst, entry.mode, entry.user, entry.group)
108108

109109
def _install_treeartifact(self, entry):
110-
logging.info("COPYTREE %s <- %s/**", entry.dest, entry.src)
110+
logging.debug("COPYTREE %s <- %s/**", entry.dest, entry.src)
111111
shutil.copytree(
112112
src=entry.src,
113113
dst=entry.dest,
@@ -147,9 +147,9 @@ class NativeInstaller(object):
147147

148148
def _install_symlink(self, entry):
149149
raise NotImplementedError("symlinking not yet supported")
150-
logging.info("SYMLINK %s <- %s", entry.dest, entry.link_to)
151-
logging.info("CHMOD %s %s", entry.dest, entry.mode)
152-
logging.info("CHOWN %s.%s %s", entry.dest, entry.user, entry.group)
150+
logging.debug("SYMLINK %s <- %s", entry.dest, entry.link_to)
151+
logging.debug("CHMOD %s %s", entry.dest, entry.mode)
152+
logging.debug("CHOWN %s.%s %s", entry.dest, entry.user, entry.group)
153153

154154
def include_manifest_path(self, path):
155155
with open(path, 'r') as fh:
@@ -170,6 +170,7 @@ class NativeInstaller(object):
170170
self.entries.append(entry)
171171

172172
def do_the_thing(self):
173+
logging.info("Installing to %s", self.destdir)
173174
for entry in self.entries:
174175
if entry.type == manifest.ENTRY_IS_FILE:
175176
self._install_file(entry)
@@ -241,13 +242,14 @@ def main(args):
241242
loudness = args.verbose - args.quiet
242243

243244
if args.quiet:
244-
logging.getLogger().setLevel(logging.ERROR)
245+
level = logging.ERROR
245246
elif loudness == 0:
246-
logging.getLogger().setLevel(logging.WARNING)
247-
elif loudness == 1:
248-
logging.getLogger().setLevel(logging.INFO)
249-
else: # loudness >= 2:
250-
logging.getLogger().setLevel(logging.DEBUG)
247+
level = logging.INFO
248+
else: # loudness >= 1
249+
level = logging.DEBUG
250+
logging.basicConfig(
251+
level=level, format="%(levelname)s: %(message)s"
252+
)
251253

252254
installer = NativeInstaller(destdir=args.destdir)
253255

0 commit comments

Comments
 (0)