Skip to content

Commit 92aa8b3

Browse files
LuKkssindresorhus
andauthored
Using logging instead of plain print() (#23)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent 30ebf8d commit 92aa8b3

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

linter.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sublime
44
import sublime_plugin
55
import subprocess
6+
import logging
67
from SublimeLinter.lint import (
78
NodeLinter,
89
linter as linter_module
@@ -12,6 +13,7 @@
1213
from SublimeLinter.lint.linter import PermanentError
1314
from SublimeLinter.lint.base_linter.node_linter import read_json_file
1415

16+
logger = logging.getLogger('SublimeLinter.plugin.xo')
1517

1618
STANDARD_SELECTOR = 'source.js'
1719
PLUGINS = {
@@ -103,10 +105,10 @@ def xo_fix(self, view, content):
103105
if encoding == 'Undefined':
104106
encoding = 'utf-8'
105107

106-
print('xo_fix -> content length:', len(content))
107-
print('xo_fix -> encoding:', encoding)
108-
print('xo_fix -> xo_env.PWD:', self.xo_env['PWD'])
109-
print('xo_fix -> xo_project_root:', self.xo_project_root)
108+
logger.info('xo_fix content length: %d', len(content))
109+
logger.info('xo_fix encoding: %s', encoding)
110+
logger.info('xo_fix xo_env.PWD: %s', self.xo_env['PWD'])
111+
logger.info('xo_fix xo_project_root: %s', self.xo_project_root)
110112

111113
# TODO: Change to use `subprocess.run()` when Sublime updates Python to 3.5 or later.
112114
proc = subprocess.Popen(
@@ -119,43 +121,43 @@ def xo_fix(self, view, content):
119121
startupinfo=startup_info,
120122
)
121123
stdout, stderr = proc.communicate(content)
122-
print('xo_fix -> stdout len:', len(stdout))
123-
print('xo_fix -> stderr len:', len(stderr))
124-
print('xo_fix -> stderr content:', stderr.decode(encoding))
125-
print('xo_fix -> returncode:', proc.returncode)
124+
logger.info('xo_fix stdout len: %d', len(stdout))
125+
logger.info('xo_fix stderr len: %d', len(stderr))
126+
logger.info('xo_fix stderr content: %s', stderr.decode(encoding))
127+
logger.info('xo_fix returncode: %d', proc.returncode)
126128

127129
if proc.returncode != 0:
128-
sublime.message_dialog("[xo_fix " + str(proc.returncode) + "] " + stderr.decode(encoding))
130+
sublime.message_dialog('[xo_fix ' + str(proc.returncode) + '] ' + stderr.decode(encoding))
129131
return None
130132

131133
return stdout.decode(encoding)
132134

133135
class XoFixCommand(sublime_plugin.TextCommand):
134136
def is_enabled(self):
135-
print('XoFixCommand -> is_enabled?')
137+
logger.info('XoFixCommand is_enabled?')
136138
linter = make_fake_linter(self.view)
137-
print('XoFixCommand -> project_root ->', linter.context.get('project_root'))
139+
logger.info('XoFixCommand project_root → %s', linter.context.get('project_root'))
138140

139141
self.xo_start_dir = linter.get_start_dir()
140-
print('XoFixCommand -> xo_start_dir', self.xo_start_dir)
142+
logger.info('XoFixCommand xo_start_dir %s', self.xo_start_dir)
141143
if not self.xo_start_dir:
142-
print('XoFixCommand -> xo_start_dir -> False')
144+
logger.info('XoFixCommand xo_start_dir False')
143145
return False
144146

145147
self.xo_path = linter.find_local_executable(self.xo_start_dir, 'xo')
146-
print('XoFixCommand -> xo_path', self.xo_path)
148+
logger.info('XoFixCommand xo_path %s', self.xo_path)
147149
if not self.xo_path:
148-
print('XoFixCommand -> xo_path -> False')
150+
logger.info('XoFixCommand xo_path False')
149151
return False
150152

151153
self.xo_project_root = linter.context.get('project_root')
152154
self.xo_env = os.environ.copy()
153155
self.xo_env['PWD'] = self.xo_project_root
154156
self.xo_env['PATH'] += os.pathsep + '/usr/local/bin' # Ensure correct PATH for Node.js on macOS
155157

156-
print('XoFixCommand -> environ.path ->', self.xo_env['PATH'])
157-
print('XoFixCommand -> project_root ->', self.xo_project_root)
158-
print('XoFixCommand -> return -> True')
158+
logger.info('XoFixCommand environ.path → %s', self.xo_env['PATH'])
159+
logger.info('XoFixCommand project_root → %s', self.xo_project_root)
160+
logger.info('XoFixCommand return True')
159161
return True
160162

161163
def run(self, edit):

0 commit comments

Comments
 (0)