Skip to content

Commit

Permalink
tools.vpm: debug-log to $VMODULES/cache/vpm.log if not running in d…
Browse files Browse the repository at this point in the history
…ebug mode (#21192)
  • Loading branch information
ttytm committed Apr 6, 2024
1 parent 31fdf58 commit 3a6cf5a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
8 changes: 6 additions & 2 deletions cmd/tools/vpm/common.v
Expand Up @@ -6,7 +6,6 @@ import net.urllib
import v.vmod
import json
import term
import log

struct ModuleVpmInfo {
// id int
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 16 additions & 5 deletions cmd/tools/vpm/settings.v
Expand Up @@ -19,27 +19,38 @@ 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
is_verbose: '-v' in opts || '--verbose' in opts
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
}
}
4 changes: 4 additions & 0 deletions cmd/tools/vpm/vpm.v
Expand Up @@ -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 {
Expand Down

0 comments on commit 3a6cf5a

Please sign in to comment.