ipfs_api_prelude/request/
log.rs

1// Copyright 2017 rust-ipfs-api Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7//
8
9use crate::request::ApiRequest;
10use serde::{Serialize, Serializer};
11use std::borrow::Cow;
12
13#[derive(Copy, Clone)]
14pub enum LoggingLevel {
15    Debug,
16    Info,
17    Warning,
18    Error,
19    Critical,
20}
21
22impl Serialize for LoggingLevel {
23    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
24    where
25        S: Serializer,
26    {
27        let s = match self {
28            LoggingLevel::Debug => "debug",
29            LoggingLevel::Info => "info",
30            LoggingLevel::Warning => "warning",
31            LoggingLevel::Error => "error",
32            LoggingLevel::Critical => "critical",
33        };
34
35        serializer.serialize_str(s)
36    }
37}
38
39pub enum Logger<'a> {
40    All,
41    Specific(Cow<'a, str>),
42}
43
44impl<'a> Serialize for Logger<'a> {
45    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
46    where
47        S: Serializer,
48    {
49        let s = match self {
50            Logger::All => "*",
51            Logger::Specific(ref logger) => logger.as_ref(),
52        };
53
54        serializer.serialize_str(s)
55    }
56}
57
58#[derive(Serialize)]
59pub struct LogLevel<'a> {
60    #[serde(rename = "arg")]
61    pub logger: Logger<'a>,
62
63    #[serde(rename = "arg")]
64    pub level: LoggingLevel,
65}
66
67impl<'a> ApiRequest for LogLevel<'a> {
68    const PATH: &'static str = "/log/level";
69}
70
71pub struct LogLs;
72
73impl_skip_serialize!(LogLs);
74
75impl ApiRequest for LogLs {
76    const PATH: &'static str = "/log/ls";
77}
78
79pub struct LogTail;
80
81impl_skip_serialize!(LogTail);
82
83impl ApiRequest for LogTail {
84    const PATH: &'static str = "/log/tail";
85}