Robot Framework Integrated Development Environment (RIDE)
librarylogger.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 
21 
22 import sys
23 import threading
24 
25 from robotide.lib.robot.errors import DataError
26 from robotide.lib.robot.utils import unic, console_encode
27 
28 from .logger import LOGGER
29 from .loggerhelper import Message
30 
31 
32 LOGGING_THREADS = ('MainThread', 'RobotFrameworkTimeoutThread')
33 
34 
35 def write(msg, level, html=False):
36  # Callable messages allow lazy logging internally, but we don't want to
37  # expose this functionality publicly. See the following issue for details:
38  # https://github.com/robotframework/robotframework/issues/1505
39  if callable(msg):
40  msg = unic(msg)
41  if level.upper() not in ('TRACE', 'DEBUG', 'INFO', 'HTML', 'WARN', 'ERROR'):
42  raise DataError("Invalid log level '%s'." % level)
43  if threading.currentThread().getName() in LOGGING_THREADS:
44  LOGGER.log_message(Message(msg, level, html))
45 
46 
47 def trace(msg, html=False):
48  write(msg, 'TRACE', html)
49 
50 
51 def debug(msg, html=False):
52  write(msg, 'DEBUG', html)
53 
54 
55 def info(msg, html=False, also_console=False):
56  write(msg, 'INFO', html)
57  if also_console:
58  console(msg)
59 
60 
61 def warn(msg, html=False):
62  write(msg, 'WARN', html)
63 
64 
65 def error(msg, html=False):
66  write(msg, 'ERROR', html)
67 
68 
69 def console(msg, newline=True, stream='stdout'):
70  msg = unic(msg)
71  if newline:
72  msg += '\n'
73  stream = sys.__stdout__ if stream.lower() != 'stderr' else sys.__stderr__
74  stream.write(console_encode(msg, stream=stream))
75  stream.flush()
Used when variable does not exist.
Definition: errors.py:67
def info(msg, html=False, also_console=False)
def console(msg, newline=True, stream='stdout')
def write(msg, level, html=False)
def console_encode(string, errors='replace', stream=sys.__stdout__)
Encodes Unicode to bytes in console or system encoding.
Definition: encoding.py:62