Skip to content

Commit 4262449

Browse files
committed
Making process._logger readonly and exporting logger function types
1 parent e5fd6e2 commit 4262449

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/console.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
const util = require('util');
44

5-
// Values should match with the ones from logger_func_type enum in node.h
6-
const LOGGER_FUNC_TYPE_LOG = 2;
7-
const LOGGER_FUNC_TYPE_INFO = 3;
8-
const LOGGER_FUNC_TYPE_WARN = 4;
9-
const LOGGER_FUNC_TYPE_ERROR = 5;
10-
const LOGGER_FUNC_TYPE_DIR = 6;
5+
const LOGGER_FUNC_TYPE_LOG = process._logger.LOGGER_FUNC_TYPE_LOG;
6+
const LOGGER_FUNC_TYPE_INFO = process._logger.LOGGER_FUNC_TYPE_INFO;
7+
const LOGGER_FUNC_TYPE_WARN = process._logger.LOGGER_FUNC_TYPE_WARN;
8+
const LOGGER_FUNC_TYPE_ERROR = process._logger.LOGGER_FUNC_TYPE_ERROR;
9+
const LOGGER_FUNC_TYPE_DIR = process._logger.LOGGER_FUNC_TYPE_DIR;
1110

1211

1312
function Console(stdout, stderr) {

src/node.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,8 @@ void LoggerCallback(const FunctionCallbackInfo<Value>& args) {
954954
CHECK(args[1]->IsString());
955955

956956
if (custom_logger) {
957-
int32_t func_type = args[0]->ToInteger(env->isolate())->Int32Value();
958-
node::Utf8Value message(env->isolate(), args[1]);
957+
int32_t func_type = args[0]->IntegerValue();
958+
Utf8Value message(env->isolate(), args[1].As<String>());
959959
if (custom_logger(static_cast<logger_func_type>(func_type), *message))
960960
args.GetReturnValue().Set(True(env->isolate()));
961961
}
@@ -2890,7 +2890,22 @@ void SetupProcessObject(Environment* env,
28902890
env->SetMethod(process, "_setupPromises", SetupPromises);
28912891
env->SetMethod(process, "_setupDomainUse", SetupDomainUse);
28922892

2893-
env->SetMethod(process, "_logger", LoggerCallback);
2893+
// Readonly _logger method
2894+
v8::Local<v8::Function> logger =
2895+
env->NewFunctionTemplate(LoggerCallback)->GetFunction();
2896+
READONLY_PROPERTY(process, "_logger", logger);
2897+
logger->SetName(v8::String::NewFromUtf8(env->isolate(), "_logger"));
2898+
// Logger function type constants
2899+
READONLY_PROPERTY(logger, "LOGGER_FUNC_TYPE_LOG",
2900+
Integer::New(env->isolate(), LOGGER_FUNC_TYPE_LOG));
2901+
READONLY_PROPERTY(logger, "LOGGER_FUNC_TYPE_INFO",
2902+
Integer::New(env->isolate(), LOGGER_FUNC_TYPE_INFO));
2903+
READONLY_PROPERTY(logger, "LOGGER_FUNC_TYPE_WARN",
2904+
Integer::New(env->isolate(), LOGGER_FUNC_TYPE_WARN));
2905+
READONLY_PROPERTY(logger, "LOGGER_FUNC_TYPE_ERROR",
2906+
Integer::New(env->isolate(), LOGGER_FUNC_TYPE_ERROR));
2907+
READONLY_PROPERTY(logger, "LOGGER_FUNC_TYPE_DIR",
2908+
Integer::New(env->isolate(), LOGGER_FUNC_TYPE_DIR));
28942909

28952910
// pre-set _events object for faster emit checks
28962911
process->Set(env->events_string(), Object::New(env->isolate()));

0 commit comments

Comments
 (0)