tools.vpm: debug-log to $VMODULES/cache/vpm.log if not running in debug mode (#21192)

This commit is contained in:
Turiiya 2024-04-06 11:29:43 +02:00 committed by GitHub
parent 31fdf580a4
commit 3a6cf5adfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 7 deletions

View File

@ -6,7 +6,6 @@ import net.urllib
import v.vmod
import json
import term
import log
struct ModuleVpmInfo {
// id int
@ -241,8 +240,13 @@ fn verbose_println(msg string) {
}
}
fn vpm_log_header(txt string) {
divider := '='.repeat(40 - txt.len / 2)
settings.logger.debug('\n${divider} ${txt} ${divider}\n')
}
fn vpm_log(line string, func string, msg string) {
log.debug('${line} | (${func}) ${msg}')
settings.logger.debug('${line} | (${func}) ${msg}')
}
fn vpm_error(msg string, opts ErrorOptions) {

View File

@ -19,17 +19,27 @@ mut:
fail_on_prompt bool
// git is used by default. URL installations can specify `--hg`. For already installed modules
// and VPM modules that specify a different VCS in their `v.mod`, the VCS is validated separately.
vcs VCS
vcs VCS
logger &log.Logger
}
fn init_settings() VpmSettings {
args := os.args[1..]
opts := cmdline.only_options(args)
cmds := cmdline.only_non_options(args)
if os.getenv('VPM_DEBUG') != '' {
log.set_level(.debug)
}
vmodules_path := os.vmodules_dir()
no_inc_env := os.getenv('VPM_NO_INCREMENT')
dbg_env := os.getenv('VPM_DEBUG')
mut logger := &log.Log{}
if dbg_env != '0' {
logger.set_level(.debug)
if dbg_env == '' {
logger.set_output_path(os.join_path(vmodules_path, 'cache', 'vpm.log'))
}
}
return VpmSettings{
is_help: '-h' in opts || '--help' in opts || 'help' in cmds
is_once: '--once' in opts
@ -37,9 +47,10 @@ fn init_settings() VpmSettings {
is_force: '-f' in opts || '--force' in opts
server_urls: cmdline.options(args, '--server-urls')
vcs: if '--hg' in opts { .hg } else { .git }
vmodules_path: os.vmodules_dir()
vmodules_path: vmodules_path
tmp_path: os.join_path(os.vtmp_dir(), 'vpm_modules')
no_dl_count_increment: os.getenv('CI') != '' || (no_inc_env != '' && no_inc_env != '0')
fail_on_prompt: os.getenv('VPM_FAIL_ON_PROMPT') != ''
logger: logger
}
}

View File

@ -20,6 +20,10 @@ fn main() {
// This tool is intended to be launched by the v frontend,
// which provides the path to V inside os.getenv('VEXE')
// args are: vpm [options] SUBCOMMAND module names
vpm_log_header('vpm start')
defer {
vpm_log_header('vpm exit')
}
params := cmdline.only_non_options(os.args[1..])
vpm_log(@FILE_LINE, @FN, 'params: ${params}')
if params.len < 1 {