030 / n3dr

Nexus3 Disaster Recovery (N3DR) is a tool that is capable of downloading all artifacts from a Nexus3 server and to migrate them to another one.
https://n3dr.releasesoftwaremoreoften.com/
MIT License
141 stars 37 forks source link

Logging changes (fine tuning) #270

Open 3eka opened 2 years ago

3eka commented 2 years ago

What would you like to be added: I would like to have an option to fine tune logging (like: INFO, WARN, ERROR, etc -- with NONE option too). Or, some errors I want to see on the screen (like ERROR), other can go into file (like INFO ones)

Why is this needed: Because, it is really annoying. Few examples:

++++++++++++++++++INFO[0240]/n3dr/internal/pkg/connection/connection.go:23 github.com/030/n3dr/internal/pkg/connection.(*Nexus3).Client() adding 'nexus' as a prefix to the basePath
*********++++++++++INFO[0240]/n3dr/internal/pkg/connection/connection.go:23 github.com/030/n3dr/internal/pkg/connection.(*Nexus3).Client() adding 'nexus' as a prefix to the basePath
*INFO[0240]/n3dr/internal/pkg/connection/connection.go:23 github.com/030/n3dr/internal/pkg/connection.(*Nexus3).Client() adding 'nexus' as a prefix to the basePath
*******+++++++++++++*++**INFO[0241]/n3dr/internal/pkg/connection/connection.go:23 github.com/030/n3dr/internal/pkg/connection.(*Nexus3).Client() adding 'nexus' as a prefix to the basePath
++++++INFO[0241]/n3dr/internal/pkg/connection/connection.go:23 github.com/030/n3dr/internal/pkg/connection.(*Nexus3).Client() adding 'nexus' as a prefix to the basePath
*********++++++++++INFO[0241]/n3dr/internal/pkg/connection/connection.go:23 github.com/030/n3dr/internal/pkg/connection.(*Nexus3).Client() adding 'nexus' as a prefix to the basePath
*INFO[0241]/n3dr/internal/pkg/connection/connection.go:23 github.com/030/n3dr/internal/pkg/connection.(*Nexus3).Client() adding 'nexus' as a prefix to the basePath
...

As you might see n3dr keeps repeating following, every time when it advances to the next item, which make it hard to follow:

:; n3dr --version
n3dr version 6.7.3
:; go version
go version go1.19.1 illumos/amd64
030 commented 1 year ago

6.8.0

030 commented 1 year ago

@3eka Did you try the logging option?

3eka commented 1 year ago

Tests done with version 6.8.1...

:; n3dr --help
...
      --logFile                       write the log to syslog
      --logLevel string               change the log level
...

Q1: Why --logFile goes to syslog (I would expect options, like syslog or /path/log_file_name.log)? Q2: Would be nice to display options for --logLevel (had to dig into code to find that info, debug and trace are allowed options)

  1. Using --basePathPrefix and --logLevel=info

    INFO[2022-11-04T16:15:36+01:00]/n3dr/cmd/n3dr/root.go:80 main.n3drHiddenHome() n3drHomeDir: '/export/home/predrag_zecevic/.n3dr'
    INFO 2022/11/04 16:15:36 trying to resolve absolute path path=/export/home/predrag_zecevic/.n3dr
    INFO 2022/11/04 16:15:36 adding path to search paths path=/export/home/predrag_zecevic/.n3dr
    INFO 2022/11/04 16:15:36 attempting to read in config file
    INFO 2022/11/04 16:15:36 searching for config in paths paths=[/export/home/predrag_zecevic/.n3dr]
    INFO[2022-11-04T16:15:36+01:00]/n3dr/cmd/n3dr/root.go:202 main.parseConfig() Using config file: '/export/home/predrag_zecevic/.n3dr/config.yml'
    INFO[2022-11-04T16:15:36+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'npm_group', 'group', npm
    ...
    INFO[2022-11-04T16:25:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'test-raw', 'hosted', raw
    *******%%++++++++++++++++++++++++++++++%+*+++++++*+**?*******?*??*?*?????+++????????+++++++++++++++++

    Timestamp output is not consolidated, but all seems OK (except legend what all those characters, displayed during backup means)

  2. Backup of second Nexus instance (no prefix) with --logLevel=info

    INFO[2022-11-04T16:30:10+01:00]/n3dr/cmd/n3dr/root.go:80 main.n3drHiddenHome() n3drHomeDir: '/export/home/predrag_zecevic/.n3dr'
    INFO 2022/11/04 16:30:10 trying to resolve absolute path path=/export/home/predrag_zecevic/.n3dr
    INFO 2022/11/04 16:30:10 adding path to search paths path=/export/home/predrag_zecevic/.n3dr
    INFO 2022/11/04 16:30:10 attempting to read in config file
    INFO 2022/11/04 16:30:10 searching for config in paths paths=[/export/home/predrag_zecevic/.n3dr]
    INFO[2022-11-04T16:30:10+01:00]/n3dr/cmd/n3dr/root.go:202 main.parseConfig() Using config file: '/export/home/predrag_zecevic/.n3dr/config.yml'
    INFO[2022-11-04T16:30:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'my-yum', 'hosted', yum
    INFO[2022-11-04T16:30:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'nuget-group', 'group', nuget
    INFO[2022-11-04T16:30:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'maven-snapshots', 'hosted', maven2
    INFO[2022-11-04T16:30:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'maven-central', 'proxy', maven2
    INFO[2022-11-04T16:30:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'nuget.org-proxy', 'proxy', nuget
    INFO[2022-11-04T16:30:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'maven-releases', 'hosted', maven2
    INFO[2022-11-04T16:30:10+01:00]/n3dr/internal/app/n3dr/artifactsv2/download.go:212 github.com/030/n3dr/internal/app/n3dr/artifactsv2.(*Nexus3).Backup() backing up 'my-docker', 'hosted', docker
    FATA[2022-11-04T16:30:10+01:00]/n3dr/cmd/n3dr/repositoriesV2.go:70 main.glob..func7() parse ":0/v2/_catalog": missing protocol scheme

    Died? But logging is OK (same notice as for above attempt is true)

There is no difference between debug and trace log levels. I have few observations: A) I would expect in either debug or trace log level explanation where and why it has died in more details (for example, I am not sure if it has died on my-docker backup or trying to fetch info for next one (in my case `my-raw repository) B) Specifying either log level (debug or trace) following is displayed on screen

DEBU[2022-11-04T16:31:55+01:00]/export/home/predrag_zecevic/go/pkg/mod/github.com/030/p2iwd@v0.2.0/internal/pkg/http/http.go:20 github.com/030/p2iwd/internal/pkg/http.(*Auth).RequestAndResponse() Auth: '&{Accept  GET PASSWORD_SHOWN_HERE! :0/v2/_catalog predrag_zecevic}'
FATA[2022-11-04T16:31:55+01:00]/n3dr/cmd/n3dr/repositoriesV2.go:70 main.glob..func7() parse ":0/v2/_catalog": missing protocol scheme

password is visible, should be masked.

Thanks for update. Best regards.

P.S. It seems that I still have 2 problems: Case 1) - it dies often after some period if running time w/o finishing job (maybe Nexus kicks it out, because it thinks someone is DDOS-ing?). Not so important, because if I repeat it several times, it finishes Case 2) - seems raw repository causes error "missing protocol schema"

This is my config file:

:; cat /export/home/predrag_zecevic/.n3dr/config.yml
removeLocalFile: true
030 commented 1 year ago

@3eka Could you create another issue to address "the raw repository and FATA[2022-11-04T16:30:10+01:00]/n3dr/cmd/n3dr/repositoriesV2.go:70 main.glob..func7() parse ":0/v2/_catalog": missing protocol scheme" issue?

030 commented 1 year ago

Example: n3dr repositoriesV2 --backup -u some-user -p some-pass -n localhost:9000 --https=false --directory-prefix /tmp/some-dir --dockerPort 9001 --dockerHost http://localhost --logFile some-file.log --logLevel trace --syslog

030 commented 1 year ago

7.0.0

3eka commented 1 year ago

Sorry, I have missed your latest update completely.

Let us focus on logging:

Thanks and regards

3eka commented 1 year ago

HI @030 ,

can you describe a bit logging logic?

I am expecting following:

I still have to check all logging level options Regards.