Skip to content

Commit

Permalink
Merge pull request #6 from gammaalfa/feature_set_verbosity_from_cli
Browse files Browse the repository at this point in the history
Feature: set verbosity at startup
  • Loading branch information
oott123 authored Sep 19, 2019
2 parents 83c5d3a + eb82281 commit d7c7815
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TDLib JSON CLI

![TDLib v1.5.0](https://img.shields.io/badge/TDLib-v1.5.0-green.svg)
![TDLib JSON CLI v1.1.2](https://img.shields.io/badge/TDLib%20JSON%20CLI-v1.1.2-green.svg)
![TDLib JSON CLI v1.1.3](https://img.shields.io/badge/TDLib%20JSON%20CLI-v1.1.3-green.svg)
![Build Status](https://img.shields.io/travis/oott123/tdlib-json-cli.svg)
![AGPL v3.0](https://img.shields.io/github/license/oott123/tdlib-json-cli.svg)
[![GitHub release](https://img.shields.io/github/release/oott123/tdlib-json-cli.svg)](https://github.com/oott123/tdlib-json-cli/releases)
Expand All @@ -18,8 +18,17 @@ This project is licensed under AGPL v3.0, but you can distribute it separately s
## Usage

```bash
./bin/tdlib-json-cli
./bin/tdlib-json-cli [verbosity]
```
[verbosity] = 0123456789
Set TDLib's verbosity level at startup.
- 0 - fatal errors;
- 1 - errors;
- 2 - warnings and debug warnings;
- 3 - informational;
- 4 - debug;
- 5 - verbose debug;
- greater than 5 and up to 1024 can be used to enable even more logging.

tdlib-json-cli will use stdin & stdout to process data.

Expand Down
14 changes: 11 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
#include <string>
#include <thread>
#include "td/td/telegram/td_json_client.h"
#include "td/td/telegram/td_log.h"
#include "td/td/telegram/Log.h"

void* client;
int should_stop = 0;

void proc_thread_input();
void proc_thread_output();
void trigger_cli_event(std::string);
void set_verbosity(char const *);

int main(int argc, char const *argv[])
{
set_verbosity(argv[1]);
client = td_json_client_create();
trigger_cli_event("client_created");
std::thread thread_input(proc_thread_input);
Expand All @@ -37,8 +39,7 @@ void proc_thread_input() {
if (input.rfind("verbose ", 0) == 0) {
// verbose<space>
// 01234567
auto level = atoi(input.substr(7).c_str());
td_set_log_verbosity_level(level);
set_verbosity(input.substr(7).c_str());
continue;
}
td_json_client_send(client, input.c_str());
Expand All @@ -58,3 +59,10 @@ void proc_thread_output() {
void trigger_cli_event(std::string event_name) {
std::cout << "{\"@cli\":{\"event\":\"" << event_name << "\"}}" << std::endl;
}

void set_verbosity(char const *argv) {
if (argv == NULL) return;
auto level = atoi(argv);
td::Log::set_verbosity_level(level);
trigger_cli_event("verbosity_set");
}

0 comments on commit d7c7815

Please sign in to comment.