1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8 <title>Class: MCollective::Log</title>
10 <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
12 <script src="../js/jquery.js" type="text/javascript"
13 charset="utf-8"></script>
14 <script src="../js/thickbox-compressed.js" type="text/javascript"
15 charset="utf-8"></script>
16 <script src="../js/quicksearch.js" type="text/javascript"
17 charset="utf-8"></script>
18 <script src="../js/darkfish.js" type="text/javascript"
19 charset="utf-8"></script>
25 <div id="file-metadata">
26 <div id="file-list-section" class="section">
27 <h3 class="section-header">In Files</h3>
28 <div class="section-body">
31 <li><a href="../lib/mcollective/log_rb.html?TB_iframe=true&height=550&width=785"
32 class="thickbox" title="lib/mcollective/log.rb">lib/mcollective/log.rb</a></li>
41 <div id="class-metadata">
45 <div id="parent-class-section" class="section">
46 <h3 class="section-header">Parent</h3>
48 <p class="link"><a href="../Object.html">Object</a></p>
53 <!-- Namespace Contents -->
56 <!-- Method Quickref -->
58 <div id="method-list-section" class="section">
59 <h3 class="section-header">Methods</h3>
60 <ul class="link-list">
62 <li><a href="#M000124">::check_level</a></li>
64 <li><a href="#M000123">::config_and_check_level</a></li>
66 <li><a href="#M000131">::configure</a></li>
68 <li><a href="#M000122">::cycle_level</a></li>
70 <li><a href="#M000118">::debug</a></li>
72 <li><a href="#M000120">::error</a></li>
74 <li><a href="#M000134">::execution_stack</a></li>
76 <li><a href="#M000119">::fatal</a></li>
78 <li><a href="#M000133">::from</a></li>
80 <li><a href="#M000116">::info</a></li>
82 <li><a href="#M000121">::instance</a></li>
84 <li><a href="#M000129">::log</a></li>
86 <li><a href="#M000127">::logexception</a></li>
88 <li><a href="#M000115">::logger</a></li>
90 <li><a href="#M000128">::logmsg</a></li>
92 <li><a href="#M000126">::message_for</a></li>
94 <li><a href="#M000130">::set_logger</a></li>
96 <li><a href="#M000132">::unconfigure</a></li>
98 <li><a href="#M000125">::valid_level?</a></li>
100 <li><a href="#M000117">::warn</a></li>
106 <!-- Included Modules -->
110 <div id="project-metadata">
113 <div id="fileindex-section" class="section project-section">
114 <h3 class="section-header">Files</h3>
117 <li class="file"><a href="../COPYING.html">COPYING</a></li>
119 <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
121 <li class="file"><a href="../README.html">README</a></li>
123 <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
125 <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
127 <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
129 <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
131 <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
133 <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
135 <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
137 <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
139 <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
141 <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
143 <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
145 <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
147 <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
149 <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
151 <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
153 <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
155 <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
161 <div id="classindex-section" class="section project-section">
162 <h3 class="section-header">Class Index
163 <span class="search-toggle"><img src="../images/find.png"
164 height="16" width="16" alt="[+]"
165 title="show/hide quicksearch" /></span></h3>
166 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
168 <legend>Quicksearch</legend>
169 <input type="text" name="quicksearch" value=""
170 class="quicksearch-field" />
174 <ul class="link-list">
176 <li><a href="../MCollective.html">MCollective</a></li>
178 <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
180 <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
182 <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
184 <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
186 <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
188 <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
190 <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
192 <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
194 <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
196 <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
198 <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
200 <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
202 <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
204 <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
206 <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
208 <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
210 <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
212 <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
214 <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
216 <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
218 <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
220 <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
222 <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
224 <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
226 <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
228 <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
230 <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
232 <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
234 <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
236 <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
238 <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
240 <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
242 <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
244 <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
246 <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
248 <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
250 <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
252 <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
254 <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
256 <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
258 <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
260 <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
262 <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
264 <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
266 <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
268 <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
270 <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
272 <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
274 <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
276 <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
278 <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
280 <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
282 <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
284 <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
286 <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
288 <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
290 <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
292 <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
294 <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
296 <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
298 <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
300 <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
302 <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
304 <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
306 <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
308 <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
310 <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
312 <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
314 <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
316 <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
318 <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
320 <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
322 <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
324 <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
326 <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
328 <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
330 <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
332 <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
334 <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
336 <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
338 <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
340 <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
342 <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
344 <li><a href="../Array.html">Array</a></li>
346 <li><a href="../Dir.html">Dir</a></li>
348 <li><a href="../Object.html">Object</a></li>
350 <li><a href="../String.html">String</a></li>
352 <li><a href="../Symbol.html">Symbol</a></li>
355 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
362 <div id="documentation">
363 <h1 class="class">MCollective::Log</h1>
365 <div id="description">
367 A simple class that allows logging at various levels.
374 <div id="constants-list" class="section">
375 <h3 class="section-header">Constants</h3>
378 <dt><a name="VALID_LEVELS">VALID_LEVELS</a></dt>
380 <dd class="description missing-docs">(Not documented)</dd>
392 <div id="public-class-method-details" class="method-section section">
393 <h3 class="section-header">Public Class Methods</h3>
396 <div id="check-level-method" class="method-detail ">
397 <a name="M000124"></a>
399 <div class="method-heading">
401 <span class="method-name">check_level</span><span
402 class="method-args">(level)</span>
403 <span class="method-click-advice">click to toggle source</span>
407 <div class="method-description">
409 <p class="missing-docs">(Not documented)</p>
413 <div class="method-source-code"
414 id="check-level-source">
416 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 55</span>
417 55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">check_level</span>(<span class="ruby-identifier">level</span>)
418 56: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Unknown log level"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">valid_level?</span>(<span class="ruby-identifier">level</span>)
419 57: <span class="ruby-keyword kw">end</span></pre>
428 <div id="config-and-check-level-method" class="method-detail ">
429 <a name="M000123"></a>
431 <div class="method-heading">
433 <span class="method-name">config_and_check_level</span><span
434 class="method-args">(level)</span>
435 <span class="method-click-advice">click to toggle source</span>
439 <div class="method-description">
441 <p class="missing-docs">(Not documented)</p>
445 <div class="method-source-code"
446 id="config-and-check-level-source">
448 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 49</span>
449 49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config_and_check_level</span>(<span class="ruby-identifier">level</span>)
450 50: <span class="ruby-identifier">configure</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@configured</span>
451 51: <span class="ruby-identifier">check_level</span>(<span class="ruby-identifier">level</span>)
452 52: <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">should_log?</span>(<span class="ruby-identifier">level</span>)
453 53: <span class="ruby-keyword kw">end</span></pre>
462 <div id="configure-method" class="method-detail ">
463 <a name="M000131"></a>
465 <div class="method-heading">
467 <span class="method-name">configure</span><span
468 class="method-args">(logger=nil)</span>
469 <span class="method-click-advice">click to toggle source</span>
473 <div class="method-description">
476 configures the logger class, if the config has not yet been loaded we
477 default to the console logging class and do not set @configured so that
478 future calls to the log method will keep attempting to configure the logger
479 till we eventually get a logging preference from the config module
484 <div class="method-source-code"
485 id="configure-source">
487 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 130</span>
488 130: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure</span>(<span class="ruby-identifier">logger</span>=<span class="ruby-keyword kw">nil</span>)
489 131: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">logger</span>
490 132: <span class="ruby-identifier">logger_type</span> = <span class="ruby-value str">"console"</span>
492 134: <span class="ruby-identifier">config</span> = <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>
494 136: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">config</span>.<span class="ruby-identifier">configured</span>
495 137: <span class="ruby-identifier">logger_type</span> = <span class="ruby-identifier">config</span>.<span class="ruby-identifier">logger_type</span>
496 138: <span class="ruby-ivar">@configured</span> = <span class="ruby-keyword kw">true</span>
497 139: <span class="ruby-keyword kw">end</span>
499 141: <span class="ruby-identifier">require</span> <span class="ruby-value str">"mcollective/logger/%s_logger"</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">logger_type</span>.<span class="ruby-identifier">downcase</span>
501 143: <span class="ruby-identifier">logger_class</span> = <span class="ruby-constant">MCollective</span><span class="ruby-operator">::</span><span class="ruby-constant">Logger</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-value str">"%s_logger"</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">logger_type</span>.<span class="ruby-identifier">capitalize</span>)
503 145: <span class="ruby-identifier">set_logger</span>(<span class="ruby-identifier">logger_class</span>.<span class="ruby-identifier">new</span>)
504 146: <span class="ruby-keyword kw">else</span>
505 147: <span class="ruby-identifier">set_logger</span>(<span class="ruby-identifier">logger</span>)
506 148: <span class="ruby-ivar">@configured</span> = <span class="ruby-keyword kw">true</span>
507 149: <span class="ruby-keyword kw">end</span>
510 152: <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">start</span>
511 153: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
512 154: <span class="ruby-ivar">@configured</span> = <span class="ruby-keyword kw">false</span>
513 155: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"Could not start logger: #{e.class} #{e}"</span>
514 156: <span class="ruby-keyword kw">end</span></pre>
523 <div id="cycle-level-method" class="method-detail ">
524 <a name="M000122"></a>
526 <div class="method-heading">
528 <span class="method-name">cycle_level</span><span
529 class="method-args">()</span>
530 <span class="method-click-advice">click to toggle source</span>
534 <div class="method-description">
537 increments the active log level
542 <div class="method-source-code"
543 id="cycle-level-source">
545 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 45</span>
546 45: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cycle_level</span>
547 46: <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">cycle_level</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@configured</span>
548 47: <span class="ruby-keyword kw">end</span></pre>
557 <div id="debug-method" class="method-detail ">
558 <a name="M000118"></a>
560 <div class="method-heading">
562 <span class="method-name">debug</span><span
563 class="method-args">(msg)</span>
564 <span class="method-click-advice">click to toggle source</span>
568 <div class="method-description">
576 <div class="method-source-code"
579 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 25</span>
580 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">debug</span>(<span class="ruby-identifier">msg</span>)
581 26: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">msg</span>)
582 27: <span class="ruby-keyword kw">end</span></pre>
591 <div id="error-method" class="method-detail ">
592 <a name="M000120"></a>
594 <div class="method-heading">
596 <span class="method-name">error</span><span
597 class="method-args">(msg)</span>
598 <span class="method-click-advice">click to toggle source</span>
602 <div class="method-description">
610 <div class="method-source-code"
613 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 35</span>
614 35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">error</span>(<span class="ruby-identifier">msg</span>)
615 36: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">:error</span>, <span class="ruby-identifier">msg</span>)
616 37: <span class="ruby-keyword kw">end</span></pre>
625 <div id="execution-stack-method" class="method-detail ">
626 <a name="M000134"></a>
628 <div class="method-heading">
630 <span class="method-name">execution_stack</span><span
631 class="method-args">()</span>
632 <span class="method-click-advice">click to toggle source</span>
636 <div class="method-description">
639 this method is here to facilitate testing
644 <div class="method-source-code"
645 id="execution-stack-source">
647 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 170</span>
648 170: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">execution_stack</span>
649 171: <span class="ruby-identifier">caller</span>
650 172: <span class="ruby-keyword kw">end</span></pre>
659 <div id="fatal-method" class="method-detail ">
660 <a name="M000119"></a>
662 <div class="method-heading">
664 <span class="method-name">fatal</span><span
665 class="method-args">(msg)</span>
666 <span class="method-click-advice">click to toggle source</span>
670 <div class="method-description">
678 <div class="method-source-code"
681 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 30</span>
682 30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fatal</span>(<span class="ruby-identifier">msg</span>)
683 31: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">:fatal</span>, <span class="ruby-identifier">msg</span>)
684 32: <span class="ruby-keyword kw">end</span></pre>
693 <div id="from-method" class="method-detail ">
694 <a name="M000133"></a>
696 <div class="method-heading">
698 <span class="method-name">from</span><span
699 class="method-args">()</span>
700 <span class="method-click-advice">click to toggle source</span>
704 <div class="method-description">
707 figures out the filename that called us
712 <div class="method-source-code"
715 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 164</span>
716 164: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">from</span>
717 165: <span class="ruby-identifier">path</span>, <span class="ruby-identifier">line</span>, <span class="ruby-identifier">method</span> = <span class="ruby-identifier">execution_stack</span>[<span class="ruby-value">3</span>].<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/:(\d+)/</span>)
718 166: <span class="ruby-value str">"%s:%s%s"</span> <span class="ruby-operator">%</span> [<span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">path</span>), <span class="ruby-identifier">line</span>, <span class="ruby-identifier">method</span>]
719 167: <span class="ruby-keyword kw">end</span></pre>
728 <div id="info-method" class="method-detail ">
729 <a name="M000116"></a>
731 <div class="method-heading">
733 <span class="method-name">info</span><span
734 class="method-args">(msg)</span>
735 <span class="method-click-advice">click to toggle source</span>
739 <div class="method-description">
747 <div class="method-source-code"
750 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 15</span>
751 15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">info</span>(<span class="ruby-identifier">msg</span>)
752 16: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">:info</span>, <span class="ruby-identifier">msg</span>)
753 17: <span class="ruby-keyword kw">end</span></pre>
762 <div id="instance-method" class="method-detail ">
763 <a name="M000121"></a>
765 <div class="method-heading">
767 <span class="method-name">instance</span><span
768 class="method-args">()</span>
769 <span class="method-click-advice">click to toggle source</span>
773 <div class="method-description">
776 handle old code that relied on this class being a singleton
781 <div class="method-source-code"
782 id="instance-source">
784 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 40</span>
785 40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">instance</span>
786 41: <span class="ruby-keyword kw">self</span>
787 42: <span class="ruby-keyword kw">end</span></pre>
796 <div id="log-method" class="method-detail ">
797 <a name="M000129"></a>
799 <div class="method-heading">
801 <span class="method-name">log</span><span
802 class="method-args">(level, msg, origin=nil)</span>
803 <span class="method-click-advice">click to toggle source</span>
807 <div class="method-description">
810 logs a message at a certain level
815 <div class="method-source-code"
818 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 106</span>
819 106: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">log</span>(<span class="ruby-identifier">level</span>, <span class="ruby-identifier">msg</span>, <span class="ruby-identifier">origin</span>=<span class="ruby-keyword kw">nil</span>)
820 107: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">config_and_check_level</span>(<span class="ruby-identifier">level</span>)
822 109: <span class="ruby-identifier">origin</span> = <span class="ruby-identifier">from</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">origin</span>
824 111: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>
825 112: <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">level</span>, <span class="ruby-identifier">origin</span>, <span class="ruby-identifier">msg</span>)
826 113: <span class="ruby-keyword kw">else</span>
827 114: <span class="ruby-identifier">t</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-value str">"%H:%M:%S"</span>)
829 116: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">"#{t}: #{level}: #{origin}: #{msg}"</span>
830 117: <span class="ruby-keyword kw">end</span>
831 118: <span class="ruby-keyword kw">end</span></pre>
840 <div id="logexception-method" class="method-detail ">
841 <a name="M000127"></a>
843 <div class="method-heading">
845 <span class="method-name">logexception</span><span
846 class="method-args">(msgid, level, e, backtrace=false, args={})</span>
847 <span class="method-click-advice">click to toggle source</span>
851 <div class="method-description">
853 <p class="missing-docs">(Not documented)</p>
857 <div class="method-source-code"
858 id="logexception-source">
860 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 67</span>
861 67: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logexception</span>(<span class="ruby-identifier">msgid</span>, <span class="ruby-identifier">level</span>, <span class="ruby-identifier">e</span>, <span class="ruby-identifier">backtrace</span>=<span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">args</span>={})
862 68: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">config_and_check_level</span>(<span class="ruby-identifier">level</span>)
864 70: <span class="ruby-identifier">path</span>, <span class="ruby-identifier">line</span>, <span class="ruby-identifier">method</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/:(\d+)/</span>)
865 71: <span class="ruby-identifier">origin</span> = <span class="ruby-value str">"%s:%s%s"</span> <span class="ruby-operator">%</span> [<span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">path</span>), <span class="ruby-identifier">line</span>, <span class="ruby-identifier">method</span>]
867 73: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">CodedError</span>)
868 74: <span class="ruby-identifier">msg</span> = <span class="ruby-value str">"%s: %s"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">code</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>]
869 75: <span class="ruby-keyword kw">else</span>
870 76: <span class="ruby-identifier">error_string</span> = <span class="ruby-value str">"%s: %s"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>]
871 77: <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">message_for</span>(<span class="ruby-identifier">msgid</span>, <span class="ruby-identifier">args</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:error</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">error_string</span>))
872 78: <span class="ruby-keyword kw">end</span>
874 80: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">level</span>, <span class="ruby-identifier">msg</span>, <span class="ruby-identifier">origin</span>)
876 82: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">backtrace</span>
877 83: <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
878 84: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">level</span>, <span class="ruby-value str">"%s: %s"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">msgid</span>, <span class="ruby-identifier">line</span>], <span class="ruby-identifier">origin</span>)
879 85: <span class="ruby-keyword kw">end</span>
880 86: <span class="ruby-keyword kw">end</span>
881 87: <span class="ruby-keyword kw">end</span></pre>
890 <div id="logger-method" class="method-detail ">
891 <a name="M000115"></a>
893 <div class="method-heading">
895 <span class="method-name">logger</span><span
896 class="method-args">()</span>
897 <span class="method-click-advice">click to toggle source</span>
901 <div class="method-description">
904 Obtain the class name of the currently configured logger
909 <div class="method-source-code"
912 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 10</span>
913 10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logger</span>
914 11: <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">class</span>
915 12: <span class="ruby-keyword kw">end</span></pre>
924 <div id="logmsg-method" class="method-detail ">
925 <a name="M000128"></a>
927 <div class="method-heading">
929 <span class="method-name">logmsg</span><span
930 class="method-args">(msgid, default, level, args={})</span>
931 <span class="method-click-advice">click to toggle source</span>
935 <div class="method-description">
938 Logs a message at a certain level, the message must be a token that will be
939 looked up from the i18n localization database
942 Messages can interprolate strings from the args hash, a message with
943 “foo %{bar}” in the localization database will use args[:bar]
944 for the value there, the interprolation is handled by the i18n library
950 <div class="method-source-code"
953 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 97</span>
954 97: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logmsg</span>(<span class="ruby-identifier">msgid</span>, <span class="ruby-identifier">default</span>, <span class="ruby-identifier">level</span>, <span class="ruby-identifier">args</span>={})
955 98: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">config_and_check_level</span>(<span class="ruby-identifier">level</span>)
957 100: <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">message_for</span>(<span class="ruby-identifier">msgid</span>, {<span class="ruby-identifier">:default</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">default</span>}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">args</span>))
959 102: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">level</span>, <span class="ruby-identifier">msg</span>)
960 103: <span class="ruby-keyword kw">end</span></pre>
969 <div id="message-for-method" class="method-detail ">
970 <a name="M000126"></a>
972 <div class="method-heading">
974 <span class="method-name">message_for</span><span
975 class="method-args">(msgid, args={})</span>
976 <span class="method-click-advice">click to toggle source</span>
980 <div class="method-description">
982 <p class="missing-docs">(Not documented)</p>
986 <div class="method-source-code"
987 id="message-for-source">
989 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 63</span>
990 63: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">message_for</span>(<span class="ruby-identifier">msgid</span>, <span class="ruby-identifier">args</span>={})
991 64: <span class="ruby-value str">"%s: %s"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">msgid</span>, <span class="ruby-constant">Util</span>.<span class="ruby-identifier">t</span>(<span class="ruby-identifier">msgid</span>, <span class="ruby-identifier">args</span>)]
992 65: <span class="ruby-keyword kw">end</span></pre>
1001 <div id="set-logger-method" class="method-detail ">
1002 <a name="M000130"></a>
1004 <div class="method-heading">
1006 <span class="method-name">set_logger</span><span
1007 class="method-args">(logger)</span>
1008 <span class="method-click-advice">click to toggle source</span>
1012 <div class="method-description">
1015 sets the logger class to use
1020 <div class="method-source-code"
1021 id="set-logger-source">
1023 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 121</span>
1024 121: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_logger</span>(<span class="ruby-identifier">logger</span>)
1025 122: <span class="ruby-ivar">@logger</span> = <span class="ruby-identifier">logger</span>
1026 123: <span class="ruby-keyword kw">end</span></pre>
1035 <div id="unconfigure-method" class="method-detail ">
1036 <a name="M000132"></a>
1038 <div class="method-heading">
1040 <span class="method-name">unconfigure</span><span
1041 class="method-args">()</span>
1042 <span class="method-click-advice">click to toggle source</span>
1046 <div class="method-description">
1048 <p class="missing-docs">(Not documented)</p>
1052 <div class="method-source-code"
1053 id="unconfigure-source">
1055 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 158</span>
1056 158: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unconfigure</span>
1057 159: <span class="ruby-ivar">@configured</span> = <span class="ruby-keyword kw">false</span>
1058 160: <span class="ruby-identifier">set_logger</span>(<span class="ruby-keyword kw">nil</span>)
1059 161: <span class="ruby-keyword kw">end</span></pre>
1068 <div id="valid-level--method" class="method-detail ">
1069 <a name="M000125"></a>
1071 <div class="method-heading">
1073 <span class="method-name">valid_level?</span><span
1074 class="method-args">(level)</span>
1075 <span class="method-click-advice">click to toggle source</span>
1079 <div class="method-description">
1081 <p class="missing-docs">(Not documented)</p>
1085 <div class="method-source-code"
1086 id="valid-level--source">
1088 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 59</span>
1089 59: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">valid_level?</span>(<span class="ruby-identifier">level</span>)
1090 60: <span class="ruby-constant">VALID_LEVELS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">level</span>)
1091 61: <span class="ruby-keyword kw">end</span></pre>
1100 <div id="warn-method" class="method-detail ">
1101 <a name="M000117"></a>
1103 <div class="method-heading">
1105 <span class="method-name">warn</span><span
1106 class="method-args">(msg)</span>
1107 <span class="method-click-advice">click to toggle source</span>
1111 <div class="method-description">
1119 <div class="method-source-code"
1122 <span class="ruby-comment cmt"># File lib/mcollective/log.rb, line 20</span>
1123 20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">warn</span>(<span class="ruby-identifier">msg</span>)
1124 21: <span class="ruby-identifier">log</span>(<span class="ruby-identifier">:warn</span>, <span class="ruby-identifier">msg</span>)
1125 22: <span class="ruby-keyword kw">end</span></pre>
1140 <div id="rdoc-debugging-section-dump" class="debugging-section">
1142 <p>Disabled; run with --debug to generate this.</p>
1146 <div id="validator-badges">
1147 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
1148 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
1149 Rdoc Generator</a> 1.1.6</small>.</p>