[Checkins] SVN: z3c.rml/trunk/ Implemented all logging directives.
Stephen Richter
cvs-admin at zope.org
Fri Dec 21 04:27:58 UTC 2012
Log message for revision 128840:
Implemented all logging directives.
Changed:
U z3c.rml/trunk/CHANGES.txt
U z3c.rml/trunk/RML-DIFFERENCES.txt
U z3c.rml/trunk/src/z3c/rml/attr.py
U z3c.rml/trunk/src/z3c/rml/document.py
U z3c.rml/trunk/src/z3c/rml/flowable.py
U z3c.rml/trunk/src/z3c/rml/interfaces.py
A z3c.rml/trunk/src/z3c/rml/tests/expected/tag-log.pdf
A z3c.rml/trunk/src/z3c/rml/tests/input/tag-log.rml
U z3c.rml/trunk/src/z3c/rml/tests/test_rml.py
-=-
Modified: z3c.rml/trunk/CHANGES.txt
===================================================================
--- z3c.rml/trunk/CHANGES.txt 2012-12-21 03:03:18 UTC (rev 128839)
+++ z3c.rml/trunk/CHANGES.txt 2012-12-21 04:27:57 UTC (rev 128840)
@@ -54,6 +54,8 @@
- Added ``pageLayout`` and ``pageMode`` to ``docInit`` directive.
+- Implemented all logging related directives.
+
- Don't show "doc" namespace in reference snippets.
- Create a list of RML2PDF and z3c.rml differences.
Modified: z3c.rml/trunk/RML-DIFFERENCES.txt
===================================================================
--- z3c.rml/trunk/RML-DIFFERENCES.txt 2012-12-21 03:03:18 UTC (rev 128839)
+++ z3c.rml/trunk/RML-DIFFERENCES.txt 2012-12-21 04:27:57 UTC (rev 128840)
@@ -115,19 +115,5 @@
- length
-- log
-
-- debug
-
-- info
-
-- warning
-
-- error
-
-- critical
-
-- logConfig
-
- -pdfInclude
Modified: z3c.rml/trunk/src/z3c/rml/attr.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/attr.py 2012-12-21 03:03:18 UTC (rev 128839)
+++ z3c.rml/trunk/src/z3c/rml/attr.py 2012-12-21 04:27:57 UTC (rev 128840)
@@ -201,6 +201,10 @@
if isinstance(choices, (tuple, list)):
choices = dict(
[(val.lower() if doLower else val, val) for val in choices])
+ else:
+ choices = dict(
+ [(key.lower() if doLower else key, val)
+ for key, val in choices.items()])
self.choices = choices
self.doLower = doLower
Modified: z3c.rml/trunk/src/z3c/rml/document.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/document.py 2012-12-21 03:03:18 UTC (rev 128839)
+++ z3c.rml/trunk/src/z3c/rml/document.py 2012-12-21 04:27:57 UTC (rev 128840)
@@ -17,6 +17,7 @@
"""
__docformat__ = "reStructuredText"
import cStringIO
+import logging
import sys
import zope.interface
import reportlab.pdfgen.canvas
@@ -28,6 +29,7 @@
from z3c.rml import occurence, pdfinclude, special, storyplace, stylesheet
from z3c.rml import template
+LOGGER_NAME = 'z3c.rml.render'
class IRegisterType1Face(interfaces.IRMLDirectiveSignature):
"""Register a new Type 1 font face."""
@@ -349,6 +351,55 @@
setattr(cmp, name, value)
self.parent.parent.cropMarks = cmp
+class ILogConfig(interfaces.IRMLDirectiveSignature):
+ """Configure the render logger."""
+
+ level = attr.Choice(
+ title=u'Level',
+ description=u'The default log level.',
+ choices=interfaces.LOG_LEVELS,
+ doLower=False,
+ required=False)
+
+ format = attr.String(
+ title=u'Format',
+ description=u'The format of the log messages.',
+ required=False)
+
+ filename = attr.File(
+ title=u'File Name',
+ description=u'The path to the file that is being logged.',
+ doNotOpen=True,
+ required=True)
+
+ filemode = attr.Choice(
+ title=u'File Mode',
+ description=u'The mode to open the file in.',
+ choices={'WRITE': 'w', 'APPEND': 'a'},
+ default='a',
+ required=False)
+
+ datefmt = attr.String(
+ title=u'Date Format',
+ description=u'The format of the log message date.',
+ required=False)
+
+class LogConfig(directive.RMLDirective):
+ signature = ILogConfig
+
+ def process(self):
+ args = dict(self.getAttributeValues())
+ logger = logging.Logger(LOGGER_NAME)
+ handler = logging.FileHandler(args['filename'], args['filemode'])
+ formatter = logging.Formatter(
+ args.get('format'), args.get('datefmt'))
+ handler.setFormatter(formatter)
+ logger.addHandler(handler)
+ if 'level' in args:
+ logger.setLevel(args['level'])
+ self.parent.parent.logger = logger
+
+
class IDocInit(interfaces.IRMLDirectiveSignature):
occurence.containing(
occurence.ZeroOrMore('color', IColorDefinition),
@@ -359,6 +410,7 @@
occurence.ZeroOrMore('registerTTFont', IRegisterTTFont),
occurence.ZeroOrMore('registerFontFamily', IRegisterFontFamily),
occurence.ZeroOrMore('addMapping', IAddMapping),
+ occurence.ZeroOrMore('logConfig', ILogConfig),
occurence.ZeroOrMore('cropMarks', ICropMarks),
occurence.ZeroOrMore('startIndex', IStartIndex),
)
@@ -393,6 +445,7 @@
'registerTTFont': RegisterTTFont,
'registerCidFont': RegisterCidFont,
'addMapping': AddMapping,
+ 'logConfig': LogConfig,
'cropMarks': CropMarks,
'startIndex': StartIndex,
}
@@ -465,6 +518,7 @@
self.cropMarks = False
self.pageLayout = None
self.pageMode = None
+ self.logger = None
def _indexAdd(self, canvas, name, label):
self.indexes[name](canvas, name, label)
Modified: z3c.rml/trunk/src/z3c/rml/flowable.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/flowable.py 2012-12-21 03:03:18 UTC (rev 128839)
+++ z3c.rml/trunk/src/z3c/rml/flowable.py 2012-12-21 04:27:57 UTC (rev 128840)
@@ -17,6 +17,7 @@
"""
__docformat__ = "reStructuredText"
import copy
+import logging
import re
import reportlab.lib.styles
import reportlab.platypus
@@ -1333,6 +1334,95 @@
self.parent.flow.append(index)
+class IBaseLogCall(interfaces.IRMLDirectiveSignature):
+
+ message = attr.RawXMLContent(
+ title=u'Message',
+ description=u'The message to be logged.',
+ required=True)
+
+class LogCallFlowable(reportlab.platypus.flowables.Flowable):
+
+ def __init__(self, logger, level, message):
+ self.logger = logger
+ self.level = level
+ self.message = message
+
+ def wrap(self, *args):
+ return (0, 0)
+
+ def draw(self):
+ self.logger.log(self.level, self.message)
+
+class BaseLogCall(directive.RMLDirective):
+ signature = IBaseLogCall
+ level = None
+
+ def process(self):
+ message = self.getAttributeValues(
+ select=('message',), valuesOnly=True)[0]
+ manager = attr.getManager(self)
+ self.parent.flow.append(
+ LogCallFlowable(manager.logger, self.level, message))
+
+class ILog(IBaseLogCall):
+ """Log message at DEBUG level."""
+
+ level = attr.Choice(
+ title=u'Level',
+ description=u'The default log level.',
+ choices=interfaces.LOG_LEVELS,
+ doLower=False,
+ default=logging.INFO,
+ required=True)
+
+class Log(BaseLogCall):
+ signature = ILog
+
+ @property
+ def level(self):
+ return self.getAttributeValues(select=('level',), valuesOnly=True)[0]
+
+class IDebug(IBaseLogCall):
+ """Log message at DEBUG level."""
+
+class Debug(BaseLogCall):
+ signature = IDebug
+ level = logging.DEBUG
+
+
+class IInfo(IBaseLogCall):
+ """Log message at INFO level."""
+
+class Info(BaseLogCall):
+ signature = IInfo
+ level = logging.INFO
+
+
+class IWarning(IBaseLogCall):
+ """Log message at WARNING level."""
+
+class Warning(BaseLogCall):
+ signature = IWarning
+ level = logging.WARNING
+
+
+class IError(IBaseLogCall):
+ """Log message at ERROR level."""
+
+class Error(BaseLogCall):
+ signature = IError
+ level = logging.ERROR
+
+
+class ICritical(IBaseLogCall):
+ """Log message at CRITICAL level."""
+
+class Critical(BaseLogCall):
+ signature = ICritical
+ level = logging.CRITICAL
+
+
class IFlow(interfaces.IRMLDirectiveSignature):
"""A list of flowables."""
occurence.containing(
@@ -1372,6 +1462,12 @@
occurence.ZeroOrMore('showIndex', IShowIndex),
occurence.ZeroOrMore('name', special.IName),
occurence.ZeroOrMore('namedString', INamedString),
+ occurence.ZeroOrMore('log', ILog),
+ occurence.ZeroOrMore('debug', IDebug),
+ occurence.ZeroOrMore('info', IInfo),
+ occurence.ZeroOrMore('warning', IWarning),
+ occurence.ZeroOrMore('error', IError),
+ occurence.ZeroOrMore('critical', ICritical),
)
class Flow(directive.RMLDirective):
@@ -1418,6 +1514,13 @@
# Special Elements
'name': special.Name,
'namedString': NamedString,
+ # Logging
+ 'log': Log,
+ 'debug': Debug,
+ 'info': Info,
+ 'warning': Warning,
+ 'error': Error,
+ 'critical': Critical,
}
def __init__(self, *args, **kw):
Modified: z3c.rml/trunk/src/z3c/rml/interfaces.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/interfaces.py 2012-12-21 03:03:18 UTC (rev 128839)
+++ z3c.rml/trunk/src/z3c/rml/interfaces.py 2012-12-21 04:27:57 UTC (rev 128840)
@@ -14,6 +14,7 @@
"""RML to PDF Converter Interfaces
"""
__docformat__ = "reStructuredText"
+import logging
import reportlab.lib.enums
import zope.interface
import zope.schema
@@ -38,6 +39,12 @@
LIST_FORMATS = ('I', 'i', '123', 'ABC', 'abc')
ORDERED_LIST_TYPES = ('I', 'i', '1', 'A', 'a')
UNORDERED_BULLET_VALUES = ('circle', 'square', 'disc', 'diamond', 'rarrowhead')
+LOG_LEVELS = {
+ 'DEBUG': logging.DEBUG,
+ 'INFO': logging.INFO,
+ 'WARNING': logging.WARNING,
+ 'ERROR': logging.ERROR,
+ 'CRITICAL': logging.CRITICAL}
class IRML2PDF(zope.interface.Interface):
"""This is the main public API of z3c.rml"""
Added: z3c.rml/trunk/src/z3c/rml/tests/expected/tag-log.pdf
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/expected/tag-log.pdf (rev 0)
+++ z3c.rml/trunk/src/z3c/rml/tests/expected/tag-log.pdf 2012-12-21 04:27:57 UTC (rev 128840)
@@ -0,0 +1,107 @@
+%PDF-1.4
+% ReportLab Generated PDF document http://www.reportlab.com
+% 'BasicFonts': class PDFDictionary
+1 0 obj
+% The standard fonts dictionary
+<< /F1 2 0 R
+ /F2 3 0 R >>
+endobj
+% 'F1': class PDFType1Font
+2 0 obj
+% Font Helvetica
+<< /BaseFont /Helvetica
+ /Encoding /WinAnsiEncoding
+ /Name /F1
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+% 'F2': class PDFType1Font
+3 0 obj
+% Font Helvetica-Bold
+<< /BaseFont /Helvetica-Bold
+ /Encoding /WinAnsiEncoding
+ /Name /F2
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+% 'Page1': class PDFPage
+4 0 obj
+% Page dictionary
+<< /Contents 8 0 R
+ /MediaBox [ 0
+ 0
+ 595.2756
+ 841.8898 ]
+ /Parent 7 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans << >>
+ /Type /Page >>
+endobj
+% 'R5': class PDFCatalog
+5 0 obj
+% Document Root
+<< /Outlines 9 0 R
+ /PageMode /UseNone
+ /Pages 7 0 R
+ /Type /Catalog >>
+endobj
+% 'R6': class PDFInfo
+6 0 obj
+<< /Author (\(anonymous\))
+ /CreationDate (D:20121220232518+05'00')
+ /Creator (\(unspecified\))
+ /Keywords ()
+ /Producer (ReportLab PDF Library - www.reportlab.com)
+ /Subject (\(unspecified\))
+ /Title (\(anonymous\)) >>
+endobj
+% 'R7': class PDFPages
+7 0 obj
+% page tree
+<< /Count 1
+ /Kids [ 4 0 R ]
+ /Type /Pages >>
+endobj
+% 'R8': class PDFStream
+8 0 obj
+% page stream
+<< /Filter [ /ASCII85Decode
+ /FlateDecode ]
+ /Length 234 >>
+stream
+Gb!<E9b)b/&;Bj(gu0j4`56Ug$X49HZ-]9_0T(iZr*+Go9,1=a"\^<"ba\'JKZlXfs1/<p(26Jc$+g?iTjSg=2NBCukSa+61+X<5M4 at 1DqVr.Vp[gdu8/G+I".Jo0/A/#NZ<4XQ1kFK#:4m(;baV3?JsB at T7^:lVnXpdc?W,EIdoq?\?71As8gU:\m.Y[UUcCHE4$$?M<HgX66\X3+Ci&aM%\'`KT4SX)GAm[q'*~>endstream
+endobj
+% 'R9': class PDFOutlines
+9 0 obj
+<< /Count 0
+ /Type /Outlines >>
+endobj
+xref
+0 10
+0000000000 65535 f
+0000000113 00000 n
+0000000221 00000 n
+0000000386 00000 n
+0000000559 00000 n
+0000000836 00000 n
+0000000970 00000 n
+0000001239 00000 n
+0000001344 00000 n
+0000001720 00000 n
+trailer
+<< /ID
+ % ReportLab generated PDF document -- digest (http://www.reportlab.com)
+ [(\322\013\316\213\253\363\234\225\322\007\025*\276w\3376) (\322\013\316\213\253\363\234\225\322\007\025*\276w\3376)]
+
+ /Info 6 0 R
+ /Root 5 0 R
+ /Size 10 >>
+startxref
+1771
+%%EOF
Added: z3c.rml/trunk/src/z3c/rml/tests/input/tag-log.rml
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/input/tag-log.rml (rev 0)
+++ z3c.rml/trunk/src/z3c/rml/tests/input/tag-log.rml 2012-12-21 04:27:57 UTC (rev 128840)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
+<!DOCTYPE document SYSTEM "rml.dtd">
+
+<document
+ filename="tag-log.pdf"
+ xmlns:doc="http://namespaces.zope.org/rml/doc">
+ <docinit>
+ <logConfig
+ level="DEBUG"
+ format="%(asctime)s %(levelname)s - %(message)s"
+ datefmt="%Y-%m-%dT%H:%M:%S"
+ filename="[z3c.rml.tests]/render.log"
+ filemode="APPEND"
+ doc:example=""
+ />
+ </docinit>
+ <template>
+ <pageTemplate id="main">
+ <frame id="first" x1="1cm" y1="1cm" width="19cm" height="26cm"/>
+
+ <pageGraphics>
+ <place x="0.5cm" y="0.5cm" width="10cm" height="1cm">
+ <para>Page <pageNumber /></para>
+ </place>
+ </pageGraphics>
+
+ </pageTemplate>
+ </template>
+ <story>
+ <title>Logging Example</title>
+
+ <log level="WARNING" doc:example="">Log message with level WARNING.</log>
+ <debug doc:example="">A DEBUG message</debug>
+ <info doc:example="">A INFO message</info>
+ <warning doc:example="">A WARNING message</warning>
+ <error doc:example="">A ERROR message</error>
+ <critical doc:example="">A CRITICAL message</critical>
+ </story>
+</document>
Modified: z3c.rml/trunk/src/z3c/rml/tests/test_rml.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/test_rml.py 2012-12-21 03:03:18 UTC (rev 128839)
+++ z3c.rml/trunk/src/z3c/rml/tests/test_rml.py 2012-12-21 04:27:57 UTC (rev 128840)
@@ -60,7 +60,10 @@
attr.File.open = self._fileOpen
del sys.modules['module']
del sys.modules['mymodule']
+ os.remove(
+ os.path.join(os.path.dirname(__file__), 'render.log'))
+
def runTest(self):
rml2pdf.go(self._inPath, self._outPath)
More information about the checkins
mailing list