Skip to main content

log system

Project description

micropython-lagan

介绍

基于micropython语言的日志库.

lagan取名来自于宜家的水龙头"拉根"。

本软件包已上传到pypi,可输入命令直接安装。

pip install micropython-lagan

功能

  • 支持日志在终端实时打印
  • 支持二进制流打印
  • 支持带颜色的日志打印

与python标准版lagan相比,micropython版本的lagan删除了输出到日志文件的功能。

error打印函数名改为err,原因是使用error函数名在设备运行会报错。

示例

# 默认输出界别是info,本行不会打印
lagan.debug("case4", "debug test print")

lagan.info("case4", "info test print")
lagan.warn("case4", "warn test print")
lagan.err("case4", "error test print")

输出:

186172:12:16 -  I/case4: info test print
186172:12:16 -  W/case4: warn test print
186172:12:16 -  E/case4: error test print

注意:时间戳是基于设备本地时钟,不是标准时间。

二进制流打印

s = bytearray()
for i in range(100):
    s.append(i)
lagan.print_hex('case2', lagan.LEVEL_ERROR, s)

输出:

186172:11:40 -  E/case2: 
****00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
---- : -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
0000 : 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 
0010 : 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 
0020 : 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 
0030 : 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 
0040 : 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 
0050 : 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 
0060 : 60 61 62 63 

颜色控制

可以使用EnableColor函数开控制打开或者关闭日志颜色,默认关闭颜色。

lagan.set_filter_level(lagan.LEVEL_DEBUG)
lagan.enable_color(True)
lagan.println('case1', lagan.LEVEL_OFF, 'TestPrintOut1:%d', 100)
lagan.println('case1', lagan.LEVEL_DEBUG, 'TestPrintOut1:%d', 100)
lagan.println('case1', lagan.LEVEL_INFO, 'TestPrintOut1:%d', 100)
lagan.println('case1', lagan.LEVEL_WARN, 'TestPrintOut1:%d', 100)
lagan.println('case1', lagan.LEVEL_ERROR, 'TestPrintOut1:%d', 100)

s = bytearray()
for i in range(100):
    s.append(i)
lagan.print_hex('case2', lagan.LEVEL_INFO, s)

图片

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

micropython-lagan-1.4.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file micropython-lagan-1.4.tar.gz.

File metadata

  • Download URL: micropython-lagan-1.4.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7

File hashes

Hashes for micropython-lagan-1.4.tar.gz
Algorithm Hash digest
SHA256 8d9d7a63e4b8c750cea99ec4f4868615604cb53ce1f70224f8c6c4c186fe54d6
MD5 5684537975d91a0b7a818215888ac13f
BLAKE2b-256 a3b8b7c1ca35a7cddd85004de1818b9ceb46750f5eb0f0a5e1e1b4f96e7e8250

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page