【Temporal】日志打印控制

开启server日志级别

首先我们从代码出发看看应该怎么开启,进入到temporal server的启动入口:temporal/cmd/server/main.go

logger := log.NewZapLogger(log.BuildZapLogger(cfg.Log))
logger.Info("Build info.",
   tag.NewTimeTag("git-time", build.InfoData.GitTime),
   tag.NewStringTag("git-revision", build.InfoData.GitRevision),
   tag.NewBoolTag("git-modified", build.InfoData.GitModified),
   tag.NewStringTag("go-arch", build.InfoData.GoArch),
   tag.NewStringTag("go-os", build.InfoData.GoOs),
   tag.NewStringTag("go-version", build.InfoData.GoVersion),
   tag.NewBoolTag("cgo-enabled", build.InfoData.CgoEnabled),
   tag.NewStringTag("server-version", headers.ServerVersion),
   tag.NewBoolTag("debug-mode", debug.Enabled),
)


var dynamicConfigClient dynamicconfig.Client
if cfg.DynamicConfigClient != nil {
   dynamicConfigClient, err = dynamicconfig.NewFileBasedClient(cfg.DynamicConfigClient, logger, temporal.InterruptCh())
   if err != nil {
      return cli.Exit(fmt.Sprintf("Unable to create dynamic config client. Error: %v", err), 1)
   }
} else {
   dynamicConfigClient = dynamicconfig.NewNoopClient()
   logger.Info("Dynamic config client is not configured. Using noop client.")
}


authorizer, err := authorization.GetAuthorizerFromConfig(
   &cfg.Global.Authorization,
)
if err != nil {
   return cli.Exit(fmt.Sprintf("Unable to instantiate authorizer. Error: %v", err), 1)
}
if authorization.IsNoopAuthorizer(authorizer) && !allowNoAuth {
   logger.Warn(
      "Not using any authorizer and flag `--allow-no-auth` not detected. " +
         "Future versions will require using the flag `--allow-no-auth` " +
         "if you do not want to set an authorizer.",
   )
}


claimMapper, err := authorization.GetClaimMapperFromConfig(&cfg.Global.Authorization, logger)
if err != nil {
   return cli.Exit(fmt.Sprintf("Unable to instantiate claim mapper: %v.", err), 1)
}
s, err := temporal.NewServer(
   temporal.ForServices(services),
   temporal.WithConfig(cfg),
   temporal.WithDynamicConfigClient(dynamicConfigClient),
   temporal.WithLogger(logger),
   temporal.InterruptOn(temporal.InterruptCh()),
   temporal.WithAuthorizer(authorizer),
   temporal.WithClaimMapper(func(cfg *config.Config) authorization.ClaimMapper {
      return claimMapper
   }),
)
if err != nil {
   return cli.Exit(fmt.Sprintf("Unable to create server. Error: %v.", err), 1)
}


err = s.Start()
if err != nil {
   return cli.Exit(fmt.Sprintf("Unable to start server. Error: %v", err), 1)
}
return cli.Exit("All services are stopped.", 0)

上面是一部分的启动代码,可以看到,在构造server的时候传入了一个自定义的logger配置;我们看看这个logger配置,通过代码调用我们可以知道:

func parseZapLevel(level string) zapcore.Level {
   switch strings.ToLower(level) {
   case "debug":
      return zap.DebugLevel
   case "info":
      return zap.InfoLevel
   case "warn":
      return zap.WarnLevel
   case "error":
      return zap.ErrorLevel
   case "dpanic":
      return zap.DPanicLevel
   case "panic":
      return zap.PanicLevel
   case "fatal":
      return zap.FatalLevel
   default:
      return zap.InfoLevel
   }
}

这个日志级别可以通过配置文件的log.level字段来控制。

如果我们是通过temporal提供的k8s集群场景下安装命令来默认安装的话,会自动生成各个组件的configMap,我们找到这个configMap,可以看到是这样的:

log:
  stdout: true
  level: "debug"


persistence:
  defaultStore: default
  visibilityStore: visibility
  numHistoryShards: 512
  datastores:
    default:
      sql:
        pluginName: "mysql"
        driverName: "mysql"
        databaseName: "temporal"
        connectAddr: "11.141.232.141:3306"
        connectProtocol: "tcp"
        user: root
        password: "{{ .Env.TEMPORAL_STORE_PASSWORD }}"
        maxConnLifetime: 1h
        maxConns: 20
        secretName: ""
    visibility:
      sql:
        pluginName: "mysql"
        driverName: "mysql"
        databaseName: "temporal_visibility"
        connectAddr: "11.141.232.141:3306"
        connectProtocol: "tcp"
        user: "root"
        password: "{{ .Env.TEMPORAL_VISIBILITY_STORE_PASSWORD }}"
        maxConnLifetime: 1h
        maxConns: 20
        secretName: ""


global:
  membership:
    name: temporal
    maxJoinDuration: 30s
    broadcastAddress: {{ default .Env.POD_IP "0.0.0.0" }}


  pprof:
    port: 7936


  metrics:
    tags:
      type: history
    prometheus:
      timerType: histogram
      listenAddress: "0.0.0.0:9090"


services:
  frontend:
    rpc:
      grpcPort: 7233
      membershipPort: 6933
      bindOnIP: "0.0.0.0"


  history:
    rpc:
      grpcPort: 7234
      membershipPort: 6934
      bindOnIP: "0.0.0.0"


  matching:
    rpc:
      grpcPort: 7235
      membershipPort: 6935
      bindOnIP: "0.0.0.0"


  worker:
    rpc:
      grpcPort: 7239
      membershipPort: 6939
      bindOnIP: "0.0.0.0"
clusterMetadata:
  enableGlobalDomain: false
  failoverVersionIncrement: 10
  masterClusterName: "active"
  currentClusterName: "active"
  clusterInformation:
    active:
      enabled: true
      initialFailoverVersion: 1
      rpcName: "temporal-frontend"
      rpcAddress: "127.0.0.1:7933"
dcRedirectionPolicy:
  policy: "noop"
  toDC: ""
archival:
  status: "disabled"


publicClient:
  hostPort: "temporal-frontend:7233"


dynamicConfigClient:
  filepath: "/etc/temporal/dynamic_config/dynamic_config.yaml"
  pollInterval: "10s"

可以看到配置文件这里可以设置level。

开启SDK日志

在我们代码引入temporal的-go sdk,启动worker的时候,sdk代码里面有部分日志默认是不打印的,比如:

traceLog(func() {
   var firstEventID int64 = -1
   if response.History != nil && len(response.History.Events) > 0 {
      firstEventID = response.History.Events[0].GetEventId()
   }
   wtp.logger.Debug("workflowTaskPoller::Poll Succeed",
      "StartedEventID", response.GetStartedEventId(),
      "Attempt", response.GetAttempt(),
      "FirstEventID", firstEventID,
      "IsQueryTask", response.Query != nil)
})

我们进入这个traceLog方法:

func traceLog(fn func()) {
   if enableVerboseLogging {
      fn()
   }
}
var enableVerboseLogging = false


// EnableVerboseLogging enable or disable verbose logging. This is for internal use only.
func EnableVerboseLogging(enable bool) {
   enableVerboseLogging = enable
}

我们可以看到,这些日志时通过一个全局变量来控制的,默认时false,不打印。
并且我们可以看到,sdk提供了一个接口来调用设置这个变量。因此我们可以通过在启动worker的时候,设置这个变量为true。

       Choose here       javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql     

w := worker.New(*c, taskQueue, worker.Options{
   MaxConcurrentWorkflowTaskPollers:   100,
   MaxConcurrentActivityTaskPollers:   100,
   MaxConcurrentActivityExecutionSize: 1000,
   DeadlockDetectionTimeout:           time.Second * 60,
   EnableLoggingInReplay:              true,
})
worker.EnableVerboseLogging(true)
static int print_stat(DEC_STAT * stat, int ret) { #if LIBVC_ON char *stype = NULL; #else char stype = 0; #endif int i, j; if(COM_SUCCEEDED(ret)) { if (stat->ctype == COM_CT_SLICE || stat->ctype == COM_CT_PICTURE) { #if LIBVC_ON if (stat->is_RLpic_flag) { stype = "RL"; } else { switch (stat->stype) { case COM_ST_I: stype = "I"; break; case COM_ST_P: stype = "P"; break; case COM_ST_B: stype = "B"; break; #if SVAC_NAL case COM_ST_IDR: stype = "IDR"; break; case COM_ST_CRA: stype = "CRA"; break; #endif case COM_ST_UNKNOWN: default: stype = "U"; break; } } #else switch (stat->stype) { case COM_ST_I: stype = 'I'; break; case COM_ST_P: stype = 'P'; break; case COM_ST_B: stype = 'B'; break; case COM_ST_UNKNOWN: default: stype = 'U'; break; } #endif } if(stat->ctype == COM_CT_SLICE) { #if LIBVC_ON v1print("%2s-slice", stype); #else v1print("%c-slice", stype); #endif v1print(" (poc=%d) ", (int)stat->poc); #if TSVC_OPT v1print("(temporal_id = %d)", (int)stat->temporal_id); #endif } #if TSVC_OPT else if (stat->ctype == COM_CT_SIGN) { v1print("sei message\n"); printf(" num_of_temporal_level %d\n", stat->temporal_layer_num); for (int i = 0; i < stat->temporal_layer_num; i++) { printf(" temporal_fps %d ", stat->temporal_fps[i]); printf(" temporal_bitrate_low %d ", stat->temporal_bitrate_low[i]); printf(" temporal_bitrate_up %d \n", stat->temporal_bitrate_up[i]); } } #endif else if(stat->ctype == COM_CT_SQH) { #if HLS_OPT_PPS v1print("SPS"); #else v1print("Sequence header"); #endif #if PRINT_SQH_PARAM_DEC printf( "\n*** HLS Params: bitDep %d", stat->internal_bit_depth ); #if PHASE_2_PROFILE printf(" profile 0x%x", stat->profile_id); #endif #if CFG_LEVEL_ID printf(" level_id 0x%x", stat->level_id); #endif #if ENHANCE_TSPCM printf("\n*** Intra tools: TSCPM %d Enhance_TSCPM %d IPF %d IntraDT %d IPCM %d", (stat->intra_tools >> 0) & 0x1, (stat->intra_tools >> 1) & 0x1, (stat->intra_tools >> 2) & 0x1, (stat->intra_tools >> 3) & 0x1, (stat->intra_tools >> 4) & 0x1); #if MIPF printf(" MIPF %d", (stat->intra_tools >> 5) & 0x1); #endif #else printf( "\n*** Intra tools: TSCPM %d IPF %d IntraDT %d IPCM %d", (stat->intra_tools >> 0) & 0x1, (stat->intra_tools >> 1) & 0x1, (stat->intra_tools >> 2) & 0x1, (stat->intra_tools >> 3) & 0x1 ); #if MIPF printf(" MIPF %d", (stat->intra_tools >> 4) & 0x1); #endif #endif #if PMC || EPMC printf(" PMC %d", (stat->intra_tools >> 6) & 0x1); #endif #if IPF_CHROMA printf(" IPF_CHROMA %d", (stat->intra_tools >> 7) & 0x01); #endif #if IIP printf(" IIP %d", (stat->intra_tools >> 8) & 0x01); #endif #if SAWP printf(" SAWP %d", (stat->intra_tools >> 9) & 0x01); #endif // SAWP #if AWP printf("\n*** Inter tools: AFFINE %d AMVR %d UMVE %d EMVR %d SMVD %d AWP %d HMVP %d ", (stat->inter_tools >> 0) & 0x1, (stat->inter_tools >> 1) & 0x1, (stat->inter_tools >> 2) & 0x1, (stat->inter_tools >> 3) & 0x1, (stat->inter_tools >> 4) & 0x1, (stat->inter_tools >> 5) & 0x1, (stat->inter_tools >> 10) & 0xf); #else printf( "\n*** Inter tools: AFFINE %d AMVR %d UMVE %d EMVR %d SMVD %d HMVP %d ", (stat->inter_tools >> 0) & 0x1, (stat->inter_tools >> 1) & 0x1, (stat->inter_tools >> 2) & 0x1, (stat->inter_tools >> 3) & 0x1, (stat->inter_tools >> 4) & 0x1, (stat->inter_tools >> 10) & 0xf ); #endif printf( "\n*** Trans tools: NSST %d PBT %d ", (stat->trans_tools >> 0) & 0x1, (stat->trans_tools >> 1) & 0x1 ); printf("\n*** Filter tools: SAO %d ALF %d ", (stat->filte_tools >> 0) & 0x1, (stat->filte_tools >> 1) & 0x1); printf( "\n*** SCC tools: "); #if FIMC printf( " FIMC %d ", (stat->scc_tools >> 0) & 0x1); #endif #if IBC_BVP printf(" HBVP %d ", (stat->scc_tools >> 1) & 0xf); #endif #endif } #if HLS_OPT_PPS else if (stat->ctype == COM_CT_PPS) { v1print("PPS"); #if HLS_OPT_PPS printf(" pps_id %d", stat->pps_id); #endif } #endif else if (stat->ctype == COM_CT_PICTURE) { #if LIBVC_ON v1print("%2s-picture header", stype); #else v1print("%c-picture header", stype); #endif #if HLS_OPT_PPS printf(" pic_pps_id %d", stat->pic_pps_id); #endif } else if( stat->ctype == COM_CT_SEQ_END ) { v1print( "video_sequence_end_code" ); } #if LIB_PIC_MIXBIN else if (stat->ctype == COM_CT_CRR_SLICE_IMCOPLETE || stat->ctype == COM_CT_CRR_SLICE) { v0print("L-slice"); #if LIBPIC_DISPLAY if (!stat->is_dp_crr) #endif v1print(" (patch_idx=%d) ", (int)stat->patch_idx); } #endif #if SVAC_SECURITY_PARAM_SET else if (stat->ctype == COM_CT_SEC_PARA_SET) { v1print("security parameter set"); } #endif #if SVAC_AUTHENTICATION else if (stat->ctype == COM_CT_AUTH) { v1print("authentication data"); } #endif else { v0print("Unknown bitstream"); } if (stat->ctype == COM_CT_SLICE) { for (i = 0; i < 2; i++) { #if LIBVC_ON if (stat->is_RLpic_flag) { v1print("[Lib%d ", i); } else #endif { v1print("[L%d ", i); } #if MULTI_LAYER_FRAMEWORK for (j = 0; j < stat->refpic_num[i]; j++) { if (stat->reflib[i][j] == 1) v1print("LIB"); if (stat->reflib[i][j] == 2) v1print("(l%d)", stat->reflayer[i][j]); v1print("%d ", stat->refpic[i][j]); } #else for (j = 0; j < stat->refpic_num[i]; j++) v1print("%d ", stat->refpic[i][j]); #endif v1print("] "); } } if (ret == COM_OK) { v1print("\n"); } else if(ret == COM_OK_FRM_DELAYED) { v1print("->Frame delayed\n"); } else if(ret == COM_OK_DIM_CHANGED) { v1print("->Resolution changed\n"); } else { v1print("->Unknown OK code = %d\n", ret); } } else { v0print("Decoding error = %d\n", ret); } return 0; }
最新发布
07-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值