Skip to content

tcm: show TCM logs #1168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

tcm: show TCM logs #1168

wants to merge 1 commit into from

Conversation

dmyger
Copy link
Collaborator

@dmyger dmyger commented May 28, 2025

Added support for showing TCM logs

This commit introduces the ability to view TCM logs using
the tt tcm log command.

This command works in couple with the tt tcm start command,
and show the logs of the TCM process that was running by it.

Command expect exists tcm.log file in the current directory.

Usage example:

tt tcm log --lines 100 --follow

This command will show the last 100 lines of the TCM log
file and continue to follow the log output.
This feature is useful for monitoring the TCM process.
Without the --follow flag, it will show the last 100 lines
of the log file and exit.

The command also supports following flags:

  • --no-color to disable colored output
  • --no-format to disable structured output
Expand to possible output:
{
  time: 2025-05-29T17:19:47.905335965+03:00
  level: INFO
  msg: tcm stopped
  source: {
    file: "tcm/internal/app/tcm/server/server.go",
    function: "tcm/internal/server.(*TcmAPI).Close",
    line: 175
  }
}
{
  time: 2025-05-29T17:19:47.90451709+03:00
  level: WARN
  msg: retrying of unary invoker failed
  attempt: 0,
  error: "rpc error: code = Canceled desc = latest balancer error:
    last connection error: connection error: desc = \"transport:
    Error while dialing: dial tcp 127.0.0.1:2379: connect:
    connection refused\"",
  source: {
    file: "go.etcd.io/etcd/client/v3@v3.5.15/retry_interceptor.go",
    function: "v3.(*Client).unaryClientInterceptor.func1",
    line: 63
  },
  target: "etcd-endpoints://0xc0003d2000/127.0.0.1:2379"
}
{
  time: 2025-05-29T17:19:47.90548212+03:00
  level: ERROR
  msg: fail to get entity from etcd
  err: "context canceled",
  path: "/cluster/",
  source: {
    file: "tcm/internal/app/tcm/server.go",
    function: "tcm/internal/app/tcm/server.(*TcmAPI).validationKV",
    line: 17
  }
}

I didn't forget about (remove if it is not applicable):

  • Well-written commit messages (see documentation how to write a commit message)
  • Don't forget about TarantoolBot in a commit message (see example)
  • Tests (see documentation for a testing package)
  • Changelog (see documentation for changelog format)
  • Documentation (see documentation for documentation style guide)

Related issues:

Closes #TNTP-1103

@dmyger dmyger force-pushed the dmyger/tntp-1103_show_tcm_logs branch 2 times, most recently from 66584c4 to d2cdeb3 Compare May 29, 2025 15:05
Added support for showing TCM logs

@TarantoolBot
Title: Added support for showing TCM logs

This commit introduces the ability to view TCM logs using
the `tt tcm log` command.

This command works in couple with the `tt tcm start` command,
and show the logs of the TCM process that was running by it.

Command expect exists `tcm.log` file in the current directory.

**Usage example:**
```bash
tt tcm log --lines 100 --follow
```

This command will show the last 100 lines of the TCM log
file and continue to follow the log output.
This feature is useful for monitoring the TCM process.
Without the `--follow` flag, it will show the last 100 lines
of the log file and exit.

The command also supports following flags:
- `--no-color` to disable colored output
- `--no-format` to disable structured output

**Possible output:**
```text
{
  time: **2025-05-29T17:19:47.905335965+03:00**
  level: INFO
  msg: _tcm stopped_
  source: {
    file: "tcm/internal/app/tcm/server/server.go",
    function: "tcm/internal/server.(*TcmAPI).Close",
    line: 175
  }
}
{
  time: **2025-05-29T17:19:47.90451709+03:00**
  level: WARN
  msg: _retrying of unary invoker failed_
  attempt: 0,
  error: "rpc error: code = Canceled desc = latest balancer error:
    last connection error: connection error: desc = \"transport:
    Error while dialing: dial tcp 127.0.0.1:2379: connect:
    connection refused\"",
  source: {
    file: "go.etcd.io/etcd/client/v3@v3.5.15/retry_interceptor.go",
    function: "v3.(*Client).unaryClientInterceptor.func1",
    line: 63
  },
  target: "etcd-endpoints://0xc0003d2000/127.0.0.1:2379"
}
{
  time: **2025-05-29T17:19:47.90548212+03:00**
  level: ERROR
  msg: _fail to get entity from etcd_
  err: "context canceled",
  path: "/cluster/",
  source: {
    file: "tcm/internal/app/tcm/server.go",
    function: "tcm/internal/app/tcm/server.(*TcmAPI).validationKV",
    line: 17
  }
}
```

Closes #TNTP-1103

PreCommit-Verified: Passed
@dmyger dmyger force-pushed the dmyger/tntp-1103_show_tcm_logs branch from d2cdeb3 to 7d82ab4 Compare May 29, 2025 16:51
@dmyger dmyger marked this pull request as ready for review May 29, 2025 16:52
Comment on lines +108 to +109
//! "VERBOSE|ALARM" => ERROR fail to unmarshal log level
//? "--log.default.level=VERBOSE",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not get the comment. Please describe it with more context.

"github.com/tarantool/tt/cli/tail"
)

const LogFileName = "tcm.log"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required to be public?

Suggested change
const LogFileName = "tcm.log"
const logFileName = "tcm.log"

Comment on lines +17 to +19
// FollowLogs reads the last `lines` lines from the log file and prints them.
// It continues to follow the log file, printing new lines as they are added.
func FollowLogs(lines uint, prt LogPrinter) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a test for the call.

Comment on lines +44 to +45
// PrintLogs reads the last `lines` lines from the log file and prints them.
func PrintLogs(lines uint, prt LogPrinter) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a test for the call.

// Format formats a log string, applying colors and indentation if necessary.
// If noFormat is true or the string is not a valid JSON object, it returns
// the string as is without any formatting.
func (f *logPrinter) Format(str string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why if f - log or printer...

Suggested change
func (f *logPrinter) Format(str string) string {
func (l *logPrinter) Format(str string) string {
Suggested change
func (f *logPrinter) Format(str string) string {
func (p *logPrinter) Format(str string) string {

Comment on lines +46 to +47
// LogPrinter is an interface for printing formatted log messages.
type LogPrinter interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// LogPrinter is an interface for printing formatted log messages.
type LogPrinter interface {
// Printer is an interface for printing formatted log messages.
type Printer interface {

Comment on lines +149 to +150
// NewLogFormatter creates a new log printer with optional formatting and coloring.
func NewLogFormatter(noFormat, noColor bool, out io.Writer) *logPrinter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewLogFormatted creates a logPrinter?

Why the call is public?

@@ -0,0 +1,60 @@
package tcm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to test a public API.

Suggested change
package tcm
package tcm_test

Comment on lines +3 to +4
// Logging contains configuration for displaying TCM logs.
type Logging struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SomethingOpts is usual naming for the stuff.

Suggested change
// Logging contains configuration for displaying TCM logs.
type Logging struct {
// LoggerOpts contains configuration for displaying TCM logs.
type LoggerOpts struct {

Copy link
Contributor

@patapenka-alexey patapenka-alexey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add a Changelog entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants