Skip to content

Commit

Permalink
Cleanup logs and add Output shard
Browse files Browse the repository at this point in the history
  • Loading branch information
guusw committed Oct 30, 2024
1 parent 5a7e5e2 commit d0c605c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion shards/core/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2999,7 +2999,7 @@ SHCore *__cdecl shardsInterface(uint32_t abi_version) {
shards::GetGlobals().RootPath = p;
shards::loadExternalShards(p);
fs::current_path(p);
SHLOG_INFO("Root path set to: {}", p);
SHLOG_DEBUG("Root path set to: {}", p);
};

result->asyncActivate = [](SHContext *context, void *userData, SHAsyncActivateProc call, SHAsyncCancelProc cancel_call) {
Expand Down
8 changes: 4 additions & 4 deletions shards/lang/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clap::{arg, Parser};
use shards::core::{sleep, Core};
use shards::types::Mesh;
use shards::util::from_raw_parts_allow_null;
use shards::{fourCharacterCode, shlog, shlog_error, SHCore, GIT_VERSION, SHARDS_CURRENT_ABI};
use shards::{fourCharacterCode, shlog, shlog_debug, shlog_error, SHCore, GIT_VERSION, SHARDS_CURRENT_ABI};
use std::collections::HashMap;
use std::ffi::CStr;
use std::fs;
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn process_args(argc: i32, argv: *const *const c_char, no_cancellation: bool
_ => unsafe {
shards::core::Core = shardsInterface(SHARDS_CURRENT_ABI as u32);
shards_install_signal_handlers();
shlog!("Shards git version: {}", GIT_VERSION);
shlog_debug!("Shards git version: {}", GIT_VERSION);
},
};

Expand Down Expand Up @@ -286,7 +286,7 @@ fn execute_seq(
let mut defines = HashMap::new();

for arg in args {
shlog!("arg: {}", arg);
shlog_debug!("arg: {}", arg);
// find the first column and split it, the rest is the value
let mut split = arg.split(':');
let key = split.next().unwrap();
Expand Down Expand Up @@ -437,7 +437,7 @@ fn execute(
}
}

shlog!("Evaluating file: {}", file);
shlog_debug!("Evaluating file: {}", file);

let ast = {
let file_path = Path::new(&file);
Expand Down
42 changes: 39 additions & 3 deletions shards/modules/core/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
/* Copyright © 2019 Fragcolor Pte. Ltd. */

#include "logging.hpp"
#include "shards/shardwrapper.hpp"
#include "shards/utility.hpp"
#include "spdlog/spdlog.h"
#include <shards/shardwrapper.hpp>
#include <shards/utility.hpp>
#include <shards/core/params.hpp>
#include <spdlog/spdlog.h>
#include <atomic>
#include <numeric>
#include <string>
#include <cstdio>
#include <shards/log/log.hpp>
#include <spdlog/sinks/dist_sink.h>

Expand Down Expand Up @@ -188,6 +190,39 @@ struct Msg : public LoggingBase {
Enums::LogLevel _level{Enums::LogLevel::Info};
};

struct Output {
static SHOptionalString inputHelp() { return SHCCSTR("The string or bytes to output to stdout."); }
static SHOptionalString outputHelp() { return SHCCSTR("The same variable that was inputted, unmodified."); }

static SHOptionalString help() { return SHCCSTR("Outputs data directly to stdout"); }

static SHTypesInfo inputTypes() {
static Types types{CoreInfo::StringType, CoreInfo::BytesType};
return types;
}
static SHTypesInfo outputTypes() { return inputTypes(); }

PARAM_IMPL();

PARAM_REQUIRED_VARIABLES();
SHTypeInfo compose(SHInstanceData &data) {
PARAM_COMPOSE_REQUIRED_VARIABLES(data);
return data.inputType;
}

void warmup(SHContext *context) { PARAM_WARMUP(context); }
void cleanup(SHContext *context) { PARAM_CLEANUP(context); }

SHVar activate(SHContext *context, const SHVar &input) {
if (input.valueType == SHType::String) {
fwrite(input.payload.stringValue, input.payload.stringLen, 1, stdout);
} else if (input.valueType == SHType::Bytes) {
fwrite(input.payload.bytesValue, input.payload.bytesSize, 1, stdout);
}
return input;
}
};

/*
* Custom ring buffer sink
*/
Expand Down Expand Up @@ -387,6 +422,7 @@ SHARDS_REGISTER_FN(logging) {
REGISTER_SHARD("Log", Log);
REGISTER_SHARD("LogType", LogType);
REGISTER_SHARD("Msg", Msg);
REGISTER_SHARD("Output", Output);
REGISTER_SHARD("CaptureLog", CaptureLog);

struct LogFlush : public LambdaShard<logsFlushActivation, CoreInfo::AnyType, CoreInfo::AnyType> {
Expand Down

0 comments on commit d0c605c

Please sign in to comment.