Skip to content

Commit

Permalink
Merge pull request #59 from jessedoyle/crystal-0.34
Browse files Browse the repository at this point in the history
Crystal >= 0.34 | Release 0.20.0
  • Loading branch information
jessedoyle committed Apr 14, 2020
2 parents a5335f3 + 02eda60 commit 9e59e8f
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 84 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,24 @@
# v0.20.0 - April 13, 2020

* **breaking change**: Remove the `Duktape::Logger` module and constants.
* **breaking change**: Remove the `Duktape.logger` and `Duktape.headerize` class methods.
* **breaking change**: Alert messages are no longer written to STDERR. Instead they are written to STDOUT.
* Upgrade for Crystal 0.34 support! A minimum crystal version of 0.34 is required for this release.
* Add the `Duktape::Log` with the `Base`, `Alert` and `Console` constants that act as sources for general log messages, alert messages, and console messages.
* Log messages are no longer colorized by default.
* Log output can be controlled using the newly-standardized `CRYSTAL_LOG_SOURCES` and `CRYSTAL_LOG_LEVEL` environment variables.
* Log output messages are now formatted by default as JSON with the following schema:

```graphql
{
exception : String?,
message : String,
severity : String,
source : String,
timestamp : String
}
```

# v0.19.1 - March 3, 2020

- **Bugfix**: Call function properties when using `Duktape::Runtime#call` with no function arguments. [PR 58](https://github.com/jessedoyle/duktape.cr/pull/58), [Issue 57](https://github.com/jessedoyle/duktape.cr/issues/57). Thanks @dinh for reporting!
Expand Down
4 changes: 3 additions & 1 deletion Makefile
@@ -1,6 +1,8 @@
.PHONY: all spec duktape libduktape clean cleanlib

CRYSTAL_BIN := $(shell which crystal)
CRYSTAL_LOG_LEVEL ?= NONE
CRYSTAL_LOG_SOURCES ?= *
SOURCES := $(shell find src -name '*.cr')
SPEC_SOURCES := $(shell find spec -name '*.cr')
CURRENT := $(shell pwd)
Expand All @@ -12,7 +14,7 @@ duktape: $(OUTPUT)/duktape
libduktape:
$(MAKE) -C $(EXT) libduktape
spec: all_spec
$(OUTPUT)/all_spec
@CRYSTAL_LOG_LEVEL=$(CRYSTAL_LOG_LEVEL) CRYSTAL_LOG_SOURCES=$(CRYSTAL_LOG_SOURCES) $(OUTPUT)/all_spec
all_spec: $(OUTPUT)/all_spec
$(OUTPUT)/all_spec: $(SOURCES) $(SPEC_SOURCES)
@mkdir -p $(OUTPUT)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ version: 1.0.0 # your project's version
dependencies:
duktape:
github: jessedoyle/duktape.cr
version: ~> 0.19.1
version: ~> 0.20.0
```

then execute:
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
@@ -1,5 +1,5 @@
name: duktape
version: 0.19.1
version: 0.20.0

authors:
- Jesse Doyle <jdoyle@ualberta.ca>
Expand Down
3 changes: 0 additions & 3 deletions spec/spec_helper.cr
Expand Up @@ -6,9 +6,6 @@ require "../src/lib_duktape"
require "../src/duktape"
require "./support/**"

# Disable logging
Duktape.logger.level = Logger::Severity::UNKNOWN

JS_SOURCE_PATH = "#{__DIR__}/javascripts"

REFERENCE_REGEX = /identifier '__abc__' undefined/
Expand Down
12 changes: 0 additions & 12 deletions spec/support/stack_helper.cr
@@ -1,15 +1,3 @@
def last_stack_type(ctx)
LibDUK.get_type(ctx.raw, -1)
end

def log_debug
Duktape.logger.level = Logger::Severity::DEBUG
yield
Duktape.logger.level = Logger::Severity::UNKNOWN
end

def print_stack!(ctx)
log_debug do
ctx.dump!
end
end
2 changes: 1 addition & 1 deletion src/duktape/api/debug.cr
Expand Up @@ -12,7 +12,7 @@ module Duktape
end

def dump!
Duktape.logger.info "STACK: #{stack}"
Duktape::Log::Base.info { "STACK: #{stack}" }
end
end
end
2 changes: 1 addition & 1 deletion src/duktape/base.cr
@@ -1,8 +1,8 @@
require "../lib_duktape"
require "./support/*"
require "./log"
require "./builtin/base"
require "./context"
require "./error"
require "./logger"
require "./sandbox"
require "./version"
3 changes: 2 additions & 1 deletion src/duktape/builtin/alert.cr
Expand Up @@ -16,7 +16,8 @@ module Duktape
str << env.safe_to_string index
end
end
STDERR.puts output.colorize(:yellow)

Duktape::Log::Alert.info { output }
env.return_undefined
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/duktape/builtin/console.cr
Expand Up @@ -54,7 +54,7 @@ module Duktape
env.insert 0
env.join top
output = env.to_string -1
STDOUT.puts output.colorize(:white)
Duktape::Log::Console.info { output }
env.return_undefined
end

Expand Down
2 changes: 1 addition & 1 deletion src/duktape/builtin/print.cr
Expand Up @@ -16,7 +16,7 @@ module Duktape
str << env.safe_to_string index
end
end
STDOUT.puts output.colorize(:light_cyan)
Duktape::Log::Base.info { output }
env.return_undefined
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/duktape/error.cr
Expand Up @@ -15,14 +15,14 @@ module Duktape
end

def initialize(@msg : String)
Duktape.logger.fatal "InternalError: #{msg}"
Duktape::Log::Base.fatal { "InternalError: #{msg}" }
super msg
end
end

class Error < Exception
def initialize(msg : String)
Duktape.logger.error msg
Duktape::Log::Base.error(exception: self) { msg }
super msg
end
end
Expand Down
46 changes: 46 additions & 0 deletions src/duktape/log.cr
@@ -0,0 +1,46 @@
# log.cr: crystal >= 0.34 log implementation
#
# Copyright (c) 2020 Jesse Doyle. All rights reserved.
#
# This is free software. Please see LICENSE for details.

require "log"
require "json"

Log.setup_from_env(
level: ENV.fetch("CRYSTAL_LOG_LEVEL", "INFO"),
sources: ENV.fetch("CRYSTAL_LOG_SOURCES", "duktape.*"),
backend: Log::IOBackend.new.tap do |backend|
backend.formatter = Duktape::Log.formatter
end
)

module Duktape
module Log
Base = ::Log.for("duktape")
Alert = ::Log.for("duktape.alert")
Console = ::Log.for("duktape.console")

@@formatter : ::Log::Formatter?

def self.formatter
@@formatter ||= ::Log::Formatter.new do |entry, io|
timestamp = Time::Format::ISO_8601_DATE_TIME.format(time: entry.timestamp)

if entry.exception
exception = entry.exception.class.name
else
exception = nil
end

io << {
exception: exception,
message: entry.message,
severity: entry.severity.label,
source: entry.source,
timestamp: timestamp,
}.to_json
end
end
end
end
56 changes: 0 additions & 56 deletions src/duktape/logger.cr

This file was deleted.

2 changes: 1 addition & 1 deletion src/duktape/support/file.cr
Expand Up @@ -8,7 +8,7 @@ module Duktape
module Support::File
private def read_file(path : String)
::File.read path
rescue ex : Errno
rescue ex : ::File::Error
raise FileError.new "invalid file: #{ex.message}"
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/duktape/version.cr
Expand Up @@ -15,8 +15,8 @@ module Duktape

module VERSION
MAJOR = 0
MINOR = 19
TINY = 1
MINOR = 20
TINY = 0
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join "."
Expand Down

0 comments on commit 9e59e8f

Please sign in to comment.