github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/docs/source/sysadmin_guide/log_configuration.rst (about) 1 ***************** 2 Log Configuration 3 ***************** 4 5 Overview 6 ======== 7 The validator and the Python SDK make it easy to customize the 8 logging output. This is done by creating a log config file in 9 `TOML <https://github.com/toml-lang/toml>`_ or `YAML <http://yaml.org>`_ 10 format and passing it to the built-in Python logging module. 11 12 .. Note:: 13 14 Use YAML to configure a remote syslog service. Due to a limitation in 15 the TOML spec, you cannot configure a remote syslog service using TOML. 16 17 Log Files 18 ========= 19 20 If there is no log configuration file provided, the default is to create an 21 error log and a debug log. Theses files will be stored in the log directory 22 (``log_dir``) in a location determined by the ``SAWTOOTH_HOME`` environment 23 variable. For more information, see 24 :doc:`configuring_sawtooth/path_configuration_file`. 25 26 The names of the validator log files are: 27 28 - ``validator-debug.log`` 29 - ``validator-error.log`` 30 31 For Python transaction processors, the author determines the name of the log 32 file. It is highly encouraged that the file names are unique for each running 33 processor to avoid naming conflicts. The example transaction processors 34 provided with the SDK uses the following naming convention: 35 36 - ``{TPname}-{zmqID}-debug.log`` 37 - ``{TPname}-{zmqID}-error.log`` 38 39 Examples: 40 41 - ``intkey-18670799cbbe4367-debug.log`` 42 - ``intkey-18670799cbbe4367-error.log`` 43 44 Log Configuration 45 ================= 46 47 To change the default logging behavior of a Sawtooth component, such as the 48 validator, put a log configuration file in the config directory (see 49 :doc:`configuring_sawtooth/path_configuration_file`). 50 51 An example log configuration file is at 52 ``/etc/sawtooth/log_config.toml.example``. To create a log configuration file, 53 copy the example file to ``/etc/sawtooth`` and name it ``log_config.toml``. 54 55 Each transaction processor can define its own config file. The name of 56 this file is determined by the author. The transaction processors included in 57 the Python SDK use the following naming convention: 58 59 - ``{TransactionFamilyName}_log_config.toml`` 60 61 For example, the IntegerKey (``intkey``) log configuration file is 62 ``intkey_log_config.toml``. 63 64 Examples 65 ======== 66 67 Configure a Specific Logger 68 --------------------------- 69 If the default logs give too much information, you can configure a specific 70 logger that will only report on the area of the code you are interested in. 71 72 This example ``log_config.toml`` file creates a handler that only writes 73 interconnect logs to the directory and file specified. 74 75 .. code-block:: none 76 77 version = 1 78 disable_existing_loggers = false 79 80 [formatters.simple] 81 format = "[%(asctime)s.%(msecs)03d [%(threadName)s] %(module)s %(levelname)s] %(message)s" 82 datefmt = "%H:%M:%S" 83 84 [handlers.interconnect] 85 level = "DEBUG" 86 formatter = "simple" 87 class = "logging.FileHandler" 88 filename = "path/filename.log" 89 90 [loggers."sawtooth_validator.networking.interconnect"] 91 level = "DEBUG" 92 propagate = true 93 handlers = [ "interconnect"] 94 95 The formatter and log level can also be specified to provide the exact 96 information you want in your logs. 97 98 Rotating File Handler 99 --------------------- 100 Below is an example of how to setup rotating logs. This is useful when the logs 101 may grow very large, such as with a long-running network. For example: 102 103 .. code-block:: none 104 105 [formatters.simple] 106 format = "[%(asctime)s.%(msecs)03d [%(threadName)s] %(module)s %(levelname)s] %(message)s" 107 datefmt = "%H:%M:%S" 108 109 [handlers.interconnect] 110 level = "DEBUG" 111 formatter = "simple" 112 class = "logging.handlers.RotatingFileHandler" 113 filename = "example-interconnect.log" 114 maxBytes = 50000000 115 backupCount=20 116 117 [loggers."sawtooth_validator.networking.interconnect"] 118 level = "DEBUG" 119 propagate = true 120 handlers = [ "interconnect"] 121 122 If one file exceeds the ``maxBytes`` set in the config file, that file will be 123 renamed to ``filename.log.1`` and a new ``filename.log`` will be written to. 124 This process continues for the number of files plus one set in the 125 ``backupCount``. After that point, the file that is being written to is rotated. 126 The current file being written to is always ``filename.log``. 127 128 For more Python configuration options, see the Python documentation at 129 `<https://docs.python.org/3/library/logging.config.html>`_. 130 131 .. Licensed under Creative Commons Attribution 4.0 International License 132 .. https://creativecommons.org/licenses/by/4.0/