Skip to content

Commit 0289780

Browse files
authored
Initial Release for BetterStack Logger (#1)
* Basic logging in place * Prepping for release * Updated README.md * Added readme.txt
1 parent 408259f commit 0289780

File tree

4 files changed

+641
-0
lines changed

4 files changed

+641
-0
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# BetterStack Logger
2+
3+
BetterStack Logger is a powerful WordPress plugin that allows you to seamlessly integrate BetterStack with your WordPress site. Enhance your logging capabilities by sending error messages, post changes, user actions, and more directly to BetterStack. With easy configuration and flexible logging functions, this plugin is an essential tool for developers and site administrators looking to keep track of their site's activities.
4+
5+
## Features
6+
7+
- **Error Logging:** Capture and log WordPress errors directly to BetterStack.
8+
- **User Action Logging:** Log important user actions such as logins, registrations, and profile updates.
9+
- **Post Changes:** Monitor post creation, updates, and deletions.
10+
- **Plugin and Theme Activity:** Log plugin activations/deactivations and theme switches.
11+
- **Customizable Logging:** Use helper functions to log custom messages from anywhere in your codebase.
12+
- **Settings Page:** Easily configure the API key, enable or disable specific logging features via the WordPress admin panel.
13+
- **Support for `wp-config.php`:** Define your BetterStack API key in `wp-config.php` for additional security.
14+
15+
## Installation
16+
17+
### From Your WordPress Dashboard
18+
19+
1. Navigate to `Plugins` -> `Add New`.
20+
2. Search for `BetterStack Logger`.
21+
3. Click `Install Now`.
22+
4. Activate the plugin.
23+
5. Go to `Tools` -> `BetterStack Logger Settings` to configure the plugin.
24+
25+
### Manual Installation
26+
27+
1. Download the plugin from the [Plugin Releases](https://github.com/prolific-digital/betterstack-logger/releases).
28+
2. Upload the `betterstack-logger` directory to the `/wp-content/plugins/` directory.
29+
3. Activate the plugin through the `Plugins` menu in WordPress.
30+
4. Go to `Tools` -> `BetterStack Logger Settings` to configure the plugin.
31+
32+
## Configuration
33+
34+
### API Key
35+
36+
To log messages to BetterStack, you need to set up your API key:
37+
38+
1. Go to `Tools` -> `BetterStack Logger Settings`.
39+
2. Enter your BetterStack API key in the `API Key` field.
40+
3. Optionally, define the API key in your `wp-config.php` file using `BETTERSTACK_API_KEY`.
41+
42+
### Logging Options
43+
44+
- **Enable Error Logging:** Toggle to capture WordPress errors.
45+
- **Enable Event Logging:** Toggle to log user actions, post changes, and more.
46+
47+
## Usage
48+
49+
### Logging Custom Messages
50+
51+
Use the following functions to log messages from anywhere in your code:
52+
53+
```php
54+
// Log a custom message
55+
better_error_log('This is a custom error message.');
56+
57+
// Shorter version
58+
b_log('This is a quick log message.');
59+
```
60+
61+
### Example:
62+
63+
```php
64+
function my_custom_function() {
65+
// Perform some task
66+
// ...
67+
68+
// Log a message
69+
better_error_log('Task completed successfully.');
70+
}
71+
72+
add_action('init', 'my_custom_function');
73+
```
74+
75+
### Available Functions
76+
77+
- `better_error_log($message)`: Logs a custom message to BetterStack.
78+
- `b_log($message)`: Shorthand function to log a custom message to BetterStack.
79+
80+
## Frequently Asked Questions
81+
82+
Can I define the API key in `wp-config.php`?
83+
84+
Yes! For added security, you can define your API key in `wp-config.php` using:
85+
86+
```php
87+
define('BETTERSTACK_API_KEY', 'your-api-key-here');
88+
```
89+
90+
What types of events can I log with BetterStack Logger?
91+
92+
You can log errors, user actions (e.g., logins, registrations), post changes (e.g., creation, updates, deletions), plugin activations/deactivations, theme switches, and custom messages.
93+
94+
## Support
95+
96+
If you need help or have any questions, feel free to reach out to us:
97+
98+
- Visit our [Support Page](https://prolificdigital.notion.site/BetterStack-Logger-c0cc4526efd049c09b77965bf3ecc28e)
99+
- Email us at [email protected]

betterstack-logger.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/*
3+
Plugin Name: BetterStack Logger
4+
Plugin URI: https://prolificdigital.com
5+
Description: Seamlessly integrate with BetterStack to log messages directly from your WordPress site. Enhance your logging capabilities with ease and precision.
6+
Short Description: Seamlessly integrate with BetterStack to log messages directly from your WordPress site.
7+
Tags: betterstack, logger, logging, error, errors, debug, debugging, log, logs, monitoring, monitoring, betterstack logger, betterstack logging, betterstack error logging, betterstack error logger, betterstack debug logging, betterstack debug logger
8+
Version: 1.0.0
9+
Requires at least: 6.0
10+
Requires PHP: 8.0
11+
Tested up to: 6.6
12+
Author: Prolific Digital
13+
Author URI: https://prolificdigital.com
14+
License: GPLv2 or later
15+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
16+
Text Domain: betterstack-logger
17+
18+
*/
19+
20+
if (!defined('WPINC')) {
21+
die;
22+
}
23+
24+
require_once plugin_dir_path(__FILE__) . 'includes/BetterStackLogger.php';
25+
26+
// Create a global instance of the BetterStackLogger class
27+
global $betterstack_logger;
28+
$betterstack_logger = new BetterStackLogger();
29+
30+
/**
31+
* Log an error message using BetterStackLogger.
32+
*
33+
* This function allows developers to easily log messages to BetterStack
34+
* from anywhere in the codebase by calling better_error_log($message).
35+
*
36+
* @param string $message The message to log.
37+
*/
38+
if (!function_exists('better_error_log')) {
39+
function better_error_log($message) {
40+
global $betterstack_logger;
41+
42+
if ($betterstack_logger instanceof BetterStackLogger) {
43+
$betterstack_logger->log_error($message);
44+
}
45+
}
46+
}
47+
48+
/**
49+
* Log an error message using BetterStackLogger.
50+
*
51+
* This function provides a shorthand way for developers to log messages to BetterStack
52+
* from anywhere in the codebase by calling b_log($message).
53+
*
54+
* @param string $message The message to log.
55+
*/
56+
if (!function_exists('b_log')) {
57+
function b_log($message) {
58+
global $betterstack_logger;
59+
60+
if ($betterstack_logger instanceof BetterStackLogger) {
61+
$betterstack_logger->log_error($message);
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)