Skip to content

Commit

Permalink
emoved EncodingType reference, bumpo to v3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandro-bottamedi committed Feb 12, 2021
1 parent 4ffa722 commit 43b4ee5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [3.0.3] - 12-02-2021

- removed EncodingType reference on fileAsyncTransport

## [3.0.2] - 27-01-2021

- fixed web colors in console transport
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-logs",
"version": "3.0.2",
"version": "3.0.3",
"description": "Performance-aware simple logger for React-Native with namespaces, custom levels and custom transports (colored console, file writing, etc.)",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -35,6 +35,6 @@
"homepage": "https://github.com/onubo/react-native-logs#readme",
"devDependencies": {
"jest": "^26.6.3",
"typescript": "^4.1.3"
"typescript": "^4.1.5"
}
}
27 changes: 15 additions & 12 deletions src/transports/fileAsyncTransport.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { transportFunctionType } from '../index';
import { transportFunctionType } from "../index";

const EXPOFSappend = async (FS: any, file: string, msg: string) => {
try {
const fileInfo = await FS.getInfoAsync(file);
if (!fileInfo.exists) {
await FS.writeAsStringAsync(file, msg, { encoding: FS.EncodingTypes.UTF8 });
await FS.writeAsStringAsync(file, msg);
return true;
} else {
const prevFile = await FS.readAsStringAsync(file, { encoding: FS.EncodingTypes.UTF8 });
const prevFile = await FS.readAsStringAsync(file);
const newMsg = prevFile + msg;
await FS.writeAsStringAsync(file, newMsg, { encoding: FS.EncodingTypes.UTF8 });
await FS.writeAsStringAsync(file, newMsg);
return true;
}
} catch (error) {
Expand All @@ -20,21 +20,23 @@ const EXPOFSappend = async (FS: any, file: string, msg: string) => {

const RNFSappend = async (FS: any, file: string, msg: string) => {
try {
await FS.appendFile(file, msg, 'utf8');
await FS.appendFile(file, msg, "utf8");
return true;
} catch (error) {
console.error(error);
return false;
}
};

const fileAsyncTransport: transportFunctionType = props => {
const fileAsyncTransport: transportFunctionType = (props) => {
let WRITE: (FS: any, file: string, msg: string) => Promise<boolean>;
let fileName: string = 'log';
let fileName: string = "log";
let filePath: string;

if (!props?.options?.FS) {
throw Error(`react-native-logs: fileAsyncTransport - No FileSystem instance provided`);
throw Error(
`react-native-logs: fileAsyncTransport - No FileSystem instance provided`
);
}
if (props.options.FS.DocumentDirectoryPath && props.options.FS.appendFile) {
WRITE = RNFSappend;
Expand All @@ -43,20 +45,21 @@ const fileAsyncTransport: transportFunctionType = props => {
props.options.FS.documentDirectory &&
props.options.FS.writeAsStringAsync &&
props.options.FS.readAsStringAsync &&
props.options.FS.getInfoAsync &&
props.options.FS.EncodingTypes?.UTF8
props.options.FS.getInfoAsync
) {
WRITE = EXPOFSappend;
filePath = props.options.FS.documentDirectory;
} else {
throw Error(`react-native-logs: fileAsyncTransport - FileSystem not supported`);
throw Error(
`react-native-logs: fileAsyncTransport - FileSystem not supported`
);
}

if (props?.options?.fileName) fileName = props.options.fileName;
if (props?.options?.filePath) filePath = props.options.filePath;

let output = `${props?.msg}\n`;
var path = filePath + '/' + fileName;
var path = filePath + "/" + fileName;

WRITE(props.options.FS, path, output);
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3363,10 +3363,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
typescript@^4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.5.tgz#123a3b214aaff3be32926f0d8f1f6e704eb89a72"
integrity sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==

union-value@^1.0.0:
version "1.0.1"
Expand Down

0 comments on commit 43b4ee5

Please sign in to comment.