2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[自作ライブラリ] VersaLog.go

Last updated at Posted at 2025-06-28

VersaLog.goとは?

VersaLog.go は、多機能で柔軟なログ出力を簡単に実現できる Golang ライブラリです。
シンプルな表示から詳細な実行情報まで、用途に応じたログ形式を選べます。

詳細・導入方法はこちら:
リポジトリ

どんな機能があるの?

大きく分けて、3つです。


機能モード 説明
simple シンプルで見やすいログを出力します。色付き・レベル付き
detailed 実行時間、レベル付きログ
file ファイル名、行数付きログ

⚠️ 注意
ログを出力する前に、必ず VersaLog.NewVersaLog("...") でモードを設定してください。

オプションはあるの?

現在、設定可能なオプションは 1つ あります

show_file: True にすると、simple モードなどでもファイル情報(ファイル名・行数)を表示できます。

⚠️ 注意
show_file=True を指定しないと、ファイル情報は表示されません。
fileモードではshow_file=Falseにしてください

インストール方法は?

go get github.com/kayu0514/VersaLog.go

実装方法

サンプルコード(simpleモード)
package main

import versalog "github.com/kayu0514/VersaLog.go/VersaLog"

// showFile false
func main() {
	logger := versalog.NewVersaLog("simple", false)

	logger.Info("Everything is fine.")
	logger.Err("Something went wrong.")
	logger.War("This is a warning.")
}

// showFile true
func main() {
	logger := versalog.NewVersaLog("simple", true)

	logger.Info("Everything is fine.")
	logger.Err("Something went wrong.")
	logger.War("This is a warning.")
}
サンプルコード(detailedモード)
package main

import versalog "github.com/kayu0514/VersaLog.go/VersaLog"

// showFile false
func main() {
	logger := versalog.NewVersaLog("detailed", false)

	logger.Info("Everything is fine.")
	logger.Err("Something went wrong.")
	logger.War("This is a warning.")
}

// showFile true
func main() {
	logger := versalog.NewVersaLog("detailed", true)

	logger.Info("Everything is fine.")
	logger.Err("Something went wrong.")
	logger.War("This is a warning.")
}
サンプルコード(fileモード)
package main

import versalog "github.com/kayu0514/VersaLog.go/VersaLog"

func main() {
	logger := versalog.NewVersaLog("file", false)

	logger.Info("Everything is fine.")
	logger.Err("Something went wrong.")
	logger.War("This is a warning.")
}

ℹ️ ヒント
show_file=False を指定すると、simpledetailed モードでもファイル情報(ファイル名・行数)は非表示になります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?