Skip to content

File logging #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 7, 2022
Merged

File logging #1053

merged 8 commits into from
Mar 7, 2022

Conversation

alex-courtis
Copy link
Member

Add the ability to log to a file. One file per nvim session is created.

Some logging has been added:

Configuration

  • default options merged with user
  • merged mappings

Git runner

  • git command
  • stderr and stdout
  • result: success, timeout or failure code

I have elected to put the logs in the user's home rather than /tmp, so that they don't forget about them. They may forget to turn logging off and many large files will accumulate.

@@ -100,11 +122,20 @@ function Runner.run(opts)
list_ignored = opts.list_ignored,
timeout = opts.timeout or 400,
output = {},
_done = false
rc = nil, -- -1 indicates timeout
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Care has been taken to not alter the functionality or flow of control here. _done -> rc is the only significant change.

function M.setup(opts)
M.config = opts.log
if M.config and M.config.enable and M.config.types then
M.path = string.format("%s/nvim-tree-%s-%s.log", vim.env.HOME, os.date("%H:%M:%S"), vim.env.USER)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time is enough to uniquely identify the file. Date is too long.

function M.setup(opts)
M.config = opts.log
if M.config and M.config.enable and M.config.types then
M.path = string.format("%s/nvim-tree-%s-%s.log", vim.env.HOME, os.date("%H:%M:%S"), vim.env.USER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we store that in vim.stdpath('data') ? I don't like programs not respecting XDG :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using vim.fn.stdpath("cache") which is where nvim, packer and lsp put their logs.

Also printed this path at startup so that the user is aware.

@alex-courtis
Copy link
Member Author

I would be grateful for a successful test (notably the git bits) by @gegoune and @kyazdani42 before we merge this. There are a lot of moving parts.

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work thanks !

@kyazdani42 kyazdani42 merged commit 19075f4 into nvim-tree:master Mar 7, 2022
Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
* add file logging infrastructure

* log git runner operations

* log configuration and mappings

* document file logging infrastructure

* style fixes

* stylua fixes

* document log file locations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants