Skip to content

Commit

Permalink
docs(addon): setLogFilePath() method documented
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Aug 17, 2023
1 parent a012dbc commit 9f10094
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
8 changes: 8 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ Usage: [usage/addon](usage.md#addon)
languageSapToIso(langSapCode: string): string|Error
```

### setLogFilePath

Usage: [usage/addon](usage.md#addon)

```ts
setLogFilePath(langSapCode: string): string|Error
```

## Client

Usage: [usage/client](usage.md#client)
Expand Down
8 changes: 4 additions & 4 deletions src/cpp/Log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ long long Log::timestamp() {
.count();
}

void Log::set_log_file_name(const std::string& file_name) {
log_fname = file_name;
void Log::set_log_file_path(const std::string& file_path) {
log_path = file_path;
}

void Log::set_log_level(const logClass component_id,
Expand Down Expand Up @@ -43,9 +43,9 @@ void Log::set_log_level(const logClass component_id,
set_log_level(component_id, log_level);
}

Log::Log(std::string log_fname) : log_fname(log_fname) {
Log::Log(std::string log_path) : log_path(log_path) {
std::ofstream ofs;
ofs.open(log_fname, std::ofstream::out | std::ofstream::trunc);
ofs.open(log_path, std::ofstream::out | std::ofstream::trunc);
ofs.close();
}

Expand Down
10 changes: 5 additions & 5 deletions src/cpp/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum class logLevel {
class Log {
private:
// Log file name
std::string log_fname;
std::string log_path;

// Logging inactive by default
std::unordered_map<logClass, logLevel> log_config = {
Expand All @@ -53,15 +53,15 @@ class Log {

public:
// Set log file name
void set_log_file_name(const std::string& file_name);
void set_log_file_path(const std::string& file_path);

// Set log level
void set_log_level(const logClass component_id, const logLevel log_level_id);
void set_log_level(const logClass component_id,
const Napi::Value logLevelValue);

// Default log filename
explicit Log(std::string log_fname = "_noderfc.log");
explicit Log(std::string log_path = "_noderfc.log");
~Log();

// Write regular arguments. Must be defined in header becuse of variadic
Expand All @@ -85,7 +85,7 @@ class Log {

// Write log message
ofstream ofs;
ofs.open(log_fname.c_str(), ofstream::out | ios::app);
ofs.open(log_path.c_str(), ofstream::out | ios::app);
ofs << endl
<< endl
<< date::format("%F %T", now) << " UTC [" << timestamp() << "] >> "
Expand All @@ -105,7 +105,7 @@ class Log {
if (log_level_id > log_config[component_id]) {
return;
}
FILE* fp = fopen(log_fname.c_str(), "a");
FILE* fp = fopen(log_path.c_str(), "a");
fprintf(fp, "%s", "'");
fprintfU(fp, message);
fprintf(fp, "%s", "'");
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/addon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ Napi::Value LanguageSapToIso(const Napi::CallbackInfo& info) {
return scope.Escape(wrapString(ucLangISO, 2));
}

Napi::Value SetLogFileName(const Napi::CallbackInfo& info) {
_log.set_log_file_name(info[0].As<Napi::String>().Utf8Value());
Napi::Value SetLogFilePath(const Napi::CallbackInfo& info) {
_log.set_log_file_path(info[0].As<Napi::String>().Utf8Value());
return info.Env().Undefined();
}

Expand All @@ -123,7 +123,7 @@ Napi::Object RegisterModule(Napi::Env env, Napi::Object exports) {
}

exports.Set("bindingVersions", BindingVersions(env));
exports.Set("setLogFileName", Napi::Function::New(env, SetLogFileName));
exports.Set("setLogFilePath", Napi::Function::New(env, SetLogFilePath));
exports.Set("setIniFileDirectory",
Napi::Function::New(env, SetIniFileDirectory));
exports.Set("loadCryptoLibrary", Napi::Function::New(env, LoadCryptoLibrary));
Expand Down
4 changes: 2 additions & 2 deletions src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export function loadCryptoLibrary(libAbsolutePath: string) {
noderfc_binding.loadCryptoLibrary(libAbsolutePath);
}

export function setLogFileName(fileName: string) {
noderfc_binding.setLogFileName(fileName);
export function setLogFilePath(filePath: string) {
noderfc_binding.setLogFilePath(filePath);
}

export const sapnwrfcEvents = new EventEmitter();
Expand Down
2 changes: 1 addition & 1 deletion src/ts/noderfc-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface NWRfcBinding {
languageIsoToSap(langIso: string): string | NWRfcSdkError;
languageSapToIso(langSap: string): string | NWRfcSdkError;
reloadIniFile(): undefined | NWRfcSdkError;
setLogFileName(fileName: string): unknown;
setLogFilePath(filePath: string): unknown;
verbose(): this;
}

Expand Down

0 comments on commit 9f10094

Please sign in to comment.