Skip to content

Commit cb23953

Browse files
committed
logging: use predictable log file names
1 parent b8bb7c2 commit cb23953

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ You can run the plugin host in nvim with logging enabled to debug errors:
145145
NVIM_PYTHON_LOG_FILE=logfile NVIM_PYTHON_LOG_LEVEL=DEBUG nvim
146146
```
147147
As more than one python host process might be started, the log filenames take
148-
the pattern `logfile_PID` where `PID` is the process id.
148+
the pattern `logfile_pyX_KIND` where `X` is the major python version (2 or 3)
149+
and `KIND` is either "rplugin" or "script" (for the `:python[3]`
150+
script interface).
149151

150152
If the host cannot start at all, the error could be found in `~/.nvimlog` if
151153
`nvim` was compiled with logging.

neovim/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ def start_host(session=None):
5353
if os.path.isdir(path) and dup in plugins:
5454
plugins.remove(dup)
5555

56-
setup_logging()
56+
# Special case: the legacy scripthost receives a single relative filename
57+
# while the rplugin host will receive absolute paths.
58+
if plugins == ["script_host.py"]:
59+
name = "script"
60+
else:
61+
name = "rplugin"
62+
63+
setup_logging(name)
5764

5865
if not session:
5966
session = stdio_session()
@@ -94,12 +101,13 @@ def attach(session_type, address=None, port=None,
94101
return Nvim.from_session(session).with_decode(decode)
95102

96103

97-
def setup_logging():
104+
def setup_logging(name):
98105
"""Setup logging according to environment variables."""
99106
logger = logging.getLogger(__name__)
100107
if 'NVIM_PYTHON_LOG_FILE' in os.environ:
101-
logfile = (os.environ['NVIM_PYTHON_LOG_FILE'].strip() +
102-
'_' + str(os.getpid()))
108+
prefix = os.environ['NVIM_PYTHON_LOG_FILE'].strip()
109+
major_version = sys.version_info[0]
110+
logfile = '{0}_py{1}_{2}'.format(prefix, major_version, name)
103111
handler = logging.FileHandler(logfile, 'w')
104112
handler.formatter = logging.Formatter(
105113
'%(asctime)s [%(levelname)s @ '

test/test_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from nose.tools import eq_ as eq
88

9-
neovim.setup_logging()
9+
neovim.setup_logging("test")
1010

1111
child_argv = os.environ.get('NVIM_CHILD_ARGV')
1212
listen_address = os.environ.get('NVIM_LISTEN_ADDRESS')

0 commit comments

Comments
 (0)