1#!/usr/bin/env python
2
3r"""
4Provide useful error log utility keywords.
5"""
6
7import gen_print as gp
8import sys
9import os
10import imp
11base_path = os.path.dirname(os.path.dirname(
12                            imp.find_module("gen_robot_print")[1])) + os.sep
13sys.path.append(base_path + "data/")
14import variables as var
15
16
17def print_error_logs(error_logs, key_list=None):
18    r"""
19    Print the error logs to the console screen.
20
21    This function provides the following benefits:
22    - It will specify print_var parms for the caller (e.g. hex=1).
23    - It is much easier to call this function than to generate the desired code
24      directly from a robot script.
25
26    Description of argument(s):
27    error_logs  An error log dictionary such as the one returned by the
28                'Get Error Logs' keyword.
29    key_list    The list of keys to be printed.  This may be specified as
30                either a python list or a space-delimited string.  In the
31                latter case, this function will convert it to a python list.
32                See the sprint_varx function prolog for additionatl details.
33
34    Example use from a python script:
35
36    ${error_logs}=  Get Error Logs
37    Print Error Logs  ${error_logs}  Message Timestamp
38
39    Sample output:
40
41    error_logs:
42      [/xyz/openbmc_project/logging/entry/3]:
43        [Timestamp]:                                  1521738335735
44        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
45      [/xyz/openbmc_project/logging/entry/2]:
46        [Timestamp]:                                  1521738334637
47        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
48      [/xyz/openbmc_project/logging/entry/1]:
49        [Timestamp]:                                  1521738300696
50        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
51      [/xyz/openbmc_project/logging/entry/4]:
52        [Timestamp]:                                  1521738337915
53        [Message]:                                    xyz.openbmc_project.Inventory.Error.Nonfunctional
54
55    Another example call using a robot list:
56    ${error_logs}=  Get Error Logs
57    ${key_list}=  Create List  Message  Timestamp  Severity
58    Print Error Logs  ${error_logs}  ${key_list}
59    """
60
61    if key_list is not None:
62        if type(key_list) in (str, unicode):
63            key_list = key_list.split(" ")
64        key_list.insert(0, var.BMC_LOGGING_ENTRY + ".*")
65
66    gp.print_var(error_logs, hex=1, key_list=key_list)
67