Document of c-modernization-kit (porter) 1.0.0
Loading...
Searching...
No Matches
potrLog.c File Reference

porter ロガー実装。 More...

#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <trace-util.h>
#include <porter_const.h>
#include <porter.h>
#include "potrLog.h"
Include dependency graph for potrLog.c:

Go to the source code of this file.

Functions

static const char * log_basename (const char *path)
 パスの末尾ファイル名部分を返す。
POTR_EXPORT int POTR_API potrLogConfig (PotrLogLevel level, const char *log_file, int console)
 ロガーを設定します。
void potr_log_write (PotrLogLevel level, const char *file, int line, const char *fmt,...)
 ログメッセージを書き込みます (内部関数)。

Variables

static trace_provider_t * s_trace = NULL
 トレースプロバイダハンドル。trace_init() で一度だけ初期化する。

Detailed Description

porter ロガー実装。

Author
c-modernization-kit sample team
Date
2026/03/09
Version
1.0.0

trace-util のプロキシモジュールです。
OS レベルのトレース出力 (Linux: syslog、Windows: ETW)、 ファイルトレース、stderr 出力のすべてを trace-util に委任します。

OS 出力先
Linux syslog (trace-util 経由)、ログファイル (trace-util 経由)、stderr (trace-util 経由、console 指定時)
Windows ETW (trace-util 経由)、ログファイル (trace-util 経由)、stderr (trace-util 経由、console 指定時)
スレッド セーフティ
本モジュールはスレッドセーフです。
すべての出力制御は trace-util が内部で排他制御を行います。

Definition in file potrLog.c.

Function Documentation

◆ log_basename()

const char * log_basename ( const char * path)
static

パスの末尾ファイル名部分を返す。

'/' または '\' の最後の出現以降の文字列を返します。
区切り文字が存在しない場合は path をそのまま返します。

Definition at line 53 of file potrLog.c.

Referenced by potr_log_write().

Here is the caller graph for this function:

◆ potrLogConfig()

POTR_EXPORT int POTR_API potrLogConfig ( PotrLogLevel level,
const char * log_file,
int console )

ロガーを設定します。

Parameters
[in]level出力する最低ログレベル。POTR_TRACE_NONE でログ無効 (デフォルト)。
[in]log_fileログファイルのパス。NULL または空文字列を指定するとファイル出力なし。
[in]console0 以外を指定すると標準エラー出力 (stderr) にも出力します。
Returns
成功時は POTR_SUCCESS、log_file が開けない場合は POTR_ERROR を返します。

本関数は potrOpenService() の前に呼び出してください。
複数回呼び出した場合は最後の設定が有効になります。

出力先
OS 出力先
Linux syslog (trace-util 経由)、ログファイル (trace-util 経由、log_file 指定時)、stderr (trace-util 経由、console 指定時)
Windows ETW (trace-util 経由)、ログファイル (trace-util 経由、log_file 指定時)、stderr (trace-util 経由、console 指定時)
ログフォーマット
OS トレース (syslog / ETW) およびファイルへの出力フォーマット:
[file.c:line] message
stderr への出力フォーマット (タイムスタンプは UTC、L はレベル文字):
YYYY-MM-DD HH:MM:SS.mmm L [file.c:line] message
ログレベル一覧
レベル 出力内容
POTR_TRACE_CRITICAL 0 致命的エラー
POTR_TRACE_ERROR 1 操作失敗
POTR_TRACE_WARNING 2 NACK・REJECT・回復可能な異常
POTR_TRACE_INFO 3 サービス開始・終了・接続状態変化
POTR_TRACE_VERBOSE 4 ソケット操作・設定値・パケット送受信・スレッド動作
POTR_TRACE_NONE 5 ログ無効 (デフォルト)
使用例
// INFO 以上をファイルと stderr に出力
potrLogConfig(POTR_TRACE_INFO, "/var/log/porter.log", 1);
// VERBOSE 以上をファイルのみに出力
potrLogConfig(POTR_TRACE_VERBOSE, "/tmp/porter.log", 0);
// ログを無効化
POTR_EXPORT int POTR_API potrLogConfig(PotrLogLevel level, const char *log_file, int console)
ロガーを設定します。
Definition potrLog.c:72
@ POTR_TRACE_NONE
ログ出力無効。TRACE_LV_NONE (5) と同値。
@ POTR_TRACE_INFO
情報。TRACE_LV_INFO (3) と同値。
@ POTR_TRACE_VERBOSE
詳細情報 (デバッグ)。TRACE_LV_VERBOSE (4) と同値。
スレッド セーフティ
本関数はスレッドセーフです。
出力制御は trace-util が内部で排他制御を行うため、ログを出力中のスレッドが存在する場合でも 安全に設定を変更できます。
Warning
log_file に指定したパスが書き込み不可の場合は POTR_ERROR を返します。

Definition at line 72 of file potrLog.c.

References POTR_API, POTR_ERROR, POTR_EXPORT, POTR_SUCCESS, POTR_TRACE_NONE, and s_trace.

Referenced by main().

Here is the caller graph for this function:

◆ potr_log_write()

void potr_log_write ( PotrLogLevel level,
const char * file,
int line,
const char * fmt,
... )

ログメッセージを書き込みます (内部関数)。

Parameters
[in]levelログレベル。
[in]fileソースファイル名 (FILE)。
[in]line行番号 (LINE)。
[in]fmtprintf 形式のフォーマット文字列。
[in]...フォーマット引数。

g_log_level より低いレベルのメッセージは無視されます (高速パス)。
本関数を直接呼び出さず、POTR_LOG マクロを使用してください。

Definition at line 128 of file potrLog.c.

References log_basename(), and s_trace.

Here is the call graph for this function:

Variable Documentation

◆ s_trace

trace_provider_t* s_trace = NULL
static

トレースプロバイダハンドル。trace_init() で一度だけ初期化する。

Definition at line 42 of file potrLog.c.

Referenced by potr_log_write(), and potrLogConfig().