Skip to content

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
kalaiyarasiganeshalingam committed Oct 3, 2023
2 parents 5696a6f + b3f2f19 commit 7bdf716
Show file tree
Hide file tree
Showing 32 changed files with 532 additions and 254 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ensure all Java files use LF.
*.java eol=lf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ on:
default: ''
schedule:
- cron: '30 18 * * *'
pull_request:
branches:
- master
types: [opened, synchronize, reopened, labeled, unlabeled]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
call_stdlib_workflow:
name: Run StdLib Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-native-template.yml@main
uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
with:
lang_tag: ${{ inputs.lang_tag }}
lang_version: ${{ inputs.lang_version }}
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/fossa_scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Fossa Scan
on:
workflow_dispatch:
schedule:
- cron: '30 18 * * *' # 00:00 in LK time (GMT+5:30)
jobs:
fossa-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: fossas/fossa-action@main
env:
packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
with:
api-key: ${{secrets.FOSSA_APIKEY}}
2 changes: 1 addition & 1 deletion .github/workflows/update_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get current date
id: date
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ hs_err_pid*

build
.gradle/
.vscode/
target

integration-tests/Ballerina.toml
integration-tests/Dependencies.toml

# IDEA Files
.idea/
*.iml
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Ballerina Log Library
[![Build](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/build-timestamped-master.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/build-timestamped-master.yml)
[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerina-log/branch/master/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerina-log)
[![Trivy](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/trivy-scan.yml)
[![GraalVM Check](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/build-with-bal-test-native.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/build-with-bal-test-native.yml)
[![GraalVM Check](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/build-with-bal-test-graalvm.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-log/actions/workflows/build-with-bal-test-graalvm.yml)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerina-log.svg)](https://github.com/ballerina-platform/module-ballerina-log/commits/master)
[![Github issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-standard-library/module/log.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-standard-library/labels/module%2Flog)

Expand Down Expand Up @@ -66,8 +66,8 @@ This repository only contains the source code for the package.

### Set up the prerequisites

1. Download and install Java SE Development Kit (JDK) version 11 (from one of the following locations).
* [Oracle](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html)
1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations).
* [Oracle](https://www.oracle.com/java/technologies/downloads/)

* [OpenJDK](https://adoptium.net/)

Expand Down
19 changes: 11 additions & 8 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
[package]
org = "ballerina"
name = "log"
version = "2.7.1"
version = "2.9.0"
authors = ["Ballerina"]
keywords = ["level", "format"]
repository = "https://github.com/ballerina-platform/module-ballerina-log"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.5.0"
distribution = "2201.8.0"

[[platform.java11.dependency]]
[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "log-native"
version = "2.7.1"
path = "../native/build/libs/log-native-2.7.1-SNAPSHOT.jar"
version = "2.9.0"
path = "../native/build/libs/log-native-2.9.0.jar"

[[platform.java11.dependency]]
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "log-test-utils"
version = "2.7.1"
path = "../test-utils/build/libs/log-test-utils-2.7.1-SNAPSHOT.jar"
version = "2.9.0"
path = "../test-utils/build/libs/log-test-utils-2.9.0.jar"
scope = "testOnly"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "log-compiler-plugin"
class = "io.ballerina.stdlib.log.plugin.LogCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/log-compiler-plugin-2.7.1-SNAPSHOT.jar"
path = "../compiler-plugin/build/libs/log-compiler-plugin-2.9.0.jar"
20 changes: 15 additions & 5 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.5.0"
distribution-version = "2201.8.0"

[[package]]
org = "ballerina"
name = "io"
version = "1.4.0"
version = "1.6.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand All @@ -27,6 +27,15 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.value"
Expand All @@ -41,7 +50,7 @@ modules = [
[[package]]
org = "ballerina"
name = "log"
version = "2.7.1"
version = "2.9.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -56,7 +65,7 @@ modules = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.0.7"
version = "1.2.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -71,7 +80,8 @@ name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
Expand Down
78 changes: 68 additions & 10 deletions ballerina/natives.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import ballerina/io;
import ballerina/observe;
import ballerina/lang.'value;
import ballerina/jballerina.java;
import ballerina/lang.value;

# Represents log level types.
enum LogLevel {
Expand Down Expand Up @@ -61,6 +61,7 @@ type LogRecord record {
string level;
string module;
string message;
FullErrorDetails 'error?;
};

final map<int> & readonly logLevelWeight = {
Expand Down Expand Up @@ -176,12 +177,7 @@ isolated function print(string logLevel, string msg, error? err = (), error:Stac
message: msg
};
if err is error {
json|error errMessage = value:fromJsonString(err.message());
if errMessage is json {
logRecord["error"] = errMessage;
} else {
logRecord["error"] = err.message();
}
logRecord.'error = getFullErrorDetails(err);
}
if stackTrace is error:StackFrame[] {
json[] stackTraceArray = [];
Expand Down Expand Up @@ -212,6 +208,64 @@ isolated function print(string logLevel, string msg, error? err = (), error:Stac
}
}

type StackFrame record {|
string callableName;
string? moduleName;
string fileName;
int lineNumber;
|};

type ErrorDetail record {|
json|string message;
json|string detail;
StackFrame[] stackTrace;
|};

type FullErrorDetails record {|
*ErrorDetail;
ErrorDetail[] causes;
|};

isolated function getFullErrorDetails(error err) returns FullErrorDetails {
ErrorDetail[] causes = [];
error? errCause = err.cause();

while errCause != () {
causes.push({message: parseErrorMessage(errCause.message()), stackTrace: parseStackTrace(errCause.stackTrace()), detail: parseErrorDetail(errCause.detail())});
errCause = errCause.cause();
}

return {message: parseErrorMessage(err.message()), stackTrace: parseStackTrace(err.stackTrace()), detail: parseErrorDetail(err.detail()), causes};
}

isolated function parseStackTrace(error:StackFrame[] stackTrace) returns StackFrame[] {
StackFrame[] stackFrames = [];
foreach error:StackFrame item in stackTrace {
java:StackFrameImpl stackFrameImpl = <java:StackFrameImpl>item;
StackFrame stackFrame = {
callableName: stackFrameImpl.callableName,
fileName: stackFrameImpl.fileName,
moduleName: stackFrameImpl.moduleName,
lineNumber: stackFrameImpl.lineNumber
};
stackFrames.push(stackFrame);
}
return stackFrames;
}

isolated function parseErrorMessage(string message) returns json|string {
json|error errMessage = value:fromJsonString(message);
if errMessage is json {
return errMessage;
} else {
return message;
}
}

isolated function parseErrorDetail(error:Detail detail) returns json|string {
return detail is anydata ? detail.toJson() : detail.toBalString();
}

isolated function fileWrite(string logOutput) {
string output = logOutput;
string? path = ();
Expand Down Expand Up @@ -240,14 +294,17 @@ isolated function printLogFmt(LogRecord logRecord) returns string {
value = "\"\"";
}
}
"error" => {
value = v.toBalString();
}
_ => {
value = v is string ? string `${escape(v.toString())}` : v.toString();
}
}
if message == "" {
message = message + string `${k} = ${value}`;
message = message + string `${k}=${value}`;
} else {
message = message + string ` ${k} = ${value}`;
message = message + string ` ${k}=${value}`;
}
}
return message;
Expand All @@ -266,7 +323,8 @@ isolated function escape(string msg) returns string {

isolated function replaceString(handle receiver, handle target, handle replacement) returns handle = @java:Method {
'class: "java.lang.String",
name: "replace"
name: "replace",
paramTypes: ["java.lang.CharSequence", "java.lang.CharSequence"]
} external;

isolated function isLogLevelEnabled(string logLevel, string moduleName) returns boolean {
Expand Down
8 changes: 4 additions & 4 deletions ballerina/tests/log_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ isolated function testPrintLogFmtExtern() {
message: "debug message"
};
test:assertEquals(printLogFmt(logRecord1),
"time = 2021-05-04T10:32:13.220+05:30 level = DEBUG module = foo/bar message = \"debug message\"");
"time=2021-05-04T10:32:13.220+05:30 level=DEBUG module=foo/bar message=\"debug message\"");
LogRecord logRecord2 = {
time: "2021-05-04T10:32:13.220+05:30",
level: "INFO",
module: "foo/bar",
message: "debug message"
};
test:assertEquals(printLogFmt(logRecord2),
"time = 2021-05-04T10:32:13.220+05:30 level = INFO module = foo/bar message = \"debug message\"");
"time=2021-05-04T10:32:13.220+05:30 level=INFO module=foo/bar message=\"debug message\"");
LogRecord logRecord3 = {
time: "2021-05-04T10:32:13.220+05:30",
level: "DEBUG",
module: "",
message: "debug message"
};
test:assertEquals(printLogFmt(logRecord3),
"time = 2021-05-04T10:32:13.220+05:30 level = DEBUG module = \"\" message = \"debug message\"");
"time=2021-05-04T10:32:13.220+05:30 level=DEBUG module=\"\" message=\"debug message\"");
LogRecord logRecord4 = {
time: "2021-05-04T10:32:13.220+05:30",
level: "DEBUG",
Expand All @@ -78,7 +78,7 @@ isolated function testPrintLogFmtExtern() {
"id": 845315
};
test:assertEquals(printLogFmt(logRecord4),
"time = 2021-05-04T10:32:13.220+05:30 level = DEBUG module = foo/bar message = \"debug message\" username = \"Alex\" id = 845315");
"time=2021-05-04T10:32:13.220+05:30 level=DEBUG module=foo/bar message=\"debug message\" username=\"Alex\" id=845315");
}

public isolated function main() {
Expand Down
4 changes: 2 additions & 2 deletions build-config/checkstyle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ apply plugin: 'java'

task downloadCheckstyleRuleFiles(type: Download) {
src([
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.3/checkstyle/checkstyle.xml',
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.3/checkstyle/suppressions.xml'
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.xml',
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/suppressions.xml'
])
overwrite false
onlyIfNewer true
Expand Down
9 changes: 6 additions & 3 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ keywords = ["level", "format"]
repository = "https://github.com/ballerina-platform/module-ballerina-log"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.5.0"
distribution = "2201.8.0"

[[platform.java11.dependency]]
[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "log-native"
version = "@toml.version@"
path = "../native/build/libs/[email protected]@.jar"

[[platform.java11.dependency]]
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "log-test-utils"
version = "@toml.version@"
Expand Down
Loading

0 comments on commit 7bdf716

Please sign in to comment.