docs/Bovem/Logger.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Class: Bovem::Logger
— Documentation by YARD 0.9.7
</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
pathId = "Bovem::Logger";
relpath = '../';
</script>
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../_index.html">Index (L)</a> »
<span class='title'><span class='object_link'><a href="../Bovem.html" title="Bovem (module)">Bovem</a></span></span>
»
<span class="title">Logger</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><h1>Class: Bovem::Logger
</h1>
<div class="box_info">
<dl>
<dt>Inherits:</dt>
<dd>
<span class="inheritName">Logger</span>
<ul class="fullTree">
<li>Object</li>
<li class="next">Logger</li>
<li class="next">Bovem::Logger</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/bovem/logger.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>A custom logger.</p>
</div>
</div>
<div class="tags">
</div>
<h2>Constant Summary</h2>
<dl class="constants">
<dt id="LEVEL_NAMES-constant" class="">LEVEL_NAMES =
<div class="docstring">
<div class="discussion">
<p>List of valid logger levels.</p>
</div>
</div>
<div class="tags">
</div>
</dt>
<dd><pre class="code"><span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>DEBUG</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:cyan</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>INFO</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:green</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>WARN</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:yellow</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ERROR</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:red</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>FATAL</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:magenta</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
</dl>
<h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#device-instance_method" title="#device (instance method)">#<strong>device</strong> ⇒ IO|String </a>
</span>
<span class="note title readonly">readonly</span>
<span class="summary_desc"><div class='inline'><p>The file or device to log messages to.</p>
</div></span>
</li>
</ul>
<h2>
Class Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#create-class_method" title="create (class method)">.<strong>create</strong>(file = nil, level: Logger::INFO, formatter: nil) ⇒ Logger </a>
</span>
<span class="summary_desc"><div class='inline'><p>Creates a new logger.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#default_file-class_method" title="default_file (class method)">.<strong>default_file</strong> ⇒ String|IO </a>
</span>
<span class="summary_desc"><div class='inline'><p>The default file for logging.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#default_formatter-class_method" title="default_formatter (class method)">.<strong>default_formatter</strong> ⇒ Proc </a>
</span>
<span class="summary_desc"><div class='inline'><p>The default formatter for logging.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#get_real_file-class_method" title="get_real_file (class method)">.<strong>get_real_file</strong>(file) ⇒ String|IO </a>
</span>
<span class="summary_desc"><div class='inline'><p>Translates a file to standard input or standard output in some special cases.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#start_time-class_method" title="start_time (class method)">.<strong>start_time</strong> ⇒ Time </a>
</span>
<span class="summary_desc"><div class='inline'><p>The log time of the first logger.</p>
</div></span>
</li>
</ul>
<h2>
Instance Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(logdev, shift_age = 0, shift_size = 1_048_576) ⇒ Logger </a>
</span>
<span class="note title constructor">constructor</span>
<span class="summary_desc"><div class='inline'><p>Creates a new logger.</p>
</div></span>
</li>
</ul>
<div id="constructor_details" class="method_details_list">
<h2>Constructor Details</h2>
<div class="method_details first">
<h3 class="signature first" id="initialize-instance_method">
#<strong>initialize</strong>(logdev, shift_age = 0, shift_size = 1_048_576) ⇒ <tt><span class='object_link'><a href="" title="Bovem::Logger (class)">Logger</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Creates a new logger.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>logdev</span>
<span class='type'>(<tt>String|IO</tt>)</span>
—
<div class='inline'><p>The log device. This is a filename (String) or IO object (typically STDOUT, STDERR, or an open file).</p>
</div>
</li>
<li>
<span class='name'>shift_age</span>
<span class='type'>(<tt>Fixnum</tt>)</span>
<em class="default">(defaults to: <tt>0</tt>)</em>
—
<div class='inline'><p>Number of old log files to keep, or frequency of rotation (daily, weekly or monthly).</p>
</div>
</li>
<li>
<span class='name'>shift_size</span>
<span class='type'>(<tt>Fixnum</tt>)</span>
<em class="default">(defaults to: <tt>1_048_576</tt>)</em>
—
<div class='inline'><p>Maximum logfile size (only applies when shift_age is a number).</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html" target="_parent" title="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html">http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html</a></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
25
26
27
28</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/logger.rb', line 25</span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_logdev'>logdev</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_age'>shift_age</span> <span class='op'>=</span> <span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_size'>shift_size</span> <span class='op'>=</span> <span class='int'>1_048_576</span><span class='rparen'>)</span>
<span class='ivar'>@device</span> <span class='op'>=</span> <span class='id identifier rubyid_logdev'>logdev</span>
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_logdev'>logdev</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_age'>shift_age</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_size'>shift_size</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="instance_attr_details" class="attr_details">
<h2>Instance Attribute Details</h2>
<span id=""></span>
<div class="method_details first">
<h3 class="signature first" id="device-instance_method">
#<strong>device</strong> ⇒ <tt>IO|String</tt> <span class="extras">(readonly)</span>
</h3><div class="docstring">
<div class="discussion">
<p>Returns The file or device to log messages to.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>IO|String</tt>)</span>
—
<div class='inline'><p>The file or device to log messages to.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/logger.rb', line 12</span>
<span class='kw'>class</span> <span class='const'><span class='object_link'><a href="" title="Bovem::Logger (class)">Logger</a></span></span> <span class='op'><</span> <span class='op'>::</span><span class='const'>Logger</span>
<span class='id identifier rubyid_attr_reader'>attr_reader</span> <span class='symbol'>:device</span>
<span class='comment'># List of valid logger levels.
</span> <span class='const'><span class='object_link'><a href="#LEVEL_NAMES-constant" title="Bovem::Logger::LEVEL_NAMES (constant)">LEVEL_NAMES</a></span></span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>DEBUG</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:cyan</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>INFO</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:green</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>WARN</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:yellow</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ERROR</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:red</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>FATAL</span><span class='tstring_end'>"</span></span> <span class='op'>=></span> <span class='symbol'>:magenta</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span>
<span class='comment'># Creates a new logger.
</span> <span class='comment'>#
</span> <span class='comment'># @see http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html
</span> <span class='comment'>#
</span> <span class='comment'># @param logdev [String|IO] The log device. This is a filename (String) or IO object (typically STDOUT, STDERR, or an open file).
</span> <span class='comment'># @param shift_age [Fixnum] Number of old log files to keep, or frequency of rotation (daily, weekly or monthly).
</span> <span class='comment'># @param shift_size [Fixnum] Maximum logfile size (only applies when shift_age is a number).
</span> <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_logdev'>logdev</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_age'>shift_age</span> <span class='op'>=</span> <span class='int'>0</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_size'>shift_size</span> <span class='op'>=</span> <span class='int'>1_048_576</span><span class='rparen'>)</span>
<span class='ivar'>@device</span> <span class='op'>=</span> <span class='id identifier rubyid_logdev'>logdev</span>
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_logdev'>logdev</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_age'>shift_age</span><span class='comma'>,</span> <span class='id identifier rubyid_shift_size'>shift_size</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='comment'># Creates a new logger.
</span> <span class='comment'>#
</span> <span class='comment'># @param file [String|IO] The log device. This is a filename (String) or IO object (typically STDOUT, STDERR, or an open file).
</span> <span class='comment'># @param level [Fixnum] The minimum severity to log. See http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html for valid levels.
</span> <span class='comment'># @param formatter [Proc] The formatter to use for logging.
</span> <span class='comment'># @return [Logger] The new logger.
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>level:</span> <span class='const'><span class='object_link'><a href="" title="Bovem::Logger (class)">Logger</a></span></span><span class='op'>::</span><span class='const'>INFO</span><span class='comma'>,</span> <span class='label'>formatter:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_get_real_file'>get_real_file</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span> <span class='op'>||</span> <span class='id identifier rubyid_default_file'>default_file</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_level'>level</span> <span class='op'>=</span> <span class='id identifier rubyid_level'>level</span><span class='period'>.</span><span class='id identifier rubyid_to_integer'>to_integer</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_formatter'>formatter</span> <span class='op'>=</span> <span class='id identifier rubyid_formatter'>formatter</span> <span class='op'>||</span> <span class='id identifier rubyid_default_formatter'>default_formatter</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>rescue</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Errors.html" title="Bovem::Errors (module)">Errors</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Errors/InvalidLogger.html" title="Bovem::Errors::InvalidLogger (class)">InvalidLogger</a></span></span>
<span class='kw'>end</span>
<span class='comment'># Translates a file to standard input or standard output in some special cases.
</span> <span class='comment'>#
</span> <span class='comment'># @param file [String] The string to translate.
</span> <span class='comment'># @return [String|IO] The translated file name.
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_get_real_file'>get_real_file</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='rparen'>)</span>
<span class='kw'>case</span> <span class='id identifier rubyid_file'>file</span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>STDOUT</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='gvar'>$stdout</span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>STDERR</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='gvar'>$stderr</span>
<span class='kw'>else</span> <span class='id identifier rubyid_file'>file</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># The default file for logging.
</span> <span class='comment'># @return [String|IO] The default file for logging.
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_default_file'>default_file</span>
<span class='ivar'>@default_file</span> <span class='op'>||=</span> <span class='gvar'>$stdout</span>
<span class='kw'>end</span>
<span class='comment'># The default formatter for logging.
</span> <span class='comment'># @return [Proc] The default formatter for logging.
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_default_formatter'>default_formatter</span>
<span class='ivar'>@default_formatter</span> <span class='op'>||=</span> <span class='op'>::</span><span class='const'>Proc</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_severity'>severity</span><span class='comma'>,</span> <span class='id identifier rubyid_datetime'>datetime</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='comma'>,</span> <span class='id identifier rubyid_msg'>msg</span><span class='op'>|</span>
<span class='id identifier rubyid_color'>color</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="#LEVEL_NAMES-constant" title="Bovem::Logger::LEVEL_NAMES (constant)">LEVEL_NAMES</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='id identifier rubyid_severity'>severity</span><span class='comma'>,</span> <span class='symbol'>:white</span><span class='rparen'>)</span>
<span class='id identifier rubyid_header'>header</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Console.html" title="Bovem::Console (class)">Console</a></span></span><span class='period'>.</span><span class='id identifier rubyid_replace_markers'><span class='object_link'><a href="ConsoleMethods/StyleHandling.html#replace_markers-instance_method" title="Bovem::ConsoleMethods::StyleHandling#replace_markers (method)">replace_markers</a></span></span><span class='lparen'>(</span>
<span class='id identifier rubyid_sprintf'>sprintf</span><span class='lparen'>(</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>{mark=bright-</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_color'>color</span><span class='embexpr_end'>}</span><span class='tstring_content'>}[%s T+%0.5f] %s:{/mark}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_datetime'>datetime</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%Y/%b/%d %H:%M:%S</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_datetime'>datetime</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span> <span class='op'>-</span> <span class='id identifier rubyid_start_time'>start_time</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='comma'>,</span> <span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span><span class='comma'>,</span> <span class='id identifier rubyid_severity'>severity</span><span class='period'>.</span><span class='id identifier rubyid_rjust'>rjust</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span>
<span class='rparen'>)</span>
<span class='rparen'>)</span>
<span class='id identifier rubyid_sprintf'>sprintf</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%s %s\n</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_header'>header</span><span class='comma'>,</span> <span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='comment'># The log time of the first logger. This allows to show a `T+0.1234` information into the log.
</span> <span class='comment'># @return [Time] The log time of the first logger.
</span> <span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_start_time'>start_time</span>
<span class='ivar'>@start_time</span> <span class='op'>||=</span> <span class='op'>::</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
<div id="class_method_details" class="method_details_list">
<h2>Class Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="create-class_method">
.<strong>create</strong>(file = nil, level: Logger::INFO, formatter: nil) ⇒ <tt><span class='object_link'><a href="" title="Bovem::Logger (class)">Logger</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Creates a new logger.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>file</span>
<span class='type'>(<tt>String|IO</tt>)</span>
<em class="default">(defaults to: <tt>nil</tt>)</em>
—
<div class='inline'><p>The log device. This is a filename (String) or IO object (typically STDOUT, STDERR, or an open file).</p>
</div>
</li>
<li>
<span class='name'>level</span>
<span class='type'>(<tt>Fixnum</tt>)</span>
—
<div class='inline'><p>The minimum severity to log. See http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html for valid levels.</p>
</div>
</li>
<li>
<span class='name'>formatter</span>
<span class='type'>(<tt>Proc</tt>)</span>
—
<div class='inline'><p>The formatter to use for logging.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="" title="Bovem::Logger (class)">Logger</a></span></tt>)</span>
—
<div class='inline'><p>The new logger.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
36
37
38
39
40
41
42
43</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/logger.rb', line 36</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>level:</span> <span class='const'><span class='object_link'><a href="" title="Bovem::Logger (class)">Logger</a></span></span><span class='op'>::</span><span class='const'>INFO</span><span class='comma'>,</span> <span class='label'>formatter:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_get_real_file'>get_real_file</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span> <span class='op'>||</span> <span class='id identifier rubyid_default_file'>default_file</span><span class='rparen'>)</span><span class='rparen'>)</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_level'>level</span> <span class='op'>=</span> <span class='id identifier rubyid_level'>level</span><span class='period'>.</span><span class='id identifier rubyid_to_integer'>to_integer</span>
<span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_formatter'>formatter</span> <span class='op'>=</span> <span class='id identifier rubyid_formatter'>formatter</span> <span class='op'>||</span> <span class='id identifier rubyid_default_formatter'>default_formatter</span>
<span class='id identifier rubyid_rv'>rv</span>
<span class='kw'>rescue</span>
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Errors.html" title="Bovem::Errors (module)">Errors</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Errors/InvalidLogger.html" title="Bovem::Errors::InvalidLogger (class)">InvalidLogger</a></span></span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="default_file-class_method">
.<strong>default_file</strong> ⇒ <tt>String|IO</tt>
</h3><div class="docstring">
<div class="discussion">
<p>The default file for logging.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String|IO</tt>)</span>
—
<div class='inline'><p>The default file for logging.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
59
60
61</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/logger.rb', line 59</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_default_file'>default_file</span>
<span class='ivar'>@default_file</span> <span class='op'>||=</span> <span class='gvar'>$stdout</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="default_formatter-class_method">
.<strong>default_formatter</strong> ⇒ <tt>Proc</tt>
</h3><div class="docstring">
<div class="discussion">
<p>The default formatter for logging.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Proc</tt>)</span>
—
<div class='inline'><p>The default formatter for logging.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
65
66
67
68
69
70
71
72
73
74
75
76
77
78</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/logger.rb', line 65</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_default_formatter'>default_formatter</span>
<span class='ivar'>@default_formatter</span> <span class='op'>||=</span> <span class='op'>::</span><span class='const'>Proc</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_severity'>severity</span><span class='comma'>,</span> <span class='id identifier rubyid_datetime'>datetime</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span><span class='comma'>,</span> <span class='id identifier rubyid_msg'>msg</span><span class='op'>|</span>
<span class='id identifier rubyid_color'>color</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="#LEVEL_NAMES-constant" title="Bovem::Logger::LEVEL_NAMES (constant)">LEVEL_NAMES</a></span></span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='id identifier rubyid_severity'>severity</span><span class='comma'>,</span> <span class='symbol'>:white</span><span class='rparen'>)</span>
<span class='id identifier rubyid_header'>header</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Console.html" title="Bovem::Console (class)">Console</a></span></span><span class='period'>.</span><span class='id identifier rubyid_replace_markers'><span class='object_link'><a href="ConsoleMethods/StyleHandling.html#replace_markers-instance_method" title="Bovem::ConsoleMethods::StyleHandling#replace_markers (method)">replace_markers</a></span></span><span class='lparen'>(</span>
<span class='id identifier rubyid_sprintf'>sprintf</span><span class='lparen'>(</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>{mark=bright-</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_color'>color</span><span class='embexpr_end'>}</span><span class='tstring_content'>}[%s T+%0.5f] %s:{/mark}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_datetime'>datetime</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%Y/%b/%d %H:%M:%S</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span>
<span class='lbracket'>[</span><span class='id identifier rubyid_datetime'>datetime</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span> <span class='op'>-</span> <span class='id identifier rubyid_start_time'>start_time</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='comma'>,</span> <span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span><span class='comma'>,</span> <span class='id identifier rubyid_severity'>severity</span><span class='period'>.</span><span class='id identifier rubyid_rjust'>rjust</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span>
<span class='rparen'>)</span>
<span class='rparen'>)</span>
<span class='id identifier rubyid_sprintf'>sprintf</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>%s %s\n</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_header'>header</span><span class='comma'>,</span> <span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="get_real_file-class_method">
.<strong>get_real_file</strong>(file) ⇒ <tt>String|IO</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Translates a file to standard input or standard output in some special cases.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>file</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The string to translate.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String|IO</tt>)</span>
—
<div class='inline'><p>The translated file name.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
49
50
51
52
53
54
55</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/logger.rb', line 49</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_get_real_file'>get_real_file</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='rparen'>)</span>
<span class='kw'>case</span> <span class='id identifier rubyid_file'>file</span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>STDOUT</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='gvar'>$stdout</span>
<span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>STDERR</span><span class='tstring_end'>"</span></span> <span class='kw'>then</span> <span class='gvar'>$stderr</span>
<span class='kw'>else</span> <span class='id identifier rubyid_file'>file</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="start_time-class_method">
.<strong>start_time</strong> ⇒ <tt>Time</tt>
</h3><div class="docstring">
<div class="discussion">
<p>The log time of the first logger. This allows to show a <code>T+0.1234</code> information into the log.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>Time</tt>)</span>
—
<div class='inline'><p>The log time of the first logger.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
82
83
84</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/logger.rb', line 82</span>
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_start_time'>start_time</span>
<span class='ivar'>@start_time</span> <span class='op'>||=</span> <span class='op'>::</span><span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Jan 12 16:10:59 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.7 (ruby-2.3.0).
</div>
</div>
</body>
</html>