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
28                                    returned by the 'Get Error Logs' keyword.
29    key_list                        The list of keys to be printed.  This may
30                                    be specified as either a python list
31                                    or a space-delimited string.  In the
32                                    latter case, this function will convert
33                                    it to a python list. See the sprint_varx
34                                    function prolog for additionatl details.
35
36    Example use from a python script:
37
38    ${error_logs}=  Get Error Logs
39    Print Error Logs  ${error_logs}  Message Timestamp
40
41    Sample output:
42
43    error_logs:
44      [/xyz/openbmc_project/logging/entry/3]:
45        [Timestamp]:                                  1521738335735
46        [Message]:
47        xyz.openbmc_project.Inventory.Error.Nonfunctional
48      [/xyz/openbmc_project/logging/entry/2]:
49        [Timestamp]:                                  1521738334637
50        [Message]:
51        xyz.openbmc_project.Inventory.Error.Nonfunctional
52      [/xyz/openbmc_project/logging/entry/1]:
53        [Timestamp]:                                  1521738300696
54        [Message]:
55        xyz.openbmc_project.Inventory.Error.Nonfunctional
56      [/xyz/openbmc_project/logging/entry/4]:
57        [Timestamp]:                                  1521738337915
58        [Message]:
59        xyz.openbmc_project.Inventory.Error.Nonfunctional
60
61    Another example call using a robot list:
62    ${error_logs}=  Get Error Logs
63    ${key_list}=  Create List  Message  Timestamp  Severity
64    Print Error Logs  ${error_logs}  ${key_list}
65    """
66
67    if key_list is not None:
68        if type(key_list) in (str, unicode):
69            key_list = key_list.split(" ")
70        key_list.insert(0, var.BMC_LOGGING_ENTRY + ".*")
71
72    gp.print_var(error_logs, hex=1, key_list=key_list)
73