mirror of
https://github.com/beetbox/beets.git
synced 2025-12-16 05:34:47 +01:00
use logger module
--HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40132
This commit is contained in:
parent
b6345fdd5d
commit
e52f0aaaf1
2 changed files with 17 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import sqlite3, os, sys, operator, re, shutil
|
||||
from beets.mediafile import MediaFile, FileTypeError
|
||||
from string import Template
|
||||
import logging
|
||||
|
||||
# Fields in the "items" table; all the metadata available for items in the
|
||||
# library. These are used directly in SQL; they are vulnerable to injection if
|
||||
|
|
@ -44,6 +45,12 @@ library_options = {
|
|||
'path_format': u'$artist/$album/$track $title.$extension',
|
||||
}
|
||||
|
||||
# Logger.
|
||||
|
||||
log = logging.getLogger('beets')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(logging.StreamHandler())
|
||||
|
||||
|
||||
#### exceptions ####
|
||||
|
||||
|
|
@ -60,10 +67,6 @@ def _normpath(path):
|
|||
database."""
|
||||
return os.path.normpath(os.path.abspath(os.path.expanduser(path)))
|
||||
|
||||
def _log(msg):
|
||||
"""Print a log message."""
|
||||
print >>sys.stderr, msg
|
||||
|
||||
def _ancestry(path):
|
||||
"""Return a list consisting of path's parent directory, its grandparent,
|
||||
and so on. For instance, _ancestry('/a/b/c') == ['/', '/a', '/a/b']."""
|
||||
|
|
@ -609,7 +612,7 @@ class Library(object):
|
|||
i.move(copy=True)
|
||||
i.add()
|
||||
except FileTypeError:
|
||||
_log(f + ' of unknown type, skipping')
|
||||
log.warn(f + ' of unknown type, skipping')
|
||||
|
||||
def get(self, query=None):
|
||||
"""Returns a ResultIterator to the items matching query, which may be
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import eventlet.api
|
|||
import re
|
||||
from string import Template
|
||||
import beets
|
||||
import sys
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
|
||||
DEFAULT_PORT = 6600
|
||||
|
|
@ -44,8 +44,11 @@ VOLUME_MIN = 0
|
|||
VOLUME_MAX = 100
|
||||
|
||||
|
||||
def debug(msg):
|
||||
print >>sys.stderr, msg
|
||||
# Logger.
|
||||
log = logging.getLogger('bpd')
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.addHandler(logging.StreamHandler())
|
||||
|
||||
|
||||
class BPDError(Exception):
|
||||
"""An error that should be exposed to the client to the BPD
|
||||
|
|
@ -420,7 +423,7 @@ class Connection(object):
|
|||
else: # Passed an iterable of strings (for instance, a Response).
|
||||
out = NEWLINE.join(data) + NEWLINE
|
||||
|
||||
debug(out)
|
||||
log.debug(out)
|
||||
self.client.sendall(out)
|
||||
|
||||
line_re = re.compile(r'([^\r\n]*)(?:\r\n|\n\r|\n|\r)')
|
||||
|
|
@ -450,7 +453,7 @@ class Connection(object):
|
|||
|
||||
clist = None # Initially, no command list is being constructed.
|
||||
for line in self.lines():
|
||||
debug(line)
|
||||
log.debug(line)
|
||||
|
||||
if clist is not None:
|
||||
# Command list already opened.
|
||||
|
|
@ -516,7 +519,7 @@ class Command(object):
|
|||
|
||||
except Exception, e:
|
||||
# An "unintentional" error. Hide it from the client.
|
||||
debug(traceback.format_exc(e))
|
||||
l.error(traceback.format_exc(e))
|
||||
return ErrorResponse(ERROR_SYSTEM, self.name, 'server error')
|
||||
|
||||
if response is None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue