npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gosls/tencent-pythonlogs

v0.0.1

Published

Tencent Cloud Python Logs Componnet

Downloads

5

Readme

SCF Python语言实时日志功能

说明

该模块用于实现SCF Python Runtime的实时日志功能,通过该组件,您可以实时查看到函数输出的日志(包括print和logging等),本组件目前在测试阶段,欢迎测试提意见,目前不建议上业务。

准备

  • 安装scflog
pip install scflog

安装时,可能需要root权限,否则可能无法使用。安装完成,可以执行scflog -v查看是否安装成功:

scflog 0.1.1
  • 部署实时日志组件,新建项目,并且建立serverless.yaml,内容:

组件部署

PythonLogs:
  component: '@gosls/tencent-pythonlogs'
  inputs:
    region: ap-guangzhou

这里的参数是您要将这个组件部署的区域。该组件可以复用,也就是说这个组件部署完成之后可以一直被使用。

通过sls --debug部署:

DEBUG ─ Setting tags for function PythonRealTimeLogs_Cleanup
DEBUG ─ Creating trigger for function PythonRealTimeLogs_Cleanup
DEBUG ─ Deployed function PythonRealTimeLogs_Cleanup successful

PythonLogs: 
    websocket: ws://service-laabz6zm-1256773370.gz.apigw.tencentcs.com/test/python_real_time_logs
    
    26s › PythonLogs › done

此时我们需要配置组件:

scflog set -w ws://service-laabz6zm-1256773370.gz.apigw.tencentcs.com/test/python_real_time_logs

配置成功输出:

DFOUNDERLIU-MB0:~ dfounderliu$ scflog set -w ws://service-laabz6zm-1256773370.gz.apigw.tencentcs.com/test/python_real_time_logs
设置成功
	websocket: ws://service-laabz6zm-1256773370.gz.apigw.tencentcs.com/test/python_real_time_logs
	region: ap-guangzhou
	namespace: default

通过sls remove --debug移除

DEBUG ─ Removing any previously deployed API. api-rzm1uzik
DEBUG ─ Removing any previously deployed API. api-07wq4u9a
DEBUG ─ Removing any previously deployed service. service-laabz6zm

6s › PythonLogs › done

项目中使用

在项目中使用该组件的方法很简单。

  • 创建一个文件夹,并进入

mkdir scflogs && cd scflogs

  • 初始化项目

scflog init

  • 创建index.py文件以及serverless.yaml文件:
vim index.py

内容是:

from logs import *
import time
import logging

def main_handler(event, context):
    print("event is: ", event)
    time.sleep(1)
    logging.debug("this is debug_msg")
    time.sleep(1)
    logging.info("this is info_msg")
    time.sleep(1)
    logging.warning("this is warning_msg")
    time.sleep(1)
    logging.error("this is error_msg")
    time.sleep(1)
    logging.critical("this is critical_msg")
    time.sleep(1)
    print("context is: ", event)
    return "hello world"
vim serverless.yaml

内容是:

Hello_World:
  component: "@serverless/tencent-scf"
  inputs:
    name: Hello_World
    codeUri: ./
    handler: index.main_handler
    runtime: Python3.6
    region: ap-guangzhou
    description: My Serverless Function
    memorySize: 64
    timeout: 20
    exclude:
      - .gitignore
      - .git/**
      - node_modules/**
      - .serverless
      - .env
    events:
      - apigw:
          name: serverless
          parameters:
            protocols:
              - http
            serviceName: serverless
            description: the serverless service
            environment: release
            endpoints:
              - path: /test
                method: ANY

通过sls --debug部署:

DEBUG ─ Deployed function Hello_World successful

  Hello_World: 
    Name:        Hello_World
    Runtime:     Python3.6
    Handler:     index.main_handler
    MemorySize:  64
    Timeout:     20
    Region:      ap-guangzhou
    Namespace:   default
    Description: My Serverless Function
    APIGateway: 
      - serverless - http://service-89bjzrye-1256773370.gz.apigw.tencentcs.com/release

  30s › Hello_World › done

此时,我们配置了APIGW的触发器,地址是上面输出的地址 + endpoints中的path例如:

http://service-89bjzrye-1256773370.gz.apigw.tencentcs.com/release/test

此时,我们可以打开实时日志:

scflog logs -n Hello_World -r ap-guangzhou

此时会提醒我们实时日志开启成功:

DFOUNDERLIU-MB0:~ dfounderliu$ scflog logs -n Hello_World -r ap-guangzhou
实时日志开启 ... 

我们可以用浏览器通过刚才函数部署完成返回给我们的地址触发函数:

实时日志开启 ... 
[2020-03-04 16:36:08] :  ......}
[2020-03-04 16:36:09] :  DEBUG debug_msg 
[2020-03-04 16:36:10] :  INFO info_msg 
[2020-03-04 16:36:11] :  WARNING warning_msg 
[2020-03-04 16:36:14] :  ERROR error_msg 
[2020-03-04 16:36:14] :  CRITICAL critical_msg 
[2020-03-04 16:36:16] :  context is: .......}
.......

至此,实现实时日志功能。