RoundSparrow

joined 3 years ago
MODERATOR OF
 

"Nobody realizes that some people expend tremendous energy merely to be normal." - Blanche Balain, quoted/popularized by Albert Camus around September 1, 1943

 

For weeks I've been trying to figure out how to get more organized logging out of the Rust code, and I have never worked with Rust before. The default behavior of lemmy_server is to put all Rust logging into the Linux syslog and you typically filter by the Linux user account 'lemmy'.

Where to write Files ==========
I did "Lemmy from Scratch" and run without Docker. So my lemmy_server lemmy I throw logs into /home/lemmy/logs folder. I don't think Docker even creates a /home/lemmy directory, not sure. I'm inclined to make this an environment variable to set the output folder - suggestions welcome.

Rust Library =========
crate add tracing-appender

Code surgery to /src/lib.rs ==========

use tracing::Level;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::{
    fmt::{self, writer::MakeWriterExt}
};


pub fn init_logging(opentelemetry_url: &Option<Url>) -> Result<Vec<Option<WorkerGuard>>, LemmyError> {
  LogTracer::init()?;

  let log_dir = Some("/home/lemmy/logs");
  // Code may have multiple log files (target tags) in the future, so return an array.
  let mut guards = Vec::new();

  let file_filter = Targets::new()
    .with_target("federation", Level::TRACE);

  let file_log = log_dir
      .map(|p| tracing_appender::non_blocking(tracing_appender::rolling::daily(p, "federation")))
      .map(|(appender_type, g)| {
          let guard = Some(g);
          guards.push(guard);
          fmt::Layer::new()
              .with_writer(appender_type.with_max_level(Level::TRACE))
              .with_ansi(false)
              .with_filter(file_filter)
      });

  let log_description = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into());

  let targets = log_description
    .trim()
    .trim_matches('"')
    .parse::<Targets>()?;

  let format_layer = {
    #[cfg(feature = "json-log")]
    let layer = tracing_subscriber::fmt::layer().json();
    #[cfg(not(feature = "json-log"))]
    let layer = tracing_subscriber::fmt::layer();

    layer.with_filter(targets.clone())
  };

  let subscriber = Registry::default()
    .with(format_layer)
    .with(ErrorLayer::default())
    .with(file_log)
    ;

  if let Some(_url) = opentelemetry_url {
    #[cfg(feature = "console")]
    telemetry::init_tracing(_url.as_ref(), subscriber, targets)?;
    #[cfg(not(feature = "console"))]
    tracing::error!("Feature `console` must be enabled for opentelemetry tracing");
  } else {
    set_global_default(subscriber)?;
  }

  tracing::warn!("zebracat logging checkpoint A");
  tracing::info!(target:"federation", "zebracat file logging startup");

  Ok(guards)
}

Code surgery to /src/main.rs ==========

let _guards = init_logging(&SETTINGS.opentelemetry_url)?;

How to use ================
Anywhere you want in Lemmy code, you can now log to your file: tracing::info!(target:"federation", "this will go to the file");

 

If anyone can confirm this problem, please do. GitHub issue: https://github.com/LemmyNet/lemmy/issues/3588

I started noticing more accidental-duplicate posts where the creator of the post wasn't cleaning up their own dupes, but it seems some internal problem with Lemmy may be at play. I have no idea if it isn't sending it outbound, some kind of problem inbound, or other version interaction. I tested it on two 0.18.2 servers.

 

"crates/apub/src/activities/community/announce.rs", line: 46

That line of code seems like just a logging line, any Rust programmers chime in on how we can get the actual value of the data logged?

https://github.com/LemmyNet/lemmy/blob/0c82f4e66065b5772fede010a879d327135dbb1e/crates/apub/src/activities/community/announce.rs#L46

 

A few weeks ago, the topic came up and I commented on Beehaw: https://beehaw.org/comment/361658

Given the beta status of Lemmy, I don't even think it's a great idea to give the appearance of privacy. I think the core purpose of a webapp like Lemmy is public messages.

I think it's a can of worms for server operators to get into the business of thinking they can safely hold private messages between users/strangers. None of the Lemmy instances I've joined have had a "terms of service" or anything like that on SIgn Up, I really think the message should be sent far and wide that Lemmy is about posting IN PUBLIC and that messages are being FEDERATED to peers, even people that you don't know could be collecting the data for a search engine.

With small-time server operators opening up hundreds of Lemmy instances, without giving away their experience or human identity, how can you have any confidence that someone is properly securing a server they only have part-time job to update and operate? Major corporations are having their database stolen, Valve, Sony, Nintendo, health care companies, mobile network companies (AT&T)... you think a low-budget shoestring server by a hobbyist running Lemmy should be held to the same standards as a corporation who has an entire team and services to defend their data?

EDIT: Same goes for putting your Lemmy password into a smartphone app or other third-party client. Why should Lemmy server operators be claiming privacy when you have no idea (and no agreement with) who is front-ending your API? You have a 'man in the middle' right there, with full access to Lemmy logins.

view more: ‹ prev next ›